diff --git a/sbp/src/operators/algos/constmatrix.rs b/sbp/src/operators/algos/constmatrix.rs index 1f38d02..1cf2429 100644 --- a/sbp/src/operators/algos/constmatrix.rs +++ b/sbp/src/operators/algos/constmatrix.rs @@ -4,7 +4,7 @@ use num_traits::identities::Zero; /// A row-major matrix #[derive(Debug, Clone, PartialEq, Eq, Hash)] -#[repr(C)] +#[repr(transparent)] pub struct Matrix { pub data: [[T; N]; M], } @@ -346,4 +346,18 @@ mod flipping { let flipped = m.flip_ud(); assert_eq!(flipped, Matrix::new([[5.0], [4.0], [3.0], [2.0], [1.0]])); } + + #[test] + fn assert_castability_of_alignment() { + let m = Matrix::new([[1.0], [2.0], [3.0], [4.0_f64]]); + assert_eq!(std::mem::align_of_val(&m), std::mem::align_of::()); + let m = Matrix::new([[1.0], [2.0], [3.0], [4.0_f32]]); + assert_eq!(std::mem::align_of_val(&m), std::mem::align_of::()); + let m = Matrix::new([[1], [2], [3], [4_i32]]); + assert_eq!(std::mem::align_of_val(&m), std::mem::align_of::()); + let m = Matrix::new([[1], [2], [3], [4_u64]]); + assert_eq!(std::mem::align_of_val(&m), std::mem::align_of::()); + let m = Matrix::new([[1], [2], [3], [4_u128]]); + assert_eq!(std::mem::align_of_val(&m), std::mem::align_of::()); + } }