3 #![allow(incomplete_features)]
4 #![feature(generic_const_exprs)]
6 use std::{marker::PhantomData, ops::Mul};
9 pub struct Cons<T, L> {
10 _phantom: PhantomData<(T, L)>,
13 pub trait Indices<const N: usize> {
15 const NUM_ELEMS: usize;
18 impl<const N: usize> Indices<N> for Nil {
19 const RANK: usize = 0;
20 const NUM_ELEMS: usize = 1;
23 impl<T, I: Indices<N>, const N: usize> Indices<N> for Cons<T, I> {
24 const RANK: usize = I::RANK + 1;
25 const NUM_ELEMS: usize = I::NUM_ELEMS * N;
32 impl<J> Concat<J> for Nil {
36 impl<T, I, J> Concat<J> for Cons<T, I>
40 type Output = Cons<T, <I as Concat<J>>::Output>;
43 pub struct Tensor<I: Indices<N>, const N: usize>
45 [u8; I::NUM_ELEMS]: Sized,
47 pub data: [u8; I::NUM_ELEMS],
48 _phantom: PhantomData<I>,
51 impl<I: Indices<N>, J: Indices<N>, const N: usize> Mul<Tensor<J, N>> for Tensor<I, N>
54 <I as Concat<J>>::Output: Indices<N>,
55 [u8; I::NUM_ELEMS]: Sized,
56 [u8; J::NUM_ELEMS]: Sized,
57 [u8; <I as Concat<J>>::Output::NUM_ELEMS]: Sized,
59 type Output = Tensor<<I as Concat<J>>::Output, N>;
61 fn mul(self, _rhs: Tensor<J, N>) -> Self::Output {
63 data: [0u8; <I as Concat<J>>::Output::NUM_ELEMS],
64 _phantom: PhantomData,