Skip to content

Commit 1761a4b

Browse files
dschulttylerjereddy
authored andcommitted
BUG: sparse.linalg.norm: fix return type (scipy#22372)
cupy reports cupy/cupy#8866 that sparse.linalg.norm returns a python number instead of a 0-dim numpy array
1 parent 1d0fd00 commit 1761a4b

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

scipy/sparse/linalg/_norm.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,13 +150,13 @@ def norm(x, ord=None, axis=None):
150150
raise NotImplementedError
151151
#return _multi_svd_norm(x, row_axis, col_axis, amin)
152152
elif ord == 1:
153-
return abs(x).sum(axis=row_axis).max().item()
153+
return abs(x).sum(axis=row_axis).max()
154154
elif ord == np.inf:
155-
return abs(x).sum(axis=col_axis).max().item()
155+
return abs(x).sum(axis=col_axis).max()
156156
elif ord == -1:
157-
return abs(x).sum(axis=row_axis).min().item()
157+
return abs(x).sum(axis=row_axis).min()
158158
elif ord == -np.inf:
159-
return abs(x).sum(axis=col_axis).min().item()
159+
return abs(x).sum(axis=col_axis).min()
160160
elif ord in (None, 'f', 'fro'):
161161
# The axis order does not matter for this norm.
162162
return _sparse_frobenius_norm(x)

scipy/sparse/linalg/tests/test_norm.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ def test_sparray_norm():
2323
for ax in [0, 1, None, (0, 1), (1, 0)]:
2424
for A in (test_arr, test_mat):
2525
expected = npnorm(A.toarray(), ord=ord, axis=ax)
26-
assert_equal(spnorm(A, ord=ord, axis=ax), expected)
26+
actual = spnorm(A, ord=ord, axis=ax)
27+
assert hasattr(actual, "dtype")
28+
assert_equal(actual, expected)
2729
# test 1d array and 1d-like (column) matrix
2830
test_arr_1d = scipy.sparse.coo_array((data, (col,)), shape=(4,))
2931
test_mat_col = scipy.sparse.coo_matrix((data, (col, [0, 0, 0, 0])), shape=(4, 1))

0 commit comments

Comments
 (0)