From 7c8c83ee4cc5b7d5aca9c829003ead8caac287cb Mon Sep 17 00:00:00 2001 From: Eduardo Ponce Date: Fri, 25 Jun 2021 11:06:45 -0400 Subject: [PATCH 1/9] add scalar API --- cpp/src/arrow/compute/api_scalar.cc | 3 +++ cpp/src/arrow/compute/api_scalar.h | 27 +++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/cpp/src/arrow/compute/api_scalar.cc b/cpp/src/arrow/compute/api_scalar.cc index 07e56d5f3d1..82adeb81c75 100644 --- a/cpp/src/arrow/compute/api_scalar.cc +++ b/cpp/src/arrow/compute/api_scalar.cc @@ -358,6 +358,9 @@ SCALAR_ARITHMETIC_BINARY(Power, "power", "power_checked") SCALAR_ARITHMETIC_BINARY(ShiftLeft, "shift_left", "shift_left_checked") SCALAR_ARITHMETIC_BINARY(ShiftRight, "shift_right", "shift_right_checked") SCALAR_EAGER_BINARY(Atan2, "atan2") +SCALAR_EAGER_UNARY(Floor, "floor") +SCALAR_EAGER_UNARY(Ceiling, "ceiling") +SCALAR_EAGER_UNARY(Truncate, "truncate") Result MaxElementWise(const std::vector& args, ElementWiseAggregateOptions options, ExecContext* ctx) { diff --git a/cpp/src/arrow/compute/api_scalar.h b/cpp/src/arrow/compute/api_scalar.h index 285e1eb4f51..569c6429c4a 100644 --- a/cpp/src/arrow/compute/api_scalar.h +++ b/cpp/src/arrow/compute/api_scalar.h @@ -487,6 +487,33 @@ ARROW_EXPORT Result Log1p(const Datum& arg, ArithmeticOptions options = ArithmeticOptions(), ExecContext* ctx = NULLPTR); +/// \brief Round down to the nearest integer. Array values can be of arbitrary +/// length. If argument is null the result will be null. +/// +/// \param[in] arg the value round +/// \param[in] ctx the function execution context, optional +/// \return the rounded value +ARROW_EXPORT +Result Floor(const Datum& arg, ExecContext* ctx = NULLPTR); + +/// \brief Round up to the nearest integer. Array values can be of arbitrary +/// length. If argument is null the result will be null. +/// +/// \param[in] arg the value round +/// \param[in] ctx the function execution context, optional +/// \return the rounded value +ARROW_EXPORT +Result Ceiling(const Datum& arg, ExecContext* ctx = NULLPTR); + +/// \brief Get the integral part of a value. Array values can be of arbitrary +/// length. If argument is null the result will be null. +/// +/// \param[in] arg the value to truncate +/// \param[in] ctx the function execution context, optional +/// \return the truncated value +ARROW_EXPORT +Result Truncate(const Datum& arg, ExecContext* ctx = NULLPTR); + /// \brief Find the element-wise maximum of any number of arrays or scalars. /// Array values must be the same length. /// From feab8d29cc29dd36e62b10d96e4a6d18bcc2f5f2 Mon Sep 17 00:00:00 2001 From: Eduardo Ponce Date: Thu, 15 Jul 2021 14:17:20 -0400 Subject: [PATCH 2/9] add impl floor, ceil, trunc kernels --- .../compute/kernels/scalar_arithmetic.cc | 60 ++++++++++++++++--- 1 file changed, 53 insertions(+), 7 deletions(-) diff --git a/cpp/src/arrow/compute/kernels/scalar_arithmetic.cc b/cpp/src/arrow/compute/kernels/scalar_arithmetic.cc index 28904bdbfa0..e15c4941378 100644 --- a/cpp/src/arrow/compute/kernels/scalar_arithmetic.cc +++ b/cpp/src/arrow/compute/kernels/scalar_arithmetic.cc @@ -817,6 +817,27 @@ struct Log1pChecked { } }; +struct Floor { + template + static constexpr enable_if_floating_point Call(KernelContext*, Arg arg, Status*) { + return std::floor(arg); + } +}; + +struct Ceiling { + template + static constexpr enable_if_floating_point Call(KernelContext*, Arg arg, Status*) { + return std::ceil(arg); + } +}; + +struct Truncate { + template + static constexpr enable_if_floating_point Call(KernelContext*, Arg arg, Status*) { + return std::trunc(arg); + } +}; + // Generate a kernel given an arithmetic functor template