88import pytensor .sparse .math
99import pytensor .tensor as pt
1010from pytensor import sparse
11- from pytensor .compile .function import function
1211from pytensor .compile .io import In
1312from pytensor .configdefaults import config
1413from pytensor .gradient import GradientError
@@ -87,19 +86,6 @@ def as_sparse_format(data, format):
8786 raise NotImplementedError ()
8887
8988
90- def eval_outputs (outputs ):
91- return function ([], outputs )()[0 ]
92-
93-
94- # scipy 0.17 will return sparse values in all cases while previous
95- # version sometimes wouldn't. This will make everything dense so that
96- # we can use assert_allclose.
97- def as_ndarray (val ):
98- if hasattr (val , "toarray" ):
99- return val .toarray ()
100- return val
101-
102-
10389def random_lil (shape , dtype , nnz ):
10490 rval = scipy_sparse .lil_matrix (shape , dtype = dtype )
10591 huge = 2 ** 30
@@ -355,7 +341,7 @@ def test_transpose_csc(self):
355341 assert ta .type .dtype == "float64" , ta .type .dtype
356342 assert ta .type .format == "csr" , ta .type .format
357343
358- vta = eval_outputs ([ ta ] )
344+ vta = ta . eval ( )
359345 assert vta .shape == (3 , 5 )
360346
361347 def test_transpose_csr (self ):
@@ -367,7 +353,7 @@ def test_transpose_csr(self):
367353 assert ta .type .dtype == "float64" , ta .type .dtype
368354 assert ta .type .format == "csc" , ta .type .format
369355
370- vta = eval_outputs ([ ta ] )
356+ vta = ta . eval ( )
371357 assert vta .shape == (3 , 5 )
372358
373359
@@ -544,13 +530,13 @@ def test_basic(self):
544530 test_val = np .random .random ((5 ,)).astype (config .floatX )
545531 a = pt .as_tensor_variable (test_val )
546532 s = csc_from_dense (a )
547- val = eval_outputs ([ s ] )
533+ val = s . eval ( )
548534 assert str (val .dtype ) == config .floatX
549535 assert val .format == "csc"
550536
551537 a = pt .as_tensor_variable (test_val )
552538 s = csr_from_dense (a )
553- val = eval_outputs ([ s ] )
539+ val = s . eval ( )
554540 assert str (val .dtype ) == config .floatX
555541 assert val .format == "csr"
556542
@@ -573,7 +559,7 @@ def test_dense_from_sparse(self):
573559 s = t (scipy_sparse .identity (5 ))
574560 s = as_sparse_variable (s )
575561 d = dense_from_sparse (s )
576- val = eval_outputs ([ d ] )
562+ val = d . eval ( )
577563 assert str (val .dtype ) == s .dtype
578564 assert np .all (val [0 ] == [1 , 0 , 0 , 0 , 0 ])
579565
@@ -583,7 +569,7 @@ def test_todense(self):
583569 s = t (scipy_sparse .identity (5 ))
584570 s = as_sparse_variable (s )
585571 d = s .toarray ()
586- val = eval_outputs ([ d ] )
572+ val = d . eval ( )
587573 assert str (val .dtype ) == s .dtype
588574 assert np .all (val [0 ] == [1 , 0 , 0 , 0 , 0 ])
589575
0 commit comments