-
-
Notifications
You must be signed in to change notification settings - Fork 12.1k
Open
Labels
Description
Describe the issue:
np.linalg.pinv(a, rtol=None) raises ValueError when a has an integer dtype (e.g. int32, int64). The rtol=None code path is the Array API standard default, so it should work with any numeric input.
Suggested Fix:
● --- a/numpy/linalg/_linalg.py
+++ b/numpy/linalg/_linalg.py
@@ -2323,7 +2323,7 @@ def pinv(a, rcond=None, hermitian=False, *, rtol=_NoValue):
if rcond is None:
if rtol is _NoValue:
rcond = 1e-15
elif rtol is None:
- rcond = max(a.shape[-2:]) * finfo(a.dtype).eps
+ rcond = max(a.shape[-2:]) * finfo(_commonType(a)[1]).eps
else:
rcond = rtolReproduce the code example:
import numpy as np
# A valid integer matrix
a = np.array([[1, 2], [3, 4]], dtype=np.int32)
# This should compute the pseudo-inverse (pinv with default rcond works fine)
result = np.linalg.pinv(a, rtol=None)
print("pinv:", result)Error message:
Traceback (most recent call last):
File "C:\Users\madanm\git\DeepTest\repo_benchmarks\numpy-DeepTests\standalone\crash_v2\score4\linalg_pinv_rtol_none_integer_dtype.py", line 26, in <module>
result = np.linalg.pinv(a, rtol=None)
File "C:\Users\madanm\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages\numpy\linalg\_linalg.py", line 2266, in pinv
rcond = max(a.shape[-2:]) * finfo(a.dtype).eps
~~~~~^^^^^^^^^
File "C:\Users\madanm\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages\numpy\_core\getlimits.py", line 526, in __new__
raise ValueError(f"data type {dtype!r} not inexact")
ValueError: data type <class 'numpy.int32'> not inexactPython 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