Skip to content

Commit

Permalink
Merge pull request cupy#8877 from asi1024/value-error-3dim-sparse
Browse files Browse the repository at this point in the history
Raise ValueError upon attempts to create 3-dim sparse array
  • Loading branch information
kmaehashi authored and chainer-ci committed Jan 20, 2025
1 parent c2d9245 commit b7bd5ca
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion cupyx/scipy/sparse/_compressed.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ def __init__(self, arg1, shape=None, dtype=None, copy=False):

elif _base.isdense(arg1):
if arg1.ndim > 2:
raise TypeError('expected dimension <= 2 array or matrix')
raise ValueError('expected dimension <= 2 array or matrix')
elif arg1.ndim == 1:
arg1 = arg1[None]
elif arg1.ndim == 0:
Expand Down
4 changes: 2 additions & 2 deletions tests/cupyx_tests/scipy_tests/sparse_tests/test_csc.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,10 +203,10 @@ def test_init_data_row_col(self):
cupy.testing.assert_array_equal(n.indptr, self.m.indptr)
assert n.shape == self.m.shape

@testing.with_requires('scipy')
@testing.with_requires('scipy>=1.15')
def test_init_dense_invalid_ndim(self):
for xp, sp in ((numpy, scipy.sparse), (cupy, sparse)):
with pytest.raises(TypeError):
with pytest.raises(ValueError):
m = xp.zeros((1, 1, 1), dtype=self.dtype)
sp.csc_matrix(m)

Expand Down
4 changes: 2 additions & 2 deletions tests/cupyx_tests/scipy_tests/sparse_tests/test_csr.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,11 +247,11 @@ def test_init_data_row_col(self):
cupy.testing.assert_array_equal(n.indptr, self.m.indptr)
assert n.shape == self.m.shape

@testing.with_requires('scipy')
@testing.with_requires('scipy>=1.15')
def test_init_dense_invalid_ndim(self):
for xp, sp in ((numpy, scipy.sparse), (cupy, sparse)):
m = xp.zeros((1, 1, 1), dtype=self.dtype)
with pytest.raises(TypeError):
with pytest.raises(ValueError):
sp.csr_matrix(m)

def test_copy(self):
Expand Down

0 comments on commit b7bd5ca

Please sign in to comment.