Skip to content

add support for dtype kinds in astype #339

Open

Description

@lucascolley

Activity

  1. ev-br commented on Oct 28, 2025

    @ev-br
    Member

    This seems to have slipped under the radar. Could you remind me what are the motivating use cases? IIUC, one was float32->complex64, which is now IMO adequately handled by 1j*float32_array -> complex64_array. Was there something about signed/unsigned integers? My search-foo is failing me

  2. lucascolley commented on Oct 28, 2025

    @lucascolley
    MemberAuthor

    Hmm, not sure if there was a real-world motivating case for signed/unsigned integers, but in general I still think this is rather nice to have. Suppose you are using something like this in a context of parametrising over dtype kinds, something like

    dtype_id = 1.0 if dtype_kind=="float" else 1j # or more cases
    x *= dtype_id

    can become

    x = xp.astype(x, kind=dtype_kind)

    which is not only cleaner but also semantically much nicer IMO!

  3. ev-br commented on Oct 29, 2025

    @ev-br
    Member

    This is the int/uint discussion I was trying to remember:
    data-apis/array-api#859 (comment)

  4. lucascolley commented on Jun 5, 2026

    @lucascolley
    MemberAuthor

    any further thoughts @ev-br ?

  5. lucascolley commented on Jun 26, 2026

    @lucascolley
    MemberAuthor

    gentle bump

  6. ev-br commented on Jun 30, 2026

    @ev-br
    Member

    (Assuming the ping is for me) thanks for the ping! I'm bandwidth-limited for next the couple of weeks at least, won't be able get to it "soon".

  7. lucascolley commented on Aug 12, 2026

    @lucascolley
    MemberAuthor

    gentle bump @ev-br, would you be happy to see a PR for this?

  8. ev-br commented on Aug 13, 2026

    @ev-br
    Member

    Yes certainly! Happy to review a PR for this

  9. lucascolley commented on Aug 13, 2026

    @lucascolley
    MemberAuthor

    I took a brief look at implementing a close-to-array-agnostic version of this, but I think it is quite difficult to satisfy the 'lowest-precision data type' clauses of the spec with the tools we currently have available in the standard.

    On the bright side, that gives me confidence that adding this to the standard is the right way to go. I think it does mean, though, that the implementations in array-api-compat will be better off leaning heavily on promotion utilities specific to each array library, or perhaps hardcoding known lowest-precision dtypes / promotion tables.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions