elferherrera commented on a change in pull request #8129:
URL: https://github.com/apache/arrow/pull/8129#discussion_r484591510
##########
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:
Sure. That's a good idea. I could implement it like that. I was also
wondering if it is worthy to implement other type of constructors, something
similar to the ones you can find in pytorch. I think strides shouldn't be a
parameter that the user has to input, but instead a parameter that is
calculated and modified internally.
----------------------------------------------------------------
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:
[email protected]