logaddexp() of integer arrays gives float32, where NumPy gives float64

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

維護者通常 2 天內回覆

還沒有人認領這個 Issue。

評估

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

研究方向

閱讀 src/blosc2/ndarray.py 中的 logaddexp(),並將其整數結果 dtype 與 issue 中描述的 NumPy 行為進行比較。檢查直接呼叫和 blosc2.lazyexpr("logaddexp(a, b)", ...) 形式,並涵蓋列出的整數位元寬度。兩種形式都回傳相符的 dtype,並保留較大整數所示範的精度,即為完成。

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

描述

blosc2.logaddexp() sets the result dtype to float32 whenever its operands' result type is an integer (logaddexp() in src/blosc2/ndarray.py: if np.issubdtype(dtype, np.integer): dtype = blosc2.float32). NumPy uses the float type that holds the operands: float64 for 32- and 64-bit integers, float32 for 16-bit ones and float16 for 8-bit ones. The string form, blosc2.lazyexpr("logaddexp(a, b)", ...), gives float32 too. Larger integers lose precision:

import numpy as np
import blosc2

x = np.array([2**24 + 1])           # int64
a = blosc2.asarray(x)
blosc2.logaddexp(a, a).dtype        # float32             NumPy: float64
blosc2.logaddexp(a, a)[:]           # [16777218.]         NumPy: [16777217.69314718]
operands blosc2 NumPy
int8 float32 float16
int16 float32 float32
int32, int64, uint32 float32 float64

The same on main and with #741. Found while checking #754, which does not change logaddexp().

Bool operands raise TypeError: logaddexp doesn't accept boolean arguments., where NumPy gives float16. That may be on purpose, since the docstring asks for floating-point operands, as the array API does.

A fix could take the dtype from NumPy on empty operands, as #754 does for hypot() and the other two-argument float functions. I can send a PR for it if you like.

AI disclosure: the analysis was done with Claude Code; I reviewed it.

主要語言
Python
星號
214
分支
72
平均合併
3 天 9 小時
30 天內合併 PR
24

環境準備

在 Codespaces 中開啟

在瀏覽器裡用你自己的 GitHub 帳號啟動這個專案的開發容器。

  • 沒有 Dockerfile 或 Docker Compose 檔案
  • 沒有 Pull Request 範本
  • 閱讀貢獻指南

從這裡開始

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

Blosc/python-blosc2 的其他 Issue

查看 Blosc/python-blosc2 的全部 Issue

相似的 Issue

更多 Python Issue

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

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