-
-
Notifications
You must be signed in to change notification settings - Fork 12.1k
Open
Labels
Description
Describe the issue:
For ord=-2, norm calls _multi_svd_norm without initial=0.
Suggested fix:
--- a/numpy/linalg/_linalg.py
+++ b/numpy/linalg/_linalg.py
@@ -2919,7 +2919,7 @@ def norm(x, ord=None, axis=None, keepdims=False):
if ord == 2:
ret = _multi_svd_norm(x, row_axis, col_axis, amax, 0)
elif ord == -2:
- ret = _multi_svd_norm(x, row_axis, col_axis, amin)
+ ret = _multi_svd_norm(x, row_axis, col_axis, amin, 0)
elif ord == 1:Reproduce the code example:
import numpy as np
# A valid empty matrix (0 rows, 3 columns)
a = np.empty((0, 3))
# ord=2 works fine:
# np.linalg.matrix_norm(a, ord=2) # returns 0.0
# But ord=-2 crashes
result = np.linalg.matrix_norm(a, ord=-2)
print("matrix_norm:", result)Error message:
Traceback (most recent call last):
File "C:\Users\madanm\git\DeepTest\repo_benchmarks\numpy-DeepTests\standalone\crash_v2\score4\linalg_matrix_norm_empty_ord_neg2.py", line 28, in <module>
result = np.linalg.matrix_norm(a, ord=-2)
File "C:\Users\madanm\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages\numpy\linalg\_linalg.py", line 3526, in matrix_norm
return norm(x, axis=(-2, -1), keepdims=keepdims, ord=ord)
File "C:\Users\madanm\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages\numpy\linalg\_linalg.py", line 2849, in norm
ret = _multi_svd_norm(x, row_axis, col_axis, amin)
File "C:\Users\madanm\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages\numpy\linalg\_linalg.py", line 2615, in _multi_svd_norm
result = op(svd(y, compute_uv=False), axis=-1, initial=initial)
File "C:\Users\madanm\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages\numpy\_core\fromnumeric.py", line 3319, in amin
return _wrapreduction(a, np.minimum, 'min', axis, None, out,
keepdims=keepdims, initial=initial, where=where)
File "C:\Users\madanm\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages\numpy\_core\fromnumeric.py", line 86, in _wrapreduction
return ufunc.reduce(obj, axis, dtype, out, **passkwargs)
~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: zero-size array to reduction operation minimum which has no identityPython and NumPy Versions:
2.3.5
3.13.12 (tags/v3.13.12:1cbe481, Feb 3 2026, 18:22:25) [MSC v.1944 64 bit (AMD64)]
Runtime Environment:
No response
How does this issue affect you or how did you find it:
Using DeepTest
Reactions are currently unavailable