You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2022/07/19 14:37:54 UTC

[GitHub] [arrow] edponce commented on a diff in pull request #11115: ARROW-12084: [C++][Compute] Add remainder and quotient compute::Function

edponce commented on code in PR #11115:
URL: https://github.com/apache/arrow/pull/11115#discussion_r924585304


##########
cpp/src/arrow/compute/kernels/scalar_arithmetic.cc:
##########
@@ -1001,6 +1001,95 @@ struct Trunc {
   }
 };
 
+// TODO(edponce): Move builders to function state and reset.
+struct Divmod {
+  template <typename T, typename Arg0, typename Arg1>
+  static enable_if_floating_value<T, FixedSizeListScalar> Call(KernelContext* ctx, Arg0 dividend, Arg1 divisor, Status* st) {
+    T quotient = std::floor(dividend / divisor);
+    T remainder = dividend - quotient * divisor;
+
+    NumericBuilder<T> builder;
+    builder.Append(quotient);
+    builder.Append(remainder);
+    std::shared_ptr<Array> array;
+    builder.Finish(&array);
+    FixedSizeListScalar list(array, builder.type())

Review Comment:
   I know, although we can cache the builder but still need to create the `FixedSizeListScalar`. I have not found a reasonable solution for the output of this kernel or more generally:
   **What scalar and array types to use for a kernel that outputs multiple values?**
   Any suggestions on how to return a pair of values (same type) from a kernel?
   cc @pitrou 
   
   Ideas:
   * Return an Array that is twice as large - drawback is that output indices are of the form: `2i, 2i+1`
   * Return a `StructArray` or `MapArray` - require a key-value pair during construction, these structures support different value types
   * Return a `FixedSizeListArray`



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