Skip to content

Commit

Permalink
some simple tests
Browse files Browse the repository at this point in the history
  • Loading branch information
khwilson committed Oct 19, 2024
1 parent 883bbc3 commit 25e1ee8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
20 changes: 11 additions & 9 deletions cpp/src/arrow/compute/kernels/scalar_arithmetic.cc
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,6 @@ struct TanhChecked {
*st = Status::Invalid("domain error");
return val;
}
// Cannot raise range errors (overflow) since PI/2 is not exactly representable
return std::tanh(val);
}
};
Expand Down Expand Up @@ -385,8 +384,7 @@ struct Atanh {
static enable_if_floating_value<Arg0, T> Call(KernelContext*, Arg0 val, Status*) {
static_assert(std::is_same<T, Arg0>::value, "");
if (ARROW_PREDICT_FALSE((val <= -1.0 || val >= 1.0))) {
*st = Status::Invalid("domain error");
return val;
return std::numeric_limits<T>::quiet_NaN();
}
return std::atanh(val);
}
Expand All @@ -396,6 +394,10 @@ struct AtanhChecked {
template <typename T, typename Arg0>
static enable_if_floating_value<Arg0, T> Call(KernelContext*, Arg0 val, Status*) {
static_assert(std::is_same<T, Arg0>::value, "");
if (ARROW_PREDICT_FALSE((val <= -1.0 || val >= 1.0))) {
*st = Status::Invalid("domain error");
return val;
}
return std::atanh(val);
}
};
Expand Down Expand Up @@ -1392,20 +1394,20 @@ const FunctionDoc acosh_checked_doc{"Compute the inverse hyperbolic cosine",
{"x"}};

const FunctionDoc atan_doc{"Compute the inverse tangent of x",
("NaN is returned for invalid input values;\n"
"to raise an error instead, see \"atanh_checked\"."),
("The return value is in the range [-pi/2, pi/2];\n"
"for a full return range [-pi, pi], see \"atan2\"."),
{"x"}};

const FunctionDoc atan2_doc{"Compute the inverse tangent of y/x",
("The return value is in the range [-pi, pi]."),
{"y", "x"}};

const FunctionDoc atanh_doc{"Compute the inverse hyperbolic tangent of x",
("The return value is in the range [-pi/2, pi/2];\n"
"for a full return range [-pi, pi], see \"atan2\"."),
const FunctionDoc acosh_doc{"Compute the inverse hyperbolic tangent",
("NaN is returned for invalid input values;\n"
"to raise an error instead, see \"atanh_checked\"."),
{"x"}};

const FunctionDoc atanh_checked_doc{"Compute the inverse hyperbolic cosine",
const FunctionDoc atanh_checked_doc{"Compute the inverse hyperbolic tangent",
("Invalid input values raise an error;\n"
"to return NaN instead, see \"atanh\"."),
{"x"}};
Expand Down
4 changes: 2 additions & 2 deletions cpp/src/arrow/compute/kernels/scalar_arithmetic_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1226,8 +1226,8 @@ TEST(TestUnaryArithmetic, DispatchBest) {
}

TEST(TestUnaryArithmetic, Null) {
for (std::string name : {"abs", "acos", "asin", "cos", "ln", "log10", "log1p", "log2",
"negate", "sin", "tan"}) {
for (std::string name : {"abs", "acos", "acosh", "asin", "asinh", "atanh", "cos", "cosh", "ln", "log10", "log1p", "log2",
"negate", "sin", "sinh", "tan", "tanh"}) {
for (std::string suffix : {"", "_checked"}) {
name += suffix;
AssertNullToNull(name);
Expand Down

0 comments on commit 25e1ee8

Please sign in to comment.