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

オープン 初心者向け
#757 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 2 日以内に返信

まだ誰も着手していません。

評価

難易度
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時間
マージ済み PR(30日)
24

環境構築

Codespaces で開く

このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

Blosc/python-blosc2 のほかの issue

Blosc/python-blosc2 の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。