pitrou commented on code in PR #44904:
URL: https://github.com/apache/arrow/pull/44904#discussion_r1866060301
##########
cpp/src/arrow/compute/kernels/scalar_arithmetic_test.cc:
##########
@@ -1563,6 +1563,97 @@ TEST_F(TestUnaryArithmeticDecimal, Exp) {
}
}
+TYPED_TEST(TestUnaryArithmeticUnsigned, Expm1) {
+ auto expm1 = [](const Datum& arg, ArithmeticOptions, ExecContext* ctx) {
+ return Expm1(arg, ctx);
+ };
+ // Empty arrays
+ this->AssertUnaryOp(expm1, "[]", ArrayFromJSON(float64(), "[]"));
+ // Array with nulls
+ this->AssertUnaryOp(expm1, "[null]", ArrayFromJSON(float64(), "[null]"));
+ this->AssertUnaryOp(expm1, this->MakeNullScalar(),
arrow::MakeNullScalar(float64()));
+ this->AssertUnaryOp(
+ expm1, "[null, 1, 10]",
+ ArrayFromJSON(float64(), "[null, 1.718281828459045,
22025.465794806718]"));
+ this->AssertUnaryOp(expm1, this->MakeScalar(1),
+ arrow::MakeScalar<double>(1.718281828459045F));
Review Comment:
I'm curious, why the "F" suffix to the litteral?
##########
cpp/src/arrow/compute/api_scalar.h:
##########
@@ -684,6 +684,18 @@ Result<Datum> Power(const Datum& left, const Datum& right,
ARROW_EXPORT
Result<Datum> Exp(const Datum& arg, ExecContext* ctx = NULLPTR);
+/// \brief More accurately calculates `exp(arg) - 1` for values close to zero.
Review Comment:
```suggestion
/// \brief More accurately calculate `exp(arg) - 1` for values close to zero.
```
##########
cpp/src/arrow/compute/kernels/scalar_arithmetic_test.cc:
##########
@@ -1563,6 +1563,97 @@ TEST_F(TestUnaryArithmeticDecimal, Exp) {
}
}
+TYPED_TEST(TestUnaryArithmeticUnsigned, Expm1) {
+ auto expm1 = [](const Datum& arg, ArithmeticOptions, ExecContext* ctx) {
+ return Expm1(arg, ctx);
+ };
+ // Empty arrays
+ this->AssertUnaryOp(expm1, "[]", ArrayFromJSON(float64(), "[]"));
+ // Array with nulls
+ this->AssertUnaryOp(expm1, "[null]", ArrayFromJSON(float64(), "[null]"));
+ this->AssertUnaryOp(expm1, this->MakeNullScalar(),
arrow::MakeNullScalar(float64()));
+ this->AssertUnaryOp(
+ expm1, "[null, 1, 10]",
+ ArrayFromJSON(float64(), "[null, 1.718281828459045,
22025.465794806718]"));
+ this->AssertUnaryOp(expm1, this->MakeScalar(1),
+ arrow::MakeScalar<double>(1.718281828459045F));
+}
+
+TYPED_TEST(TestUnaryArithmeticSigned, Expm1) {
+ auto expm1 = [](const Datum& arg, ArithmeticOptions, ExecContext* ctx) {
+ return Expm1(arg, ctx);
+ };
+ // Empty arrays
+ this->AssertUnaryOp(expm1, "[]", ArrayFromJSON(float64(), "[]"));
+ // Array with nulls
+ this->AssertUnaryOp(expm1, "[null]", ArrayFromJSON(float64(), "[null]"));
+ this->AssertUnaryOp(expm1, this->MakeNullScalar(),
arrow::MakeNullScalar(float64()));
+ this->AssertUnaryOp(expm1, "[-10, -1, 0, null, 1, 10]",
+ ArrayFromJSON(float64(),
+ "[-0.9999546000702375,
-0.6321205588285577, 0.0, "
+ "null, 1.718281828459045,
22025.465794806718]"));
+ this->AssertUnaryOp(expm1, this->MakeScalar(1),
+ arrow::MakeScalar<double>(1.718281828459045F));
+}
+
+TYPED_TEST(TestUnaryArithmeticFloating, Expm1) {
+ using CType = typename TestFixture::CType;
+
+ auto min = std::numeric_limits<CType>::lowest();
+ auto max = std::numeric_limits<CType>::max();
+
+ auto expm1 = [](const Datum& arg, ArithmeticOptions, ExecContext* ctx) {
+ return Expm1(arg, ctx);
+ };
+ // Empty arrays
+ this->AssertUnaryOp(expm1, "[]", "[]");
+ // Array with nulls
+ this->AssertUnaryOp(expm1, "[null]", "[null]");
+ this->AssertUnaryOp(expm1, this->MakeNullScalar(), this->MakeNullScalar());
+ this->AssertUnaryOp(expm1, "[-1.0, 0.0, null, 10.0]",
+ "[-0.6321205588285577, 0.0, null, 22025.465794806718]");
+ // Ordinary arrays (positive, negative, fractional, and zero inputs)
+ this->AssertUnaryOp(
+ expm1, "[-10.0, 0.0, 0.5, 1.0]",
Review Comment:
Nit: since the main point of `expm1` is to be more precise when the input is
close to zero, shouldn't we focus on this use case here? Though of course this
is all dependent on the stdlib's implementation.
--
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]