ndtensor/impls/
impl_tensor.rs

1/*
2    appellation: impl_tensor <module>
3    authors: @FL03
4*/
5use crate::tensor::TensorBase;
6
7use ndarray::{ArrayBase, Data, Dimension, RawData, RawDataClone};
8
9impl<A, S, D> TensorBase<S, D>
10where
11    D: Dimension,
12    S: RawData<Elem = A>,
13{
14}
15
16impl<A, S, D> Clone for TensorBase<S, D>
17where
18    A: Clone,
19    S: RawDataClone<Elem = A>,
20    D: Dimension,
21{
22    fn clone(&self) -> Self {
23        TensorBase {
24            store: self.store().clone(),
25        }
26    }
27}
28
29impl<A, S, D> Copy for TensorBase<S, D>
30where
31    A: Copy,
32    S: RawDataClone<Elem = A> + Copy,
33    D: Dimension + Copy,
34{
35}
36
37impl<A, S, D> core::fmt::Debug for TensorBase<S, D>
38where
39    A: core::fmt::Debug,
40    S: Data<Elem = A>,
41    D: Dimension,
42{
43    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
44        f.debug_struct("TensorBase")
45            .field("store", &self.store())
46            .finish()
47    }
48}
49
50impl<A, S, D> core::fmt::Display for TensorBase<S, D>
51where
52    A: core::fmt::Display,
53    S: Data<Elem = A>,
54    D: Dimension,
55{
56    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
57        write!(f, "{}", self.store())
58    }
59}
60
61impl<A, S, D> PartialEq for TensorBase<S, D>
62where
63    A: PartialEq,
64    S: Data<Elem = A>,
65    D: Dimension,
66{
67    fn eq(&self, other: &Self) -> bool {
68        self.store() == other.store()
69    }
70}
71
72impl<A, S, D> PartialEq<ArrayBase<S, D>> for TensorBase<S, D>
73where
74    A: PartialEq,
75    S: Data<Elem = A>,
76    D: Dimension,
77{
78    fn eq(&self, other: &ArrayBase<S, D>) -> bool {
79        self.store() == other
80    }
81}
82
83impl<A, S, D> PartialEq<&ArrayBase<S, D>> for TensorBase<S, D>
84where
85    A: PartialEq,
86    S: Data<Elem = A>,
87    D: Dimension,
88{
89    fn eq(&self, other: &&ArrayBase<S, D>) -> bool {
90        self.store() == *other
91    }
92}
93
94impl<A, S, D> PartialEq<&mut ArrayBase<S, D>> for TensorBase<S, D>
95where
96    A: PartialEq,
97    S: Data<Elem = A>,
98    D: Dimension,
99{
100    fn eq(&self, other: &&mut ArrayBase<S, D>) -> bool {
101        self.store() == *other
102    }
103}