cyb70289 commented on a change in pull request #9841:
URL: https://github.com/apache/arrow/pull/9841#discussion_r603736068
##########
File path: cpp/src/arrow/compute/kernels/scalar_arithmetic.cc
##########
@@ -18,11 +18,13 @@
#include "arrow/compute/kernels/common.h"
#include "arrow/util/int_util_internal.h"
#include "arrow/util/macros.h"
+#include "math.h"
Review comment:
#include \<cmath\>?
##########
File path: cpp/src/arrow/compute/kernels/scalar_arithmetic.cc
##########
@@ -233,6 +235,41 @@ struct DivideChecked {
}
};
+struct Exponentiate {
+ template <typename T, typename Arg0, typename Arg1>
+ static enable_if_integer<T> Call(KernelContext* ctx, Arg0 left, Arg1 right) {
+ if (left == 0 && (-INFINITY < right && right < 0)) {
+ ctx->SetStatus(Status::Invalid("divide by zero"));
Review comment:
For reference, error message from numpy for integer power:
```
In [2]: np.power(1, -1)
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-2-eff91c77f984> in <module>
----> 1 np.power(1, -1)
ValueError: Integers to negative integer powers are not allowed.
```
##########
File path: cpp/src/arrow/compute/kernels/scalar_arithmetic.cc
##########
@@ -233,6 +235,41 @@ struct DivideChecked {
}
};
+struct Exponentiate {
+ template <typename T, typename Arg0, typename Arg1>
+ static enable_if_integer<T> Call(KernelContext* ctx, Arg0 left, Arg1 right) {
Review comment:
`std::pow` always casts arguments to floating points, so this integer
version function is actually the same as floating point version.
I think integer power can be implemented separately by a simple O(logn)
power algorithm, and with overflow check.
##########
File path: cpp/src/arrow/compute/api_scalar.h
##########
@@ -204,6 +204,20 @@ Result<Datum> Divide(const Datum& left, const Datum& right,
ArithmeticOptions options = ArithmeticOptions(),
ExecContext* ctx = NULLPTR);
+/// \brief Compute the value of base value to the power of the exponent value.
Review comment:
Also document new functions at
https://github.com/apache/arrow/blob/master/docs/source/cpp/compute.rst#arithmetic-functions
--
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.
For queries about this service, please contact Infrastructure at:
[email protected]