Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 4.3k
ARROW-12814: [C++][Gandiva] Implements ABS, FLOOR, PI, SQRT, SIGN, LSHIFT, RSHIFT, CEIL, TRUNC, LN and LOG2 functions#10350
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -21,11 +21,18 @@ | ||
| #include <gmock/gmock.h> | ||
| #include <gtest/gtest.h> | ||
| #include <cfloat> | ||
| #include <cmath> | ||
| #include "arrow/util/logging.h" | ||
| #include "gandiva/execution_context.h" | ||
| namespace gandiva { | ||
| void VerifyAlmostEquals(double actual, double expected, double max_error = FLT_EPSILON) { | ||
| EXPECT_TRUE(fabs(actual - expected) < max_error) << actual << " != " << expected; | ||
| } | ||
| TEST(TestGdvFnStubs, TestCrc32) { | ||
| gandiva::ExecutionContext ctx; | ||
| auto ctx_ptr = reinterpret_cast<int64_t>(&ctx); | ||
| @@ -949,4 +956,59 @@ TEST(TestGdvFnStubs, TestMaskLastN) { | ||
| EXPECT_EQ(expected, std::string(result, out_len)); | ||
| } | ||
| TEST(TestGdvFnStubs, TestAbs) { | ||
| gandiva::ExecutionContext ctx; | ||
| uint64_t ctx_ptr = reinterpret_cast<int64_t>(&ctx); | ||
| // Abs functions | ||
| EXPECT_EQ(gdv_fn_abs_int32(ctx_ptr, 0), 0); | ||
| EXPECT_EQ(gdv_fn_abs_uint32(ctx_ptr, 0), 0); | ||
| EXPECT_EQ(gdv_fn_abs_int64(ctx_ptr, 0), 0L); | ||
| EXPECT_EQ(gdv_fn_abs_uint64(ctx_ptr, 0), 0L); | ||
| VerifyAlmostEquals(gdv_fn_abs_float32(ctx_ptr, 0.0f), abs(0.0f)); | ||
| VerifyAlmostEquals(gdv_fn_abs_float64(ctx_ptr, 0.0), abs(0.0)); | ||
| EXPECT_EQ(gdv_fn_abs_int32(ctx_ptr, (INT32_MIN + 1)), abs(INT32_MIN + 1)); | ||
| EXPECT_EQ(gdv_fn_abs_int64(ctx_ptr, (INT64_MIN + 1)), abs(INT64_MIN + 1)); | ||
| VerifyAlmostEquals(gdv_fn_abs_float32(ctx_ptr, static_cast<float>(INT32_MIN + 1)), | ||
| abs(static_cast<float>(INT32_MIN + 1))); | ||
| VerifyAlmostEquals(gdv_fn_abs_float64(ctx_ptr, static_cast<double>(INT32_MIN + 1)), | ||
| abs(static_cast<double>(INT32_MIN + 1))); | ||
| VerifyAlmostEquals(gdv_fn_abs_float32(ctx_ptr, std::numeric_limits<float>::max()), | ||
| abs(std::numeric_limits<float>::max())); | ||
| VerifyAlmostEquals(gdv_fn_abs_float32(ctx_ptr, std::numeric_limits<float>::min()), | ||
| abs(std::numeric_limits<float>::min())); | ||
| VerifyAlmostEquals(gdv_fn_abs_float64(ctx_ptr, std::numeric_limits<double>::max()), | ||
| abs(std::numeric_limits<double>::max())); | ||
| VerifyAlmostEquals(gdv_fn_abs_float64(ctx_ptr, std::numeric_limits<double>::min()), | ||
| abs(std::numeric_limits<double>::min())); | ||
| EXPECT_EQ(gdv_fn_abs_int64(ctx_ptr, (INT64_MIN + 1)), | ||
| abs(static_cast<double>(INT64_MIN + 1))); | ||
| VerifyAlmostEquals(gdv_fn_abs_float64(ctx_ptr, static_cast<double>(INT64_MIN + 1)), | ||
| abs(static_cast<double>(INT64_MIN + 1))); | ||
Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about adding tests for min and max values of double and float by using ContributorAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tests added | ||
| VerifyAlmostEquals(gdv_fn_abs_float32(ctx_ptr, -3600.50f), abs(-3600.50f)); | ||
| VerifyAlmostEquals(gdv_fn_abs_float64(ctx_ptr, -3600.50), abs(-3600.50)); | ||
| } | ||
| TEST(TestGdvFnStubs, TestAbsOverflow) { | ||
| gandiva::ExecutionContext ctx; | ||
| uint64_t ctx_ptr = reinterpret_cast<int64_t>(&ctx); | ||
| int64_t value = gdv_fn_abs_int64(ctx_ptr, INT64_MIN); | ||
| EXPECT_TRUE(ctx.has_error()); | ||
| EXPECT_THAT(ctx.get_error(), ::testing::HasSubstr("Overflow in abs execution")); | ||
| EXPECT_EQ(value, 0); | ||
| ctx.Reset(); | ||
| int32_t value_int32 = gdv_fn_abs_int32(ctx_ptr, INT32_MIN); | ||
| EXPECT_TRUE(ctx.has_error()); | ||
| EXPECT_THAT(ctx.get_error(), ::testing::HasSubstr("Overflow in abs execution")); | ||
| EXPECT_EQ(value_int32, 0); | ||
| ctx.Reset(); | ||
| } | ||
| } // namespace gandiva | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it mean that we will accept the loss of digits in INT64?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kiszk Thanks for your revision! Please, could you explain how would occur digit loss here? I did not understand what you said.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I thought the previous version of abs is to cast int64 to double long. But, now,
gdv_fn_abs_int64handles as int64. Correct?Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kiszk Yes, this line has the changes I made in the function. I handle the number as int64 and I add a check similar to the compute kernel to avoid overflow when getting the absolute value for the
INT64_MINvalue.