BUG: `linalg.pinv` fails on integer input with `rtol=None`

未關閉 適合新手
#33,470 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 1 天內回覆

還沒有人認領這個 Issue。

評估

難度
2/5
預估耗時
1-3 小時
新手友好度
75/100
Issue 類型
缺陷
描述清晰度
描述清楚
活躍度
活躍
技術堆疊
numpy, python
領域
backend

研究方向

追蹤回溯指向 numpy/linalg/_linalg.py 中的 pinv,其中 finfo 收到了整數 dtype。閱讀 pinv 的實作以及附近針對整數輸入和 rtol=None 的測試;為回報中的呼叫補上測試,並確認它會傳回浮點單位矩陣,且不改變預設行為。

由索引模型根據 Issue 內容生成。

描述

00 - Bug component: numpy.linalg
Describe the issue:

np.linalg.pinv accepts an integer identity matrix with the default cutoff, but fails with rtol=None. Both calls should return the floating-point identity matrix.

Reproduce the code example:
import numpy as np

data = np.array([[1, 0], [0, 1]], dtype=np.int64)
print(np.linalg.pinv(data))
np.linalg.pinv(data, rtol=None)
Error message:
[[1. 0.]
 [0. 1.]]
Traceback (most recent call last):
  File "/test.py", line 5, in <module>
    np.linalg.pinv(data, rtol=None)
    ~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^
  File "/home/xxx/anaconda3/envs/py314/lib/python3.14/site-packages/numpy/linalg/_linalg.py", line 2258, in pinv
    rcond = max(a.shape[-2:]) * finfo(a.dtype).eps
                                ~~~~~^^^^^^^^^
  File "/home/xxx/anaconda3/envs/py314/lib/python3.14/site-packages/numpy/_core/getlimits.py", line 216, in __new__
    obj = object.__new__(cls)._init(dtype)
  File "/home/xxx/anaconda3/envs/py314/lib/python3.14/site-packages/numpy/_core/getlimits.py", line 226, in _init
    _populate_finfo_constants(self, self.dtype)
    ~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^
ValueError: data type dtype('int64') not compatible with finfo
Python and NumPy Versions:
2.5.5
3.14.10 | packaged by Anaconda, Inc. | (main, Oct 27 2026, 01:15:40) [GCC 14.3.0]
Runtime Environment:
2.5.5
3.14.10 | packaged by Anaconda, Inc. | (main, Oct 27 2026, 01:15:40) [GCC 14.3.0]

[{'numpy_version': '2.5.5',
  'python': '3.14.10 | packaged by Anaconda, Inc. | (main, Oct 27 2026, '
            '01:15:40) [GCC 14.3.0]',
  'uname': uname_result(system='Linux', node='rog', release='6.17.0-29-generic', version='#29~24.04.1-Ubuntu SMP PREEMPT_DYNAMIC Mon May 11 10:30:58 UTC 2', machine='x86_64')},
 {'simd_extensions': {'baseline': ['X86_V2'],
                      'found': ['X86_V3', 'X86_V4', 'AVX512_ICL'],
                      'not_found': ['AVX512_SPR']}},
 {'ignore_floating_point_errors_in_matmul': False},
 {'architecture': 'SkylakeX',
  'filepath': '/home/jacin/anaconda3/envs/py314/lib/python3.14/site-packages/numpy.libs/libscipy_openblas64_-4b78795a.so',
  'internal_api': 'openblas',
  'num_threads': 16,
  'prefix': 'libscipy_openblas',
  'threading_layer': 'pthreads',
  'user_api': 'blas',
  'version': '0.3.34.237.2'}]
How does this issue affect you or how did you find it:

We are currently developing a computational framework based on NumPy. In the process of developing and testing this new framework, we encountered these practical issues, and we are submitting them in the hope that they can be resolved.

主要語言
Python
星號
33.5k
分支
13.1k
平均合併
1 天 19 小時
30 天內合併 PR
143

環境準備

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

numpy/numpy 的其他 Issue

查看 numpy/numpy 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。