Skip to content

Commit cf755ce

Browse files
committed
Restrict changes to proper norms.
1 parent 660e287 commit cf755ce

File tree

2 files changed

+6
-18
lines changed

2 files changed

+6
-18
lines changed

numpy/linalg/_linalg.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2541,7 +2541,7 @@ def lstsq(a, b, rcond=None):
25412541
return wrap(x), wrap(resids), rank, s
25422542

25432543

2544-
def _multi_svd_norm(x, row_axis, col_axis, op, initial):
2544+
def _multi_svd_norm(x, row_axis, col_axis, op, initial=None):
25452545
"""Compute a function of the singular values of the 2-D matrices in `x`.
25462546
25472547
This is a private utility function used by `numpy.linalg.norm()`.
@@ -2765,7 +2765,7 @@ def norm(x, ord=None, axis=None, keepdims=False):
27652765
if ord == inf:
27662766
return abs(x).max(axis=axis, keepdims=keepdims, initial=0)
27672767
elif ord == -inf:
2768-
return abs(x).min(axis=axis, keepdims=keepdims, initial=inf)
2768+
return abs(x).min(axis=axis, keepdims=keepdims)
27692769
elif ord == 0:
27702770
# Zero norm
27712771
return (
@@ -2799,7 +2799,7 @@ def norm(x, ord=None, axis=None, keepdims=False):
27992799
if ord == 2:
28002800
ret = _multi_svd_norm(x, row_axis, col_axis, amax, 0)
28012801
elif ord == -2:
2802-
ret = _multi_svd_norm(x, row_axis, col_axis, amin, inf)
2802+
ret = _multi_svd_norm(x, row_axis, col_axis, amin)
28032803
elif ord == 1:
28042804
if col_axis > row_axis:
28052805
col_axis -= 1
@@ -2811,11 +2811,11 @@ def norm(x, ord=None, axis=None, keepdims=False):
28112811
elif ord == -1:
28122812
if col_axis > row_axis:
28132813
col_axis -= 1
2814-
ret = add.reduce(abs(x), axis=row_axis).min(axis=col_axis, initial=inf)
2814+
ret = add.reduce(abs(x), axis=row_axis).min(axis=col_axis)
28152815
elif ord == -inf:
28162816
if row_axis > col_axis:
28172817
row_axis -= 1
2818-
ret = add.reduce(abs(x), axis=col_axis).min(axis=row_axis, initial=inf)
2818+
ret = add.reduce(abs(x), axis=col_axis).min(axis=row_axis)
28192819
elif ord in [None, 'fro', 'f']:
28202820
ret = sqrt(add.reduce((x.conj() * x).real, axis=axis))
28212821
elif ord == 'nuc':

numpy/linalg/tests/test_linalg.py

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2376,21 +2376,11 @@ def test_matrix_norm_empty():
23762376
for shape in [(0, 2), (2, 0), (0, 0)]:
23772377
for dtype in [np.float64, np.float32, np.int32]:
23782378
x = np.zeros(shape, dtype)
2379-
23802379
assert_equal(np.linalg.matrix_norm(x, ord="fro"), 0)
23812380
assert_equal(np.linalg.matrix_norm(x, ord="nuc"), 0)
2382-
2383-
assert_equal(np.linalg.matrix_norm(x, ord=2), 0)
2384-
assert_equal(np.linalg.matrix_norm(x, ord=-2), np.inf)
2385-
23862381
assert_equal(np.linalg.matrix_norm(x, ord=1), 0)
2387-
y = np.inf if x.shape[1] == 0 else 0
2388-
assert_equal(np.linalg.matrix_norm(x, ord=-1), y)
2389-
2382+
assert_equal(np.linalg.matrix_norm(x, ord=2), 0)
23902383
assert_equal(np.linalg.matrix_norm(x, ord=np.inf), 0)
2391-
z = np.inf if x.shape[0] == 0 else 0
2392-
assert_equal(np.linalg.matrix_norm(x, ord=-np.inf), z)
2393-
23942384

23952385
def test_vector_norm():
23962386
x = np.arange(9).reshape((3, 3))
@@ -2413,8 +2403,6 @@ def test_vector_norm():
24132403
def test_vector_norm_empty():
24142404
for dtype in [np.float64, np.float32, np.int32]:
24152405
x = np.zeros(0, dtype)
2416-
assert_equal(np.linalg.vector_norm(x, ord=0), 0)
24172406
assert_equal(np.linalg.vector_norm(x, ord=1), 0)
24182407
assert_equal(np.linalg.vector_norm(x, ord=2), 0)
24192408
assert_equal(np.linalg.vector_norm(x, ord=np.inf), 0)
2420-
assert_equal(np.linalg.vector_norm(x, ord=-np.inf), np.inf)

0 commit comments

Comments
 (0)