pitrou commented on code in PR #36289:
URL: https://github.com/apache/arrow/pull/36289#discussion_r1275849562
##########
cpp/src/arrow/compute/kernels/scalar_round_arithmetic_test.cc:
##########
@@ -1014,21 +1031,70 @@ TYPED_TEST(TestUnaryRoundSigned, Round) {
this->SetRoundNdigits(0);
for (const auto& round_mode : kRoundModes) {
this->SetRoundMode(round_mode);
- this->AssertUnaryOp(Round, values, ArrayFromJSON(float64(), values));
+ this->AssertUnaryOp(Round, values, ArrayFromJSON(this->type_singleton(),
values));
}
// Test different round N-digits for nearest rounding mode
std::vector<std::pair<int64_t, std::string>> ndigits_and_expected{{
- {-2, "[0.0, 0.0, -0.0, -100, 100]"},
- {-1, "[0.0, 0.0, -10, -50, 120]"},
+ {-2, "[0, 0, -0, -100, 100]"},
+ {-1, "[0, 0, -10, -50, 120]"},
{0, values},
{1, values},
{2, values},
}};
this->SetRoundMode(RoundMode::HALF_TOWARDS_INFINITY);
for (const auto& pair : ndigits_and_expected) {
this->SetRoundNdigits(pair.first);
- this->AssertUnaryOp(Round, values, ArrayFromJSON(float64(), pair.second));
+ this->AssertUnaryOp(Round, values,
+ ArrayFromJSON(this->type_singleton(), pair.second));
+ }
+
+ // Test different rounding mode
+ // skip int8 because of its small range
+ if constexpr (!std::is_same_v<TypeParam, Int8Type>) {
+ std::string values("[0, 1, -13, -50, 115, -176, 200, 250]");
Review Comment:
Can you test with values on which `HALF_TOWARDS_ZERO` and `HALF_TO_EVEN`
would actually differ?
For example:
```suggestion
std::string values("[0, 1, -13, 115, -150, -176, 200, 250]");
```
##########
docs/source/cpp/compute.rst:
##########
@@ -563,30 +563,32 @@ representation based on the rounding criterion.
+-------------------+------------+-------------+-------------------------+----------------------------------+--------+
| floor | Unary | Numeric | Float32/Float64/Decimal |
| |
+-------------------+------------+-------------+-------------------------+----------------------------------+--------+
-| round | Unary | Numeric | Float32/Float64/Decimal |
:struct:`RoundOptions` | (1)(2) |
+| round | Unary | Numeric | Input Type |
:struct:`RoundOptions` | (1)(2) |
+-------------------+------------+-------------+-------------------------+----------------------------------+--------+
-| round_to_multiple | Unary | Numeric | Float32/Float64/Decimal |
:struct:`RoundToMultipleOptions` | (1)(3) |
+| round_to_multiple | Unary | Numeric | Input Type |
:struct:`RoundToMultipleOptions` | (1)(3) |
Review Comment:
Is `round_binary` not mentioned in this table? If so, can you add it?
##########
cpp/src/arrow/compute/kernels/scalar_round_arithmetic_test.cc:
##########
@@ -1014,21 +1031,70 @@ TYPED_TEST(TestUnaryRoundSigned, Round) {
this->SetRoundNdigits(0);
for (const auto& round_mode : kRoundModes) {
this->SetRoundMode(round_mode);
- this->AssertUnaryOp(Round, values, ArrayFromJSON(float64(), values));
+ this->AssertUnaryOp(Round, values, ArrayFromJSON(this->type_singleton(),
values));
}
// Test different round N-digits for nearest rounding mode
std::vector<std::pair<int64_t, std::string>> ndigits_and_expected{{
- {-2, "[0.0, 0.0, -0.0, -100, 100]"},
- {-1, "[0.0, 0.0, -10, -50, 120]"},
+ {-2, "[0, 0, -0, -100, 100]"},
+ {-1, "[0, 0, -10, -50, 120]"},
{0, values},
{1, values},
{2, values},
}};
this->SetRoundMode(RoundMode::HALF_TOWARDS_INFINITY);
for (const auto& pair : ndigits_and_expected) {
this->SetRoundNdigits(pair.first);
- this->AssertUnaryOp(Round, values, ArrayFromJSON(float64(), pair.second));
+ this->AssertUnaryOp(Round, values,
+ ArrayFromJSON(this->type_singleton(), pair.second));
+ }
+
+ // Test different rounding mode
+ // skip int8 because of its small range
+ if constexpr (!std::is_same_v<TypeParam, Int8Type>) {
+ std::string values("[0, 1, -13, -50, 115, -176, 200, 250]");
+ this->SetRoundNdigits(-2);
+ std::vector<std::pair<RoundMode, std::string>> round_modes_and_expected{{
+ {RoundMode::DOWN, "[0, 0, -100, -100, 100, -200, 200, 200]"},
+ {RoundMode::UP, "[0, 100, -0, -0, 200, -100, 200, 300]"},
+ {RoundMode::TOWARDS_ZERO, "[0, 0, -0, -0, 100, -100, 200, 200]"},
+ {RoundMode::TOWARDS_INFINITY, "[0, 100, -100, -100, 200, -200, 200,
300]"},
+ {RoundMode::HALF_DOWN, "[0, 0, -0, -100, 100, -200, 200, 200]"},
+ {RoundMode::HALF_UP, "[0, 0, -0, -0, 100, -200, 200, 300]"},
+ {RoundMode::HALF_TOWARDS_ZERO, "[0, 0, -0, -0, 100, -200, 200, 200]"},
+ {RoundMode::HALF_TOWARDS_INFINITY, "[0, 0, -0, -100, 100, -200, 200,
300]"},
+ {RoundMode::HALF_TO_EVEN, "[0, 0, -0, -0, 100, -200, 200, 200]"},
+ {RoundMode::HALF_TO_ODD, "[0, 0, -0, -100, 100, -200, 200, 300]"},
+ }};
+ for (const auto& pair : round_modes_and_expected) {
+ this->SetRoundMode(pair.first);
+ this->AssertUnaryOp(Round, values,
+ ArrayFromJSON(this->type_singleton(), pair.second));
+ }
+ }
+
+ // An overly large ndigits would cause an error
+ if constexpr (std::is_same_v<TypeParam, Int8Type>) {
Review Comment:
Why only int8? 100 digits should be out of range for every integer type.
##########
cpp/src/arrow/compute/kernels/scalar_round_arithmetic_test.cc:
##########
@@ -1052,7 +1118,56 @@ TYPED_TEST(TestUnaryRoundUnsigned, Round) {
this->SetRoundMode(RoundMode::HALF_TOWARDS_INFINITY);
for (const auto& pair : ndigits_and_expected) {
this->SetRoundNdigits(pair.first);
- this->AssertUnaryOp(Round, values, ArrayFromJSON(float64(), pair.second));
+ this->AssertUnaryOp(Round, values,
+ ArrayFromJSON(this->type_singleton(), pair.second));
+ }
+
+ // Test different rounding mode
+ // skip uint8 because of its small range
+ if constexpr (!std::is_same_v<TypeParam, UInt8Type>) {
+ std::string values("[0, 1, 13, 50, 115, 176, 200, 250]");
Review Comment:
(same comments as above here)
--
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]