pitrou commented on a change in pull request #10016:
URL: https://github.com/apache/arrow/pull/10016#discussion_r613423704



##########
File path: cpp/src/arrow/compute/kernels/scalar_arithmetic_test.cc
##########
@@ -709,5 +709,76 @@ TEST(TestBinaryArithmetic, 
AddWithImplicitCastsUint64EdgeCase) {
                                      ArrayFromJSON(uint64(), 
"[18446744073709551615]")}));
 }
 
+TEST(TestUnaryArithmeticSigned, Negate) {
+  for (const auto& ty : internal::SignedIntTypes()) {
+    // No input
+    CheckScalarUnary("negate", ArrayFromJSON(ty, "[]"), ArrayFromJSON(ty, 
"[]"));
+    // Null input
+    CheckScalarUnary("negate", ArrayFromJSON(ty, "[null]"), ArrayFromJSON(ty, 
"[null]"));
+    // Zeros as inputs
+    CheckScalarUnary("negate", ArrayFromJSON(ty, "[0, 0, -0]"), 
ArrayFromJSON(ty, "[0, -0, 0]"));
+    // Positive inputs
+    CheckScalarUnary("negate", ArrayFromJSON(ty, "[1, 10, 100]"), 
ArrayFromJSON(ty, "[-1, -10, -100]"));
+    // Negative inputs
+    CheckScalarUnary("negate", ArrayFromJSON(ty, "[-1, -10, -100]"), 
ArrayFromJSON(ty, "[1, 10, 100]"));
+  }
+}
+
+TEST(TestUnaryArithmeticSignedMinMax, Negate) {
+  // NOTE [EPM]: Can these tests be done by iterating types?
+
+  // Min input
+  // Out-of-bounds after operation (C++ 2's complement wrap around, 
architecture dependent)
+  auto int8_min = std::numeric_limits<int8_t>::min();
+  CheckScalarUnary("negate", MakeScalar(int8_min), MakeScalar(int8_min));
+  auto int16_min = std::numeric_limits<int16_t>::min();
+  CheckScalarUnary("negate", MakeScalar(int16_min), MakeScalar(int16_min));
+  auto int32_min = std::numeric_limits<int32_t>::min();
+  CheckScalarUnary("negate", MakeScalar(int32_min), MakeScalar(int32_min));
+  auto int64_min = std::numeric_limits<int64_t>::min();
+  CheckScalarUnary("negate", MakeScalar(int64_min), MakeScalar(int64_min));
+
+  // Max input
+  // NOTE [EPM]: Why do these fail? The expected result is promoted to int32.
+  // auto int8_max = std::numeric_limits<int8_t>::max();
+  // CheckScalarUnary("negate", MakeScalar(int8_max), MakeScalar(-int8_max));
+  // auto int16_max = std::numeric_limits<int16_t>::max();
+  // CheckScalarUnary("negate", MakeScalar(int16_max), MakeScalar(-int16_max));
+  auto int32_max = std::numeric_limits<int32_t>::max();
+  CheckScalarUnary("negate", MakeScalar(int32_max), MakeScalar(-int32_max));
+  auto int64_max = std::numeric_limits<int64_t>::max();
+  CheckScalarUnary("negate", MakeScalar(int64_max), MakeScalar(-int64_max));
+}
+
+TEST(TestUnaryArithmeticUnsigned, Negate) {
+  for (const auto& ty : internal::UnsignedIntTypes()) {
+    // No input
+    CheckScalarUnary("negate", ArrayFromJSON(ty, "[]"), ArrayFromJSON(ty, 
"[]"));
+    // Null input
+    CheckScalarUnary("negate", ArrayFromJSON(ty, "[null]"), ArrayFromJSON(ty, 
"[null]"));
+    // Zeros as inputs
+    CheckScalarUnary("negate", ArrayFromJSON(ty, "[0]"), ArrayFromJSON(ty, 
"[0]"));
+  }
+    // Positive inputs
+    // CheckScalarUnary("negate", ArrayFromJSON(ty, "[1, 10, 100]"), 
ArrayFromJSON(ty, "[-1, -10, -100]"));
+    // Negative inputs
+    // CheckScalarUnary("negate", ArrayFromJSON(ty, "[-1, -10, -100]"), 
ArrayFromJSON(ty, "[1, 10, 100]"));
+}
+
+TEST(TestUnaryArithmeticFloating, Negate) {
+  for (const auto& ty : internal::FloatingPointTypes()) {
+    // No input
+    CheckScalarUnary("negate", ArrayFromJSON(ty, "[]"), ArrayFromJSON(ty, 
"[]"));
+    // Null input
+    CheckScalarUnary("negate", ArrayFromJSON(ty, "[null]"), ArrayFromJSON(ty, 
"[null]"));
+    // Zeros as inputs
+    CheckScalarUnary("negate", ArrayFromJSON(ty, "[0.0, 0.0, -0.0]"), 
ArrayFromJSON(ty, "[0.0, -0.0, 0.0]"));
+    // Positive inputs
+    CheckScalarUnary("negate", ArrayFromJSON(ty, "[1.3, 10.80, 12748.001]"), 
ArrayFromJSON(ty, "[-1.3, -10.80, -12748.001]"));
+    // Negative inputs
+    CheckScalarUnary("negate", ArrayFromJSON(ty, "[-1.3, -10.80, 
-12748.001]"), ArrayFromJSON(ty, "[1.3, 10.80, 12748.001]"));

Review comment:
       Also please check `inf` and `NaN` (they should work implicitly, but who 
knows).




-- 
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]


Reply via email to