use std::fmt::Debug;
pub trait Dim: Copy + Debug + Default {
type Larger: Dim;
type Smaller: Dim;
type Shape: Shape<Dim = Self>;
type Strides: Strides<Dim = Self>;
const RANK: usize;
}
pub trait Shape: AsMut<[usize]> + AsRef<[usize]> + Copy + Debug + Default {
type Dim: Dim<Shape = Self>;
}
pub trait Strides: AsMut<[isize]> + AsRef<[isize]> + Copy + Debug + Default {
type Dim: Dim<Strides = Self>;
}
#[derive(Clone, Copy, Debug, Default)]
pub struct Const<const N: usize>;
macro_rules! impl_dimension {
($($n:tt),*) => {
$(
impl Dim for Const<$n> {
type Larger = Const<{ $n + ($n < 6) as usize }>;
type Smaller = Const<{ $n - ($n > 0) as usize }>;
type Shape = [usize; $n];
type Strides = [isize; $n];
const RANK: usize = $n;
}
impl Shape for [usize; $n] {
type Dim = Const<$n>;
}
impl Strides for [isize; $n] {
type Dim = Const<$n>;
}
)*
}
}
impl_dimension!(0, 1, 2, 3, 4, 5, 6);