Skip to content

Finish reorganization of "dtype transfer" casting code with new dtypes #9

Closed

Description

@seberg

@mattip the current central function for dtype transfer in NumPy is here:

PyArray_GetDTypeTransferFunction(int aligned,

This function already uses the new code largely, but the input and/or output can be misaligned or byte swapped. In that case casting_impl->get_transferfunction is allowed to pass back dtypes that that are different from the input dtypes.

This means that multiple "casts" are needed (for alignment it is always needed in that sense):

  1. Do input cast input_dtype -> "input_dtype_returned_by casting_impl->get_transferfunction" (normally this should be byte swapping)
  2. Do the actual cast.
  3. Do output cast "output_dtype_returned_by casting_impl->get_transferfunction" -> output_dtype.

Another example I could imagine/allow: float -> string cast always returns S32, so the string might need to be shortened or zero padded.

The current machinery uses the NPY_AUXDATA, etc. to already implement chaining when necessary, the new should actually be simpler, because 3 steps are always enough.

Right now I have the get_transferfunction signature on the DTypes, which is modelled after the existing function. Both are private API, so they can be changed.

Activity

  1. self-assigned this
    on Nov 20, 2019
  2. added a commit that references this issue on Nov 27, 2019
  3. added a commit that references this issue on Dec 7, 2021
  4. mattip commented on Jul 27, 2023

    @mattip
    Collaborator

    Going through old issues, I think we can close this, right?

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

Metadata

Metadata

Assignees

Labels

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions