Describe the issue:
numpy.linalg.matrix_rank raises a ValueError when given a matrix with a zero-sized dimension (e.g., shape (0, 3)). The rank of an empty matrix is mathematically 0, and other linalg functions (pinv, cond) already handle
this via the _is_empty_2d guard — matrix_rank is missing it.
Reproduce the code example:
import numpy as np
a = np.empty((0, 3))
np.linalg.matrix_rank(a) # Expected: 0
Error message:
Traceback (most recent call last):
File "C:\Users\madanm\git\DeepTest\repo_benchmarks\numpy-DeepTests\standalone\crash_v2\score5\linalg_matrix_rank_empty_matrix.py", line 24, in <module>
rank = np.linalg.matrix_rank(a)
File "C:\Users\madanm\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages\numpy\linalg\_linalg.py", line 2165, in matrix_rank
tol = S.max(axis=-1, keepdims=True) * rtol
~~~~~^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\madanm\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages\numpy\_core\_methods.py", line 43, in _amax
return umr_maximum(a, axis, None, out, keepdims, initial, where)
ValueError: zero-size array to reduction operation maximum which has no identity
Python 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
Describe the issue:
numpy.linalg.matrix_rankraises aValueErrorwhen given a matrix with a zero-sized dimension (e.g., shape(0, 3)). The rank of an empty matrix is mathematically 0, and other linalg functions (pinv,cond) already handlethis via the
_is_empty_2dguard —matrix_rankis missing it.Reproduce the code example:
Error message:
Python 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