1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
use std::fmt::Debug;
use std::ops::Index;
use std::ops::IndexMut;

pub trait TensorTrait:
    PartialEq
    + Debug
    + Default
    + std::ops::Add
    + std::ops::AddAssign
    + std::ops::Mul
    + std::ops::MulAssign
    + Copy
    + Clone
{
}

impl<T> TensorTrait for T where
    T: PartialEq
        + Debug
        + Default
        + std::ops::Add
        + std::ops::AddAssign
        + std::ops::Mul
        + std::ops::MulAssign
        + Copy
        + Clone
{
}

pub trait Tensor:
    Index<usize> + IndexMut<usize> + PartialEq + Debug + Default + Copy + Clone
{
    type Value: TensorTrait;

    const SIZE: usize;
    const NDIM: usize;

    fn dims() -> Vec<usize>;
    fn get_dims(&self) -> Vec<usize>;

    // fn transpose(self) -> TensorTranspose<Self>;
}

pub trait CwiseMul<Rhs: Tensor> {
    type Output: Tensor;
    fn cwise_mul(self, other: Rhs) -> Self::Output;
}

pub trait CwiseMulAssign<Rhs: Tensor> {
    fn cwise_mul_assign(&mut self, other: Rhs);
}

pub struct TensorTranspose<T: TensorTrait, TT: Tensor<Value = T>>(TT);

pub trait Matrix {
    const ROWS: usize;
    const COLS: usize;
}

pub trait Vector {
    const COLS: usize;
}

pub trait RowVector {
    const ROWS: usize;
}

#[derive(Debug, PartialEq)]
pub enum TensorError {
    Size,
}