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/04/27 09:44:24 UTC

[GitHub] [arrow] cyb70289 commented on a change in pull request #10113: ARROW-11950: [C++][Compute] Add unary negative kernel

cyb70289 commented on a change in pull request #10113:
URL: https://github.com/apache/arrow/pull/10113#discussion_r621045269



##########
File path: cpp/src/arrow/compute/kernels/scalar_arithmetic.cc
##########
@@ -235,6 +239,49 @@ struct DivideChecked {
   }
 };
 
+struct Negate {
+  template <typename T, typename Arg>
+  static constexpr enable_if_floating_point<T> Call(KernelContext*, Arg arg) {
+    return -arg;
+  }
+
+  template <typename T, typename Arg>
+  static constexpr enable_if_unsigned_integer<T> Call(KernelContext*, Arg arg) {
+    return ~arg + 1;
+  }
+
+  template <typename T, typename Arg>
+  static constexpr enable_if_signed_integer<T> Call(KernelContext*, Arg arg) {
+    return arrow::internal::SafeSignedNegate(arg);
+  }
+};
+
+struct NegateChecked {
+  template <typename T, typename Arg>
+  static enable_if_signed_integer<T> Call(KernelContext* ctx, Arg arg) {
+    static_assert(std::is_same<T, Arg>::value, "");
+    T result = 0;
+    if (ARROW_PREDICT_FALSE(NegateWithOverflow(arg, &result))) {
+      ctx->SetStatus(Status::Invalid("overflow"));

Review comment:
       PR #10098 changed a bit the behaviour of kernel error handling. Errors are not populated through KernelContext any more.
   You can reference latest code in this source file. E.g., https://github.com/apache/arrow/blob/master/cpp/src/arrow/compute/kernels/scalar_arithmetic.cc#L91




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