AlenkaF commented on code in PR #40867:
URL: https://github.com/apache/arrow/pull/40867#discussion_r1552886195
##########
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:
`enable_if` makes sense to me but this was a suggested in a previous PR
https://github.com/apache/arrow/pull/40359#discussion_r1532160896 and I have
copied the approach for row-major. I do not mind changing, if needed.
--
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]