-
Notifications
You must be signed in to change notification settings - Fork 53
PR: Add finfo and iinfo in the spec #129
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
Changes from 1 commit
8c414d6
39a9cb2
79dc82c
2cc6683
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
# Data type functions | ||
|
||
> Array API specification for data type functions. | ||
|
||
A conforming implementation of the array API standard must provide and support the following data type functions. | ||
|
||
<!-- NOTE: please keep the constants in alphabetical order --> | ||
|
||
## Objects in API | ||
|
||
(finfo)= | ||
### finfo(type) | ||
|
||
Defines the machine limits for floating point types. | ||
steff456 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
#### Parameters | ||
|
||
- **type**: _Union\[ float, <dtype>, instance ]_ | ||
steff456 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
- the kind of floating point data-type about which to get information | ||
steff456 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
#### Returns | ||
|
||
- **out**: _<class>_ | ||
|
||
- a class with that encapsules the following attributes: | ||
steff456 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
- **bits**: _int_ | ||
- The number of bits occupied by the type | ||
- **eps**: _float_ | ||
- The difference between 1.0 and the next smallest representable float larger than 1.0 following the IEEE 754 standard. | ||
- **max**: _float_ | ||
- The largest representable number. | ||
- **min**: _float_ | ||
- The smallest representable number. | ||
- **tiny**: _float_ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @kgryte do you happen to know if this is guaranteed to be the same across implementations? I.e. it's part of IEEE 754 somehow? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is what the NumPy docs have in their notes:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No. While part of IEEE 754, support for subnormal numbers is less common, especially among older generation GPUs. Often subnormal numbers trigger slow paths, and, if not implemented in hardware, software emulation. More recent NVIDIA GPUs do support subnormal numbers. And among ARM processors, one can flush subnormal numbers to zero. Based on NumPy docs (via @steff456 ), There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Interesting. So the description is a bit off here. I'm not sure it should be part of the standard. I can imagine it may be useful in a few corner cases, but I've never seen it used in the wild. Let's see if anyone else has an opinion. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay, so there are use cases at the compiled code level at least. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suppose having this info is useful for meta inspection concerning platform capabilities. For example, if I want to know whether a platform supports subnormals. Apart from meta data, a user would need to compute a quantity which should resolve to a subnormal number and manually check whether the value is zero. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Correct. It can also come up in user code, e.g., in the computation of transcendentals, where, if you know that a platform does not support subnormals, then you can avoid various, often slower, branching logic. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think if we wanted to be complete, instead of "tiny", we'd have There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Those do seem like better names indeed. TF and CuPy just alias I think we can add the new names, but then we should make a PR to NumPy to see if that's accepted. And otherwise we should probably drop it completely.
steff456 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
- The smallest positive representable number. | ||
steff456 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
- **resolution**: _float_ | ||
steff456 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
- The approximate decimal resolution of this type. | ||
|
||
(iinfo)= | ||
### iinfo(type) | ||
|
||
Defines the machine limits for integer types. | ||
steff456 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
#### Parameters | ||
|
||
- **type**: _Union\[ integer, <dtype>, instance ]_ | ||
|
||
- the kind of integer data-type about which to get information | ||
steff456 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
#### Returns | ||
|
||
- **out**: _<class>_ | ||
|
||
- a class with that encapsules the following attributes: | ||
|
||
- **bits**: _int_ | ||
- The number of bits occupied by the type | ||
- **max**: _int_ | ||
- The largest representable number. | ||
- **min**: _int_ | ||
- The smallest representable number. | ||
steff456 marked this conversation as resolved.
Show resolved
Hide resolved
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
type
should be a positional argument here, so this should befinfo(type, /)
.And same for
iinfo
.