-
Notifications
You must be signed in to change notification settings - Fork 49
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
RFC: add a unified inspection API namespace #640
Comments
This looks quite good to me, thanks @kgryte.
Minor: True/False please, rather than 0/1.
Minor: probably better if those keys exactly match the string names used by isdtype. |
Updated in OP.
Agreed. I had a momentary lapse and got my programming languages mixed up. Updated. |
During the previous workgroup meeting focusing on the array API standard (15 June 2023), no objections were raised to this RFC and adding the proposed namespace was greenlit to move forward for inclusion in the 2023 revision of the array API specification. As #635, #636, #637, and #638 are superseded by this RFC, they are no longer applicable and have been closed. |
Should we (as in I'd very much like that) add a statement about how dtypes should be ordered? In particular should it be: >>> info.dtypes(kind="real floating")
[xp.float64, xp.float32] or >>> info.dtypes(kind="real floating")
[xp.float32, xp.float64] and similarly when you have a mix of integers and floats. The use case for having a specified ordering would be being able to answer questions like "is there a float64 and if not, what is the next highest precision type?" |
A few points we discussed last week:
|
This RFC is intended to supersede #635, #636, #637, and #638, based on initial consortium feedback, and proposes to consolidate inspection APIs into a single non-public namespace.
Proposal
Returns a namespace with Array API namespace inspection utilities.
Note: the
x.__array_namespace__()
API supports aversion
kwarg. We don't follow suit here, as we assume backward compatibility, whereby a consumer may ask for a particular version of the array API standard and a conforming library may return a newer version. That version should still be compliant with the older specified version (backward compat guarantee), and thus, the inspection API return values should still be applicable. Stated more succinctly: conforming array libraries are expected to be "evergreen" and only have a single Array API implementation, not separate implementations for each revision of the standard.Methods
info.capabilities() -> dict[str,bool]
Returns a dictionary of static "capabilities", such as whether a conforming library supports boolean indexing or data-dependent output shapes.
Key values should be either
False
(does not support) orTrue
(does support). For example,info.default_device() -> device
Returns an object for the default device.
info.default_dtypes( /, *, device: device) -> dict[str, dtype]
Returns a dictionary having the following keys:
More keys could be added in the future, depending on evolution of the standard.
If not provided a
device
argument, the function would return a dictionary based on the current device (context). If provided adevice
argument, the function would return a dictionary as described above, but specific to the specified device.info.dtypes( /, *, device: device, kind: Union[str, Tuple[str, ...]]) -> dict[str,dtype]
Returns a dictionary of supported Array API data types (in canonical form; e.g.,
float64
,float32
,int32
, etc).Similar to the
isdtype
API, the function would support a "kind" kwarg for returning a dictionary of supported Array API data types belonging to the specified kind. The following kinds should be supported, matching theisdtype
API:'bool'
: boolean data types (e.g., bool).'signed integer'
: signed integer data types (e.g., int8, int16, int32, int64).'unsigned integer'
: unsigned integer data types (e.g., uint8, uint16, uint32, uint64).'integral'
: integer data types. Shorthand for ('signed integer', 'unsigned integer').'real floating'
: real-valued floating-point data types (e.g., float32, float64).'complex floating'
: complex floating-point data types (e.g., complex64, complex128).'numeric'
: numeric data types. Shorthand for ('integral', 'real floating', 'complex floating').If not provided a
device
argument, the function should return a dictionary of supported data types for the current device (context). If provided adevice
argument, the function should return a dictionary of supported data types for the specified device.Note: a
hasattr
check is not sufficient as a means of determining dtype support, as dtype support can vary depending on the device. A conforming array library may be fully compliant for its default device, but unable to be fully compliant on other supported devices. In which case, simply checking whether adtype
object exists in the main namespace is insufficient to determine whether a downstream consumer can actually use a specificdtype
object for a particular device/execution context.info.devices()
Returns a list of supported devices.
Related Links
The text was updated successfully, but these errors were encountered: