Skip to content
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 API to return the list of currently supported dtypes #635

Closed
kgryte opened this issue Jun 1, 2023 · 2 comments
Closed

RFC: add API to return the list of currently supported dtypes #635

kgryte opened this issue Jun 1, 2023 · 2 comments
Labels
API extension Adds new functions or objects to the API.

Comments

@kgryte
Copy link
Contributor

kgryte commented Jun 1, 2023

This RFC proposes to add an API to the standard for returning the list of currently supported dtypes. Currently, in order to query dtype support, one must do something like

hasattr(xp, "uint32")

and do so for each dtype specified in the array API standard. This is less than ideal, especially when testing. Additionally, this approach only works for known (i.e., specified) dtypes. One lacks a universal mechanism for dtype inspection (e.g., in a REPL). This RFC proposes to rectify this gap.

Prior art

To my knowledge, none of NumPy, JAX, PyTorch, TensorFlow, Dask, or MXNet support a common API for querying supported dtypes.

Proposal

dtypes() -> List[dtype]
dtypes(device: device) -> List[dtype]

If not provided an argument, the proposed API would return a list of currently supported dtype objects.

If provided a device, the proposed API would return a list of supported dtype objects applicable to the specified device.

Notes

  • When the proposed API is invoked without an argument, the list of currently supported dtypes would be based on the current device context. As discussed in the standard

    ...it is possible that a library supports multiple devices, with not all those device types supporting the same data types.

    For libraries supporting a single device (e.g., currently NumPy and CPU), dtypes() would always return the same list. For libraries supporting multiple devices, the list of dtypes returned by dtypes() could vary.

    For downstream users, they should be advised to not assume that dtypes() always returns the same list, especially when designing APIs intended to be array library agnostic.

Related

@kgryte kgryte added the API extension Adds new functions or objects to the API. label Jun 1, 2023
@kgryte
Copy link
Contributor Author

kgryte commented Jun 15, 2023

Update: updated the OP to include a device kwarg.

@kgryte
Copy link
Contributor Author

kgryte commented Jun 29, 2023

This RFC has been superseded by #640.

@kgryte kgryte closed this as completed Jun 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API extension Adds new functions or objects to the API.
Projects
None yet
Development

No branches or pull requests

1 participant