You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "pitrou (via GitHub)" <gi...@apache.org> on 2024/11/08 16:31:58 UTC

Re: [PR] GH-44393: [C++][Compute] Swizzle vector functions [arrow]

pitrou commented on code in PR #44394:
URL: https://github.com/apache/arrow/pull/44394#discussion_r1834697105


##########
cpp/src/arrow/compute/api_vector.h:
##########
@@ -705,5 +737,52 @@ Result<std::shared_ptr<Array>> PairwiseDiff(const Array& array,
                                             bool check_overflow = false,
                                             ExecContext* ctx = NULLPTR);
 
+/// \brief Return the inverse permutation of the given indices.
+///
+/// For indices[i] = x, inverse_permutation[x] = i. And inverse_permutation[x] = null if x
+/// does not appear in the input indices. For indices[i] = x where x < 0 or x > max_index,
+/// it is ignored. If multiple indices point to the same value, the last one is used.
+///
+/// For example, with indices = [null, 0, 3, 2, 4, 1, 1], the inverse permutation is
+///   [1, 6, 3]                    if max_index = 2,
+///   [1, 6, 3, 2, 4, null, null]  if max_index = 6.
+///
+/// \param[in] indices array-like indices
+/// \param[in] options configures the max index and the output type
+/// \param[in] ctx the function execution context, optional
+/// \return the resulting inverse permutation
+///
+/// \since 19.0.0
+/// \note API not yet finalized
+ARROW_EXPORT
+Result<Datum> InversePermutation(
+    const Datum& indices,
+    const InversePermutationOptions& options = InversePermutationOptions::Defaults(),
+    ExecContext* ctx = NULLPTR);
+
+/// \brief Scatter the values into specified positions according to the indices.
+///
+/// For indices[i] = x, output[x] = values[i]. And output[x] = null if x does not appear
+/// in the input indices. For indices[i] = x where x < 0 or x > max_index, values[i]
+/// is ignored. If multiple indices point to the same value, the last one is used.

Review Comment:
   ```suggestion
   /// in the input indices. For indices[i] = x where x < 0 or x > max_index, values[i]
   /// is ignored. If multiple indices point to the same value, the last one is used.
   ```
   Can you explain the point of the lenient behavior wrt. negative indices and the max_index option?
   Is there a use case that this enables?



-- 
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