Skip to content

Commit 9a124ca

Browse files
committed
Scipy is not optional
1 parent 27d7970 commit 9a124ca

File tree

3 files changed

+12
-19
lines changed

3 files changed

+12
-19
lines changed

tests/link/numba/test_basic.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66

77
import numpy as np
88
import pytest
9+
import scipy
910

1011
from pytensor.compile import SymbolicInput
11-
from tests.tensor.test_math_scipy import scipy
1212

1313

1414
numba = pytest.importorskip("numba")

tests/tensor/test_math_scipy.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,19 @@
11
import warnings
2+
from functools import partial
23

34
import numpy as np
45
import pytest
5-
6-
from pytensor.gradient import NullTypeGradError, verify_grad
7-
from pytensor.scalar import ScalarLoop
8-
from pytensor.tensor.elemwise import Elemwise
9-
10-
11-
scipy = pytest.importorskip("scipy")
12-
13-
from functools import partial
14-
6+
import scipy
157
from scipy import special, stats
168

179
from pytensor import function, grad
1810
from pytensor import tensor as pt
1911
from pytensor.compile.mode import get_default_mode
2012
from pytensor.configdefaults import config
13+
from pytensor.gradient import NullTypeGradError, verify_grad
14+
from pytensor.scalar import ScalarLoop
2115
from pytensor.tensor import gammaincc, inplace, kn, kv, kve, vector
16+
from pytensor.tensor.elemwise import Elemwise
2217
from tests import unittest_tools as utt
2318
from tests.tensor.utils import (
2419
_good_broadcast_unary_chi2sf,

tests/typed_list/test_basic.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import numpy as np
22
import pytest
3+
import scipy
34

45
import pytensor
56
import pytensor.typed_list
@@ -37,8 +38,7 @@ def rand_ranged_matrix(minimum, maximum, shape):
3738

3839

3940
def 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

Comments
 (0)