Skip to content

Commit 7d4ac51

Browse files
committed
XFAIL/SKIP Sparse tests
1 parent aecaf62 commit 7d4ac51

File tree

6 files changed

+46
-32
lines changed

6 files changed

+46
-32
lines changed

tests/compile/function/test_pfunc.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
import numpy as np
22
import pytest
3+
import scipy as sp
34

45
import pytensor.tensor as pt
5-
from pytensor.compile import UnusedInputError, get_mode
6+
from pytensor.compile import UnusedInputError, get_default_mode, get_mode
67
from pytensor.compile.function import function, pfunc
78
from pytensor.compile.function.pfunc import rebuild_collect_shared
89
from pytensor.compile.io import In
910
from pytensor.compile.sharedvalue import shared
1011
from pytensor.configdefaults import config
1112
from pytensor.graph.utils import MissingInputError
13+
from pytensor.link.numba import NumbaLinker
14+
from pytensor.sparse import SparseTensorType
1215
from pytensor.tensor.math import sum as pt_sum
1316
from pytensor.tensor.type import (
1417
bscalar,
@@ -763,18 +766,18 @@ def test_shared_constructor_copies(self):
763766
# rule #2 reading back from pytensor-managed memory
764767
assert not np.may_share_memory(A.get_value(borrow=False), data_of(A))
765768

769+
@pytest.mark.xfail(
770+
condition=isinstance(get_default_mode().linker, NumbaLinker),
771+
reason="Numba does not support Sparse Ops yet",
772+
)
766773
def test_sparse_input_aliasing_affecting_inplace_operations(self):
767-
sp = pytest.importorskip("scipy", minversion="0.7.0")
768-
769-
from pytensor import sparse
770-
771774
# Note: to trigger this bug with pytensor rev 4586:2bc6fc7f218b,
772775
# you need to make in inputs mutable (so that inplace
773776
# operations are used) and to break the elemwise composition
774777
# with some non-elemwise op (here dot)
775778

776-
x = sparse.SparseTensorType("csc", dtype="float64")()
777-
y = sparse.SparseTensorType("csc", dtype="float64")()
779+
x = SparseTensorType("csc", dtype="float64")()
780+
y = SparseTensorType("csc", dtype="float64")()
778781
f = function([In(x, mutable=True), In(y, mutable=True)], (x + y) + (x + y))
779782
# Test 1. If the same variable is given twice
780783

tests/sparse/__init__.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import pytest
2+
3+
from pytensor.compile import get_default_mode
4+
from pytensor.link.numba import NumbaLinker
5+
6+
7+
if isinstance(get_default_mode().linker, NumbaLinker):
8+
pytest.skip(
9+
reason="Numba does not support Sparse Ops yet",
10+
allow_module_level=True,
11+
)

tests/sparse/test_basic.py

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import pytensor.sparse.math
99
import pytensor.tensor as pt
1010
from pytensor import sparse
11-
from pytensor.compile.function import function
1211
from pytensor.compile.io import In
1312
from pytensor.configdefaults import config
1413
from 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-
10389
def 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

tests/sparse/test_math.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@
5454
)
5555
from tests import unittest_tools as utt
5656
from tests.sparse.test_basic import (
57-
as_ndarray,
5857
as_sparse_format,
5958
random_lil,
6059
sparse_random_inputs,
@@ -1020,7 +1019,7 @@ def test_op(self):
10201019
tested = f(*self.a)
10211020
x, y, p = self.a
10221021
expected = p.multiply(np.dot(x, y.T))
1023-
utt.assert_allclose(as_ndarray(expected), tested.toarray())
1022+
utt.assert_allclose(expected.toarray(), tested.toarray())
10241023
assert tested.format == "csr"
10251024
assert tested.dtype == expected.dtype
10261025

@@ -1030,7 +1029,7 @@ def test_negative_stride(self):
10301029
tested = f(*a2)
10311030
x, y, p = a2
10321031
expected = p.multiply(np.dot(x, y.T))
1033-
utt.assert_allclose(as_ndarray(expected), tested.toarray())
1032+
utt.assert_allclose(expected.toarray(), tested.toarray())
10341033
assert tested.format == "csr"
10351034
assert tested.dtype == expected.dtype
10361035

@@ -1098,7 +1097,7 @@ def test_structured_add_s_v(self):
10981097

10991098
out = f(spmat, mat)
11001099
utt.assert_allclose(
1101-
as_ndarray(spones.multiply(spmat + mat)), out.toarray()
1100+
spones.multiply(spmat + mat).toarray(), out.toarray()
11021101
)
11031102

11041103

tests/test_raise_op.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44

55
import pytensor
66
import pytensor.tensor as pt
7-
from pytensor.compile.mode import OPT_FAST_RUN, Mode
7+
from pytensor.compile.mode import OPT_FAST_RUN, Mode, get_default_mode
88
from pytensor.graph import vectorize_graph
99
from pytensor.graph.basic import Constant, equal_computations
10+
from pytensor.link.numba import NumbaLinker
1011
from pytensor.raise_op import Assert, CheckAndRaise, assert_op
1112
from pytensor.scalar.basic import ScalarType, float64
1213
from pytensor.sparse import as_sparse_variable
@@ -181,6 +182,10 @@ def test_infer_shape_scalar(self):
181182
)
182183

183184

185+
@pytest.mark.xfail(
186+
condition=isinstance(get_default_mode().linker, NumbaLinker),
187+
reason="Numba does not support Sparse Ops yet",
188+
)
184189
def test_CheckAndRaise_sparse_variable():
185190
check_and_raise = CheckAndRaise(ValueError, "sparse_check")
186191

tests/typed_list/test_basic.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import pytensor
88
import pytensor.typed_list
99
from pytensor import sparse
10+
from pytensor.compile import get_default_mode
11+
from pytensor.link.numba import NumbaLinker
1012
from pytensor.tensor.type import (
1113
TensorType,
1214
integer_dtypes,
@@ -452,6 +454,10 @@ def test_non_tensor_type(self):
452454

453455
assert f([[x, y], [x, y, y]], [x, y]) == 0
454456

457+
@pytest.mark.xfail(
458+
condition=isinstance(get_default_mode().linker, NumbaLinker),
459+
reason="Numba does not support Sparse Ops yet",
460+
)
455461
def test_sparse(self):
456462
mySymbolicSparseList = TypedListType(
457463
sparse.SparseTensorType("csr", pytensor.config.floatX)
@@ -519,6 +525,10 @@ def test_non_tensor_type(self):
519525

520526
assert f([[x, y], [x, y, y]], [x, y]) == 1
521527

528+
@pytest.mark.xfail(
529+
condition=isinstance(get_default_mode().linker, NumbaLinker),
530+
reason="Numba does not support Sparse Ops yet",
531+
)
522532
def test_sparse(self):
523533
mySymbolicSparseList = TypedListType(
524534
sparse.SparseTensorType("csr", pytensor.config.floatX)

0 commit comments

Comments
 (0)