zeroshade commented on code in PR #40867:
URL: https://github.com/apache/arrow/pull/40867#discussion_r1551860785


##########
cpp/src/arrow/record_batch.cc:
##########
@@ -283,18 +283,55 @@ struct ConvertColumnsToTensorVisitor {
   }
 };
 
+template <typename Out>
+struct ConvertColumnsToTensorRowMajorVisitor {
+  Out*& out_values;
+  const ArrayData& in_data;
+  int num_cols;
+  int col_idx;
+
+  template <typename T>
+  Status Visit(const T&) {
+    if constexpr (is_numeric(T::type_id)) {
+      using In = typename T::c_type;
+      auto in_values = ArraySpan(in_data).GetSpan<In>(1, in_data.length);
+
+      if (in_data.null_count == 0) {
+        for (int64_t j = 0; j < in_data.length; ++j) {
+          out_values[j * num_cols + col_idx] = static_cast<Out>(in_values[j]);
+        }
+      } else {
+        for (int64_t j = 0; j < in_data.length; ++j) {
+          out_values[j * num_cols + col_idx] =
+              in_data.IsNull(j) ? static_cast<Out>(NAN) : 
static_cast<Out>(in_values[j]);
+        }
+      }
+      return Status::OK();
+    }
+    Unreachable();

Review Comment:
   does `Unreachable` force returning a bad status / not implemented status? 
   
   If this is truly unreachable, do we really need the `if constexpr 
(is_numeric)` on top? Could this be simplified by using an `enable_if` 
constraint on the template type / etc?



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

Reply via email to