11import numpy as np
22import pytest
3+ import scipy
34
45import pytensor
56import pytensor .typed_list
@@ -37,8 +38,7 @@ def rand_ranged_matrix(minimum, maximum, shape):
3738
3839
3940def random_lil (shape , dtype , nnz ):
40- sp = pytest .importorskip ("scipy" )
41- rval = sp .sparse .lil_matrix (shape , dtype = dtype )
41+ rval = scipy .sparse .lil_matrix (shape , dtype = dtype )
4242 huge = 2 ** 30
4343 for k in range (nnz ):
4444 # set non-zeros in random locations (row x, col y)
@@ -451,7 +451,6 @@ def test_non_tensor_type(self):
451451 assert f ([[x , y ], [x , y , y ]], [x , y ]) == 0
452452
453453 def test_sparse (self ):
454- sp = pytest .importorskip ("scipy" )
455454 mySymbolicSparseList = TypedListType (
456455 sparse .SparseTensorType ("csr" , pytensor .config .floatX )
457456 )()
@@ -461,8 +460,8 @@ def test_sparse(self):
461460
462461 f = pytensor .function ([mySymbolicSparseList , mySymbolicSparse ], z )
463462
464- x = sp .sparse .csr_matrix (random_lil ((10 , 40 ), pytensor .config .floatX , 3 ))
465- y = sp .sparse .csr_matrix (random_lil ((10 , 40 ), pytensor .config .floatX , 3 ))
463+ x = scipy .sparse .csr_matrix (random_lil ((10 , 40 ), pytensor .config .floatX , 3 ))
464+ y = scipy .sparse .csr_matrix (random_lil ((10 , 40 ), pytensor .config .floatX , 3 ))
466465
467466 assert f ([x , y ], y ) == 1
468467
@@ -519,7 +518,6 @@ def test_non_tensor_type(self):
519518 assert f ([[x , y ], [x , y , y ]], [x , y ]) == 1
520519
521520 def test_sparse (self ):
522- sp = pytest .importorskip ("scipy" )
523521 mySymbolicSparseList = TypedListType (
524522 sparse .SparseTensorType ("csr" , pytensor .config .floatX )
525523 )()
@@ -529,8 +527,8 @@ def test_sparse(self):
529527
530528 f = pytensor .function ([mySymbolicSparseList , mySymbolicSparse ], z )
531529
532- x = sp .sparse .csr_matrix (random_lil ((10 , 40 ), pytensor .config .floatX , 3 ))
533- y = sp .sparse .csr_matrix (random_lil ((10 , 40 ), pytensor .config .floatX , 3 ))
530+ x = scipy .sparse .csr_matrix (random_lil ((10 , 40 ), pytensor .config .floatX , 3 ))
531+ y = scipy .sparse .csr_matrix (random_lil ((10 , 40 ), pytensor .config .floatX , 3 ))
534532
535533 assert f ([x , y , y ], y ) == 2
536534
0 commit comments