Skip to content

[Other][C++][Compute] inverse_permutation and scatter should accept unsigned integers #54920

Open

Description

@ypomortsev

Describe the enhancement requested

The compute functions inverse_permutation and scatter accept arrays of indices that are can only be be signed integers. This limits the range of indices that they can accept, and may force the user into doing an unnecessary cast.

For context, scatter is implemented as Take(values, InversePermutation(indices)).

The inverse_permutation kernel explicitly checks for negative indices:

if (ARROW_PREDICT_FALSE(index < 0 ||

indices = pa.array([0, -1, -2, -3])
pc.inverse_permutation(indices)
# ArrowIndexError: Index out of bounds: -1

Additionally,

In the original PR, @pitrou brought up a concern about codegen size with supporting both, so only signed was implemented (#44394 (comment))

Component(s)

Other

Activity

  1. changed the title [-][C++][Compute] `inverse_permutation` and `scatter` should accept unsigned integers[/-] [+][Other][C++][Compute] `inverse_permutation` and `scatter` should accept unsigned integers[/+] on Oct 21, 2026
  2. pitrou commented on Oct 22, 2026

    @pitrou
    Member

    The code size concern is genuine, but perhaps we can base the signed implementations on the unsigned ones?

  3. ypomortsev commented on Oct 22, 2026

    @ypomortsev
    Author

    Right, the signed implementation can use the fact that valid signed values are the same bitwise as unsigned, e.g. pseudocode

    signed_idx = pa.array([0, 1, 2, 3], pa.int32())
    if pc.min(signed_idx) >= 0:
        raise ArrowIndexError
    unsigned_idx = pa.view(signed_idx, pa.uint32())
    return pc.inverse_permutation(unsigned_idx)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions