You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2021/06/22 06:17:06 UTC

[GitHub] [arrow] edponce commented on a change in pull request #10567: ARROW-13096: [C++] Implement logarithm compute functions

edponce commented on a change in pull request #10567:
URL: https://github.com/apache/arrow/pull/10567#discussion_r655907205



##########
File path: cpp/src/arrow/compute/kernels/scalar_arithmetic_test.cc
##########
@@ -1511,5 +1517,55 @@ TEST(TestBinaryArithmeticDecimal, Divide) {
   }
 }
 
+TYPED_TEST(TestUnaryArithmeticFloating, Log) {
+  auto ty = this->type_singleton();
+  for (auto check_overflow : {false, true}) {
+    this->SetOverflowCheck(check_overflow);
+    this->AssertUnaryOp(Ln, ArrayFromJSON(ty, "[1, 2.7182818284590452354]"),
+                        ArrayFromJSON(ty, "[0, 1]"));
+    this->AssertUnaryOp(Log10, ArrayFromJSON(ty, "[1, 10]"), ArrayFromJSON(ty, "[0, 1]"));
+    this->AssertUnaryOp(Log2, ArrayFromJSON(ty, "[1, 2]"), ArrayFromJSON(ty, "[0, 1]"));
+  }
+  this->AssertUnaryOpRaises(Ln, "[0]", "divide by zero");
+  this->AssertUnaryOpRaises(Ln, "[-1]", "domain error");
+  this->AssertUnaryOpRaises(Log10, "[0]", "divide by zero");
+  this->AssertUnaryOpRaises(Log10, "[-1]", "domain error");
+  this->AssertUnaryOpRaises(Log2, "[0]", "divide by zero");
+  this->AssertUnaryOpRaises(Log2, "[-1]", "domain error");
+}
+
+TYPED_TEST(TestUnaryArithmeticSigned, Log) {
+  auto ty = this->type_singleton();
+  for (auto check_overflow : {false, true}) {
+    this->SetOverflowCheck(check_overflow);
+    this->AssertUnaryOp(Ln, ArrayFromJSON(ty, "[1]"), ArrayFromJSON(float64(), "[0]"));
+    this->AssertUnaryOp(Log10, ArrayFromJSON(ty, "[1, 10]"),
+                        ArrayFromJSON(float64(), "[0, 1]"));
+    this->AssertUnaryOp(Log2, ArrayFromJSON(ty, "[1, 2]"),
+                        ArrayFromJSON(float64(), "[0, 1]"));
+  }
+  this->AssertUnaryOpRaises(Ln, "[0]", "divide by zero");
+  this->AssertUnaryOpRaises(Ln, "[-1]", "domain error");
+  this->AssertUnaryOpRaises(Log10, "[0]", "divide by zero");
+  this->AssertUnaryOpRaises(Log10, "[-1]", "domain error");
+  this->AssertUnaryOpRaises(Log2, "[0]", "divide by zero");
+  this->AssertUnaryOpRaises(Log2, "[-1]", "domain error");
+}
+
+TYPED_TEST(TestUnaryArithmeticUnsigned, Log) {
+  auto ty = this->type_singleton();
+  for (auto check_overflow : {false, true}) {
+    this->SetOverflowCheck(check_overflow);
+    this->AssertUnaryOp(Ln, ArrayFromJSON(ty, "[1]"), ArrayFromJSON(float64(), "[0]"));
+    this->AssertUnaryOp(Log10, ArrayFromJSON(ty, "[1, 10]"),
+                        ArrayFromJSON(float64(), "[0, 1]"));
+    this->AssertUnaryOp(Log2, ArrayFromJSON(ty, "[1, 2]"),
+                        ArrayFromJSON(float64(), "[0, 1]"));
+  }
+  this->AssertUnaryOpRaises(Ln, "[0]", "divide by zero");
+  this->AssertUnaryOpRaises(Log10, "[0]", "divide by zero");
+  this->AssertUnaryOpRaises(Log2, "[0]", "divide by zero");
+}
+

Review comment:
       In valid test cases, no need to use `ty` (aka `this->type_singleton()`) with `ArrayFromJSON` because that is the default type. Also, no need to use the `this` keyword for the class methods.
   
   Moreover, PR #10395 extends the unary scalar arithmetic test class to support combinations of JSON/Array inputs which will allow you to further simplify the test statements as follows:
   * For integer inputs: `AssertUnaryOp(Ln, "[1]", ArrayFromJSON(float64(), "[0]"));`
   * For floating point inputs: `AssertUnaryOp(Log10, "[1, 10]", "[0, 1]");`




-- 
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:
users@infra.apache.org