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 2020/09/07 21:39:27 UTC

[GitHub] [arrow] andygrove commented on a change in pull request #8129: ARROW-9934 [Rust] Shape and stride check in tensor

andygrove commented on a change in pull request #8129:
URL: https://github.com/apache/arrow/pull/8129#discussion_r484571618



##########
File path: rust/arrow/src/tensor.rs
##########
@@ -112,13 +123,44 @@ impl<'a, T: ArrowPrimitiveType> Tensor<'a, T> {
                         )
                     })
                     .next();
+
+                let total_elements: usize = s.iter().product();
+                assert_eq!(
+                    total_elements, 
+                    buffer.len() / mem::size_of::<T::Native>(),
+                    "number of elements in buffer does not match dimensios"
+                );
             }
         };
+
+        // Checking that the tensor strides used for construction are correct
+        // otherwise a row major stride is calculated and used as value for the tensor
+        let tensor_strides = {
+            if let Some(val) = strides {
+                if let Some(ref s) = shape {
+                    if compute_row_major_strides::<T>(s) == val || compute_column_major_strides::<T>(s) == val {
+                        Some(val)
+
+                    } else {
+                        panic!("the input stride does not match the selected shape")

Review comment:
       Perhaps we could rename `new` to `try_new` and have it return `Result<Self>` rather than panic?




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