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

Add specification for explicitly casting an array to a specified dtype #290

Merged
merged 6 commits into from
Nov 1, 2021

Conversation

kgryte
Copy link
Contributor

@kgryte kgryte commented Oct 21, 2021

This PR

  • specifies an astype API for explicitly casting an array to a specified dtype.
  • adds a functional API rather than an array object method following conventions set forth in this specification to maintain a minimal array object API.
  • uses the astype name to mirror the NumPy array object method x.astype().
  • includes a copy kwarg to allow returning the input array iff copy is False and the specified dtype matches the data type of the input array. Every library except TensorFlow supports this kwarg. During the consortium meeting on 21 October 2021, TF supported including the copy kwarg in the specification.
  • updates conversion guidance for asarray to only require support for conversions following type promotion rules described in this specification. With the addition of astype, overloading asarray with comprehensive casting semantics for input arrays is not necessary.
  • resolves Cross-kind casting in asarray() #264.

Prior Art

  • TF cast: only supports providing a dtype argument.
  • NumPy x.astype: supports order, casting, and copy kwargs.
  • CuPy x.astype: supports order and copy kwargs.
  • Dask x.astype: supports casting and copy kwargs.
  • Torch to: supports copy and device kwargs.
  • MXNet x.astype: supports copy kwarg.

@kgryte kgryte added API extension Adds new functions or objects to the API. topic: Creation Array creation. topic: Type Promotion Type promotion. labels Oct 21, 2021
@kgryte kgryte added this to the v2021 milestone Oct 21, 2021
@kgryte
Copy link
Contributor Author

kgryte commented Nov 1, 2021

This change was discussed and agreed upon during the consortium meeting held on 21 October 2021. Merging...

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. topic: Creation Array creation. topic: Type Promotion Type promotion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cross-kind casting in asarray()
1 participant