X Tutup
Skip to content

BUG: numpy.linalg.pinv crashes with ValueError when called with rtol=None on an integer-dtype array [DeepTest] #30917

@madanMus

Description

@madanMus

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 = rtol

Reproduce 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 inexact

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      X Tutup