1macro_rules! impl_vector_common {
2 ($vec:ty, $con:ty, $in:ty) => {
3 impl<T: Scalar> VectorCommon for $vec {
4 type T = T;
5 type C = $con;
6 type Inner = $in;
7 fn inner(&self) -> &Self::Inner {
8 &self.data
9 }
10 }
11 };
12}
13pub(crate) use impl_vector_common;
14
15macro_rules! impl_vector_common_ref {
16 ($vec:ty, $con:ty, $in:ty) => {
17 impl<'a, T: Scalar> VectorCommon for $vec {
18 type T = T;
19 type C = $con;
20 type Inner = $in;
21 fn inner(&self) -> &Self::Inner {
22 &self.data
23 }
24 }
25 };
26}
27pub(crate) use impl_vector_common_ref;
28
29macro_rules! impl_sub_assign {
30 ($lhs:ty, $rhs:ty) => {
31 impl<T: Scalar> SubAssign<$rhs> for $lhs {
32 fn sub_assign(&mut self, rhs: $rhs) {
33 self.data -= &rhs.data;
34 }
35 }
36 };
37}
38pub(crate) use impl_sub_assign;
39
40macro_rules! impl_add_assign {
41 ($lhs:ty, $rhs:ty) => {
42 impl<T: Scalar> AddAssign<$rhs> for $lhs {
43 fn add_assign(&mut self, rhs: $rhs) {
44 self.data += &rhs.data;
45 }
46 }
47 };
48}
49pub(crate) use impl_add_assign;
50
51macro_rules! impl_sub_lhs {
52 ($lhs:ty, $rhs:ty, $out:ty) => {
53 impl<T: Scalar> Sub<$rhs> for $lhs {
54 type Output = $out;
55 fn sub(self, rhs: $rhs) -> Self::Output {
56 Self::Output {
57 data: self.data - &rhs.data,
58 context: self.context,
59 }
60 }
61 }
62 };
63}
64pub(crate) use impl_sub_lhs;
65
66macro_rules! impl_sub_rhs {
67 ($lhs:ty, $rhs:ty, $out:ty) => {
68 impl<T: Scalar> Sub<$rhs> for $lhs {
69 type Output = $out;
70 fn sub(self, rhs: $rhs) -> Self::Output {
71 Self::Output {
72 data: &self.data - rhs.data,
73 context: rhs.context,
74 }
75 }
76 }
77 };
78}
79pub(crate) use impl_sub_rhs;
80
81macro_rules! impl_sub_both_ref {
82 ($lhs:ty, $rhs:ty, $out:ty) => {
83 impl<T: Scalar> Sub<$rhs> for $lhs {
84 type Output = $out;
85 fn sub(self, rhs: $rhs) -> Self::Output {
86 Self::Output {
87 data: &self.data - &rhs.data,
88 context: self.context.clone(),
89 }
90 }
91 }
92 };
93}
94pub(crate) use impl_sub_both_ref;
95
96macro_rules! impl_add_lhs {
97 ($lhs:ty, $rhs:ty, $out:ty) => {
98 impl<T: Scalar> Add<$rhs> for $lhs {
99 type Output = $out;
100 fn add(self, rhs: $rhs) -> Self::Output {
101 Self::Output {
102 data: self.data + &rhs.data,
103 context: self.context,
104 }
105 }
106 }
107 };
108}
109pub(crate) use impl_add_lhs;
110
111macro_rules! impl_add_rhs {
112 ($lhs:ty, $rhs:ty, $out:ty) => {
113 impl<T: Scalar> Add<$rhs> for $lhs {
114 type Output = $out;
115 fn add(self, rhs: $rhs) -> Self::Output {
116 Self::Output {
117 data: &self.data + rhs.data,
118 context: rhs.context,
119 }
120 }
121 }
122 };
123}
124pub(crate) use impl_add_rhs;
125
126macro_rules! impl_add_both_ref {
127 ($lhs:ty, $rhs:ty, $out:ty) => {
128 impl<T: Scalar> Add<$rhs> for $lhs {
129 type Output = $out;
130 fn add(self, rhs: $rhs) -> Self::Output {
131 Self::Output {
132 data: &self.data + &rhs.data,
133 context: self.context.clone(),
134 }
135 }
136 }
137 };
138}
139pub(crate) use impl_add_both_ref;
140
141macro_rules! impl_index {
142 ($lhs:ty) => {
143 impl<T: Scalar> Index<IndexType> for $lhs {
144 type Output = T;
145 fn index(&self, index: IndexType) -> &Self::Output {
146 &self.data[index]
147 }
148 }
149 };
150}
151pub(crate) use impl_index;
152
153macro_rules! impl_index_mut {
154 ($lhs:ty) => {
155 impl<T: Scalar> IndexMut<IndexType> for $lhs {
156 fn index_mut(&mut self, index: IndexType) -> &mut Self::Output {
157 &mut self.data[index]
158 }
159 }
160 };
161}
162pub(crate) use impl_index_mut;