question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

finfo should not require float type for the result fields

See original GitHub issue

Right now finfo requires that the output fields be float 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:

>>> import numpy as np
>>> np.finfo(np.float128)
finfo(resolution=1.0000000000000000715e-18, min=-1.189731495357231765e+4932, max=1.189731495357231765e+4932, dtype=float128)
>>> float('-1.189731495357231765e+4932')
-inf

float is essentially a float64, so the various values for float128 cannot be represented as floats. NumPy uses scalars for the values, which for the spec would be 0-D arrays:

>>> type(np.finfo(np.float128).min)
<class 'numpy.float128'>

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 for finfo, since float and a 0-D array aren’t 100% duck type compatible.

For iinfo obviously this problem isn’t present since int 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 that numpy.iinfo just uses int for its fields).

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:2
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

3reactions
rgommerscommented, Mar 21, 2022

This is not a proposal that I immediately think is a good idea, because:

  • There are no current issues, only a hypothetical future one. NumPy is the only library with a >64-bits dtype, and it has array scalars too so there’s only a problem if it really becomes possible to completely remove array scalars.
    • Side note: I hope we can get rid of float96/float128 in NumPy, because they’re a massive pain and a not-so-useful relic of the past.
  • It’d be a breaking change for every library that has finfo and wants to implement array API standard support in its main namespace (which long-term is everyone I hope), not just PyTorch.

If we designed this from scratch with no concern for backwards compatibility, then I’d agree 0-D arrays would be preferred.

2reactions
leofangcommented, Mar 21, 2022

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 🙂

Read more comments on GitHub >

github_iconTop Results From Across the Web

11.1.4 Floating-Point Types (Approximate Value) - ...
The FLOAT and DOUBLE types represent approximate numeric data values. MySQL uses four bytes for single-precision values and eight bytes for double-precision ...
Read more >
ArcGIS field data types
Floats in file and personal geodatabases can precisely store numbers that contain up to 6 digits only. For example, you could not store...
Read more >
Numeric field types | Elasticsearch Guide [master]
If scaled_float is not a good fit, then you should pick the smallest type that is enough for the use-case among the floating-point...
Read more >
Types of fields and field data - Dynamics 365
Use floating point numbers when you store data that represents fractions or values that you will typically query comparing to another value ...
Read more >
Numeric field types
float, A single-precision 32-bit IEEE 754 floating-point value. Minimum magnitude is 2 -149 . Maximum magnitude is (2 − 2 -23 ) ·...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found