I have a multi dimensional array as below.
let mut my_array = [[[0f32; 15]; 15]; 4];
I need create a tensor by copying the data from this array. The Tendor
structure provides a with_values
method to initialize from a 1-D slice.
pub fn with_values(self, value: &[T]) -> Result<Self>
I dislike the inefficient approach to copy the element one by one. Perhaps it is better to take use memcpy
internally. The multi-dimensional array is a continuous area of memory. The dimensions do not change the memory layout if I am correct.
let state_tensor = Tensor::<f32>::new(&[1, 4, 15, 15]).with_values(...);
Is there a way to efficiently initialize tensor using the multi dimensional array?