constensor_core/
shape.rs

1/// Marker trait for shapes
2pub trait Shape: Clone {
3    fn shape() -> Vec<usize>;
4    fn element_count() -> usize {
5        Self::shape().iter().product()
6    }
7}
8
9macro_rules! shape {
10    (($($C:ident),*), ($($N:tt),*), $name:ident) => {
11        #[derive(Clone)]
12        pub struct $name<$($C $N: usize, )*>;
13
14        impl<$($C $N: usize, )*> Shape for $name<$({ $N }, )*> {
15            fn shape() -> Vec<usize> {
16                vec![$($N, )*]
17            }
18        }
19    };
20}
21
22shape!((const), (A), R1);
23shape!((const, const), (A, B), R2);
24shape!((const, const, const), (A, B, C), R3);
25shape!((const, const, const, const), (A, B, C, D), R4);
26shape!((const, const, const, const, const), (A, B, C, D, E), R5);
27shape!((const, const, const, const, const, const), (A, B, C, D, E, F), R6);