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

Đang mở Phù hợp với người mới
#757 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 2 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
74/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
numpy, python
Lĩnh vực
backend, data

Hướng nghiên cứu

Đọc logaddexp() trong src/blosc2/ndarray.py và so sánh dtype của kết quả số nguyên với hành vi của NumPy được mô tả trong issue. Kiểm tra cả lời gọi trực tiếp lẫn dạng blosc2.lazyexpr("logaddexp(a, b)", ...), bao gồm các độ rộng số nguyên được liệt kê. Hoàn thành khi cả hai dạng trả về dtype tương ứng và giữ được độ chính xác đã minh họa với các số nguyên lớn hơn.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
Python
Star
214
Fork
72
Merge trung bình
3 ngày 9 giờ
Pull request đã merge (30 ngày)
24

Chuẩn bị môi trường

Mở trong Codespaces

Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của Blosc/python-blosc2

Tất cả issue của Blosc/python-blosc2

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.