pub type SquareMatrix<T = f32> = [[T; BOARD_SIZE]; BOARD_SIZE];
pub type StateTensor<T = f32> = [SquareMatrix<T>; CHANNELS];
pub trait StateTensorExtension {
fn shape(self: &Self) -> [usize; 3];
}
impl<T> StateTensorExtension for StateTensor<T> {
fn shape(self: &Self) -> [usize; 3] {
return [CHANNELS, BOARD_SIZE, BOARD_SIZE];
}
}
I am using a quite ugly style to construct an array view from the array
let state_tensor: StateTensor<f32> = // ...;
let dims = state_tensor.shape();
let x: ArrayBase<ViewRepr<&f32>, _> = unsafe {
ArrayView::from_shape_ptr(dims, bytemuck::cast_slice(&state_tensor).as_ptr())
};
The above code assumes multiple dimensional arrays are tightly packed in Rust. Would that work always?
What is the best way to construct ndarray::ArrayView from multiple dimensional array in my case? Or should I created a owned array instead?