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 15:20:02 UTC

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

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


##########
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:
   We use a `StructArray` in all such cases, e.g. the Mode kernel.



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