-
Notifications
You must be signed in to change notification settings - Fork 50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
finfo should not require float type for the result fields #405
Comments
Thanks for opening this issue @asmeurer. Agreed that 0-D arrays probably make the most sense here. As we've already departed from NumPy behavior for reductions (e.g., Given that NumPy, CuPy, etc have the array API implementation under an experimental status, probably not too late to make this change for these libraries. However, Torch is already shipping @rgommers perhaps you have thoughts? |
This is not a proposal that I immediately think is a good idea, because:
If we designed this from scratch with no concern for backwards compatibility, then I'd agree 0-D arrays would be preferred. |
I don't have strong opinion here, but whatever we do for finfo it must be done consistently for other constants as well: https://data-apis.org/array-api/latest/API_specification/constants.html |
gh-154 is the discussion on constants. The reason for them to be included was different though: #154 (comment). I don't think we ever discussed making constants 0-D arrays, only whether to include them or not. |
No we didn't discuss making them 0D arrays, but both pi, e, etc and finfo are constants that require uniform treatments in the standard. If there is desire to keep pi on GPU, it's equally possible there's desire to have eps stay on GPU 🙂 |
(So, in short, I'm just adding another reason for finfo to keep floating type) |
One other concern similar to >>> import decimal
>>> d = decimal.Decimal('0.142857')
>>> x = np.array([d, d])
>>> x
array([Decimal('0.142857'), Decimal('0.142857')], dtype=object)
>>> np.finfo(x)
Traceback (most recent call last):
Input In [12] in <cell line: 1>
np.finfo(x)
File ~/anaconda3/envs/dev/lib/python3.9/site-packages/numpy/core/getlimits.py:473 in __new__
raise ValueError("data type %r not inexact" % (dtype))
ValueError: data type <class 'numpy.object_'> not inexact @jakirkham mentioned that cuDF has a native decimal dtype, so that could in principle be made to work with A >64-bit type like So the proposed solution to close this issue is: add a new section to the standard which explicitly mentions that it's fine to implement duck type objects, the reasons why libraries may do that, and give examples for constants ( |
Right now
finfo
requires that the output fields befloat
https://data-apis.org/array-api/latest/API_specification/generated/signatures.data_type_functions.finfo.html#signatures.data_type_functions.finfo. However, making the results 0-D arrays would be better.For the spec itself,
float
is fine, but it's problematic for any library that implements higher precision data types like float128:float
is essentially a float64, so the various values forfloat128
cannot be represented as floats. NumPy uses scalars for the values, which for the spec would be 0-D arrays:Even if there are no plans to add
float128
to the spec, it's useful for libraries that do have it to have a consistent return type forfinfo
, sincefloat
and a 0-D array aren't 100% duck type compatible.For
iinfo
obviously this problem isn't present sinceint
can represent any integer, but it may be good to change it to 0-D array as well just for consistency (although I should note thatnumpy.iinfo
just usesint
for its fields).The text was updated successfully, but these errors were encountered: