You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@arrow.apache.org by "ypomortsev (via GitHub)" <gi...@apache.org> on 2026/10/21 22:29:29 UTC

[I] [C++][Compute] `inverse_permutation` and `scatter` should accept unsigned integers [arrow]

ypomortsev opened a new issue, #54920:
URL: https://github.com/apache/arrow/issues/54920

   ### 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))`.
   
   `inverse_permutation` kernel explicitly checks for negative indices (https://github.com/apache/arrow/blob/main/cpp/src/arrow/compute/kernels/vector_swizzle.cc#L209):
   
   ```python
   indices = pa.array([0, -1, -2, -3])
   pc.inverse_permutation(indices)
   # ArrowIndexError: Index out of bounds: -1
   ```
   
   Additionally,
   
   * `inverse_permutation` has kernels only for signed integers (https://github.com/apache/arrow/blob/main/cpp/src/arrow/compute/kernels/vector_swizzle.cc#L209)
   * `scatter` explicitly checks the type (https://github.com/apache/arrow/blob/main/cpp/src/arrow/compute/kernels/vector_swizzle.cc#L366)
   
   In the original PR, @pitrou brought up a concern about codegen size with supporting both, so only signed was implemented (https://github.com/apache/arrow/pull/44394#discussion_r1878473668) 
   
   ### Component(s)
   
   Other


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@arrow.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] [Other][C++][Compute] `inverse_permutation` and `scatter` should accept unsigned integers [arrow]

Posted by "pitrou (via GitHub)" <gi...@apache.org>.
pitrou commented on issue #54920:
URL: https://github.com/apache/arrow/issues/54920#issuecomment-6342613922

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


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] [C++][Compute] `inverse_permutation` and `scatter` should accept unsigned integers [arrow]

Posted by "zanmato1984 (via GitHub)" <gi...@apache.org>.
zanmato1984 commented on issue #54920:
URL: https://github.com/apache/arrow/issues/54920#issuecomment-6379376419

   I can work on that.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] [Other][C++][Compute] `inverse_permutation` and `scatter` should accept unsigned integers [arrow]

Posted by "ypomortsev (via GitHub)" <gi...@apache.org>.
ypomortsev commented on issue #54920:
URL: https://github.com/apache/arrow/issues/54920#issuecomment-6350177173

   Right, the signed implementation can use the fact that valid signed values are the same bitwise as unsigned, e.g. pseudocode
   ```python
   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)
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org