edponce commented on a change in pull request #10349:
URL: https://github.com/apache/arrow/pull/10349#discussion_r705526272
##########
File path: cpp/src/arrow/compute/kernels/scalar_arithmetic.cc
##########
@@ -1276,6 +1496,65 @@ std::shared_ptr<ScalarFunction>
MakeUnaryArithmeticFunctionNotNull(
return func;
}
+// Generate a kernel given an arithmetic rounding functor
+template <template <RoundMode> class Op>
+ArrayKernelExec GenerateArithmeticRound(RoundMode rmode, detail::GetTypeId ty)
{
+ switch (rmode) {
+ case RoundMode::DOWN:
+ return GenerateArithmeticFloatingPoint<ScalarUnaryNotNull,
Op<RoundMode::DOWN>>(ty);
+ case RoundMode::UP:
+ return GenerateArithmeticFloatingPoint<ScalarUnaryNotNull,
Op<RoundMode::UP>>(ty);
+ case RoundMode::TOWARDS_ZERO:
+ return GenerateArithmeticFloatingPoint<ScalarUnaryNotNull,
+ Op<RoundMode::TOWARDS_ZERO>>(ty);
+ case RoundMode::TOWARDS_INFINITY:
+ return GenerateArithmeticFloatingPoint<ScalarUnaryNotNull,
+
Op<RoundMode::TOWARDS_INFINITY>>(ty);
+ case RoundMode::HALF_DOWN:
+ return GenerateArithmeticFloatingPoint<ScalarUnaryNotNull,
+ Op<RoundMode::HALF_DOWN>>(ty);
+ case RoundMode::HALF_UP:
+ return GenerateArithmeticFloatingPoint<ScalarUnaryNotNull,
Op<RoundMode::HALF_UP>>(
+ ty);
+ case RoundMode::HALF_TOWARDS_ZERO:
+ return GenerateArithmeticFloatingPoint<ScalarUnaryNotNull,
+
Op<RoundMode::HALF_TOWARDS_ZERO>>(ty);
+ case RoundMode::HALF_TOWARDS_INFINITY:
+ return GenerateArithmeticFloatingPoint<ScalarUnaryNotNull,
+
Op<RoundMode::HALF_TOWARDS_INFINITY>>(ty);
+ case RoundMode::HALF_TO_EVEN:
+ return GenerateArithmeticFloatingPoint<ScalarUnaryNotNull,
+ Op<RoundMode::HALF_TO_EVEN>>(ty);
+ case RoundMode::HALF_TO_ODD:
+ return GenerateArithmeticFloatingPoint<ScalarUnaryNotNull,
+ Op<RoundMode::HALF_TO_ODD>>(ty);
+ default:
+ DCHECK(false);
+ return ExecFail;
+ }
+}
+
+// Like MakeUnaryArithmeticFunction, but for unary rounding functions that
control
+// kernel dispatch based on RoundMode, only on non-null output.
+template <template <RoundMode> class Op, typename OptionsType>
+std::shared_ptr<ScalarFunction> MakeUnaryRoundFunction(std::string name,
+ const FunctionDoc* doc)
{
+ using State = RoundOptionsWrapper<OptionsType>;
+
+ static const OptionsType kDefaultOptions = OptionsType::Defaults();
+ auto func = std::make_shared<ArithmeticFloatingPointFunction>(name,
Arity::Unary(), doc,
+
&kDefaultOptions);
+ for (const auto& ty : FloatingPointTypes()) {
+ auto exec = [&](KernelContext* ctx, const ExecBatch& batch, Datum* out) {
+ auto options = State::Get(ctx);
+ auto exec_ = GenerateArithmeticRound<Op>(options.round_mode, ty);
Review comment:
Actually, it is doing the same thing as the other kernels. Other kernels
pass `exec` (an `ArrayKernelExec`) to the `AddKernel` method without invoking
it. `exec` is invoked during kernel dispatching because it requires
`KernelContext, ExecBatch, and Datum` parameters.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]