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 摘要。