1#![macro_use]
2
3macro_rules! md_impl(
6 (
7 $Op: ident, $op: ident $(where T: $($ScalarBounds: ident),*)*;
9 ($R1: ty, $C1: ty),($R2: ty, $C2: ty)
11 const $($D: ident),*;
13 for $($DimsDecl: ident),*;
15 where $($ConstraintType: ty: $ConstraintBound: ident$(<$($ConstraintBoundParams: ty $( = $EqBound: ty )*),*>)*),*;
17 $lhs: ident: $Lhs: ty, $rhs: ident: $Rhs: ty, Output = $Result: ty;
19 $action: expr;
21 $($lives: tt),*) => {
23 impl<$($lives ,)* T $(, $DimsDecl)* $(, const $D: usize)*> $Op<$Rhs> for $Lhs
24 where T: Scalar + Zero + One + ClosedAdd + ClosedMul $($(+ $ScalarBounds)*)*,
25 $( $ConstraintType: $ConstraintBound$(<$( $ConstraintBoundParams $( = $EqBound )*),*>)* ),*
26 {
27 type Output = $Result;
28
29 #[inline]
30 fn $op($lhs, $rhs: $Rhs) -> Self::Output {
31 $action
32 }
33 }
34 }
35);
36
37macro_rules! md_impl_all(
40 (
41 $Op: ident, $op: ident $(where T: $($ScalarBounds: ident),*)*;
43 ($R1: ty, $C1: ty),($R2: ty, $C2: ty)
45 const $($D: ident),*;
47 for $($DimsDecl: ident),*;
49 where $($ConstraintType: ty: $ConstraintBound: ident$(<$($ConstraintBoundParams: ty $( = $EqBound: ty )*),*>)*),*;
51 $lhs: ident: $Lhs: ty, $rhs: ident: $Rhs: ty, Output = $Result: ty;
53 [val val] => $action_val_val: expr;
55 [ref val] => $action_ref_val: expr;
56 [val ref] => $action_val_ref: expr;
57 [ref ref] => $action_ref_ref: expr;) => {
58
59 md_impl!(
60 $Op, $op $(where T: $($ScalarBounds),*)*;
61 ($R1, $C1),($R2, $C2)
62 const $($D),*;
63 for $($DimsDecl),*;
64 where $($ConstraintType: $ConstraintBound$(<$($ConstraintBoundParams $( = $EqBound )*),*>)*),*;
65 $lhs: $Lhs, $rhs: $Rhs, Output = $Result;
66 $action_val_val; );
67
68 md_impl!(
69 $Op, $op $(where T: $($ScalarBounds),*)*;
70 ($R1, $C1),($R2, $C2)
71 const $($D),*;
72 for $($DimsDecl),*;
73 where $($ConstraintType: $ConstraintBound$(<$($ConstraintBoundParams $( = $EqBound )*),*>)*),*;
74 $lhs: &'a $Lhs, $rhs: $Rhs, Output = $Result;
75 $action_ref_val; 'a);
76
77 md_impl!(
78 $Op, $op $(where T: $($ScalarBounds),*)*;
79 ($R1, $C1),($R2, $C2)
80 const $($D),*;
81 for $($DimsDecl),*;
82 where $($ConstraintType: $ConstraintBound$(<$($ConstraintBoundParams $( = $EqBound )*),*>)*),*;
83 $lhs: $Lhs, $rhs: &'b $Rhs, Output = $Result;
84 $action_val_ref; 'b);
85
86 md_impl!(
87 $Op, $op $(where T: $($ScalarBounds),*)*;
88 ($R1, $C1),($R2, $C2)
89 const $($D),*;
90 for $($DimsDecl),*;
91 where $($ConstraintType: $ConstraintBound$(<$($ConstraintBoundParams $( = $EqBound )*),*>)*),*;
92 $lhs: &'a $Lhs, $rhs: &'b $Rhs, Output = $Result;
93 $action_ref_ref; 'a, 'b);
94 }
95);
96
97macro_rules! md_assign_impl(
99 (
100 $Op: ident, $op: ident $(where T: $($ScalarBounds: ident),*)* $(for T::Element: $($ElementBounds: ident),*)*;
102 ($R1: ty, $C1: ty),($R2: ty, $C2: ty)
104 const $($D: ident),*;
106 for $($DimsDecl: ident),*;
108 where $($ConstraintType: ty: $ConstraintBound: ident$(<$($ConstraintBoundParams: ty $( = $EqBound: ty )*),*>)*),*;
110 $lhs: ident: $Lhs: ty, $rhs: ident: $Rhs: ty;
112 $action: expr; $($lives: tt),*) => {
114 impl<$($lives ,)* T $(, $DimsDecl)* $(, const $D: usize)*> $Op<$Rhs> for $Lhs
115 where T: Scalar + Zero + One + ClosedAdd + ClosedMul $($(+ $ScalarBounds)*)*,
116 $($(T::Element: $ElementBounds,)*)*
117 $( $ConstraintType: $ConstraintBound $(<$( $ConstraintBoundParams $( = $EqBound )*),*>)* ),*
118 {
119 #[inline]
120 fn $op(&mut $lhs, $rhs: $Rhs) {
121 $action
122 }
123 }
124 }
125);
126
127macro_rules! md_assign_impl_all(
130 (
131 $Op: ident, $op: ident $(where T: $($ScalarBounds: ident),*)* $(for T::Element: $($ElementBounds: ident),*)*;
133 ($R1: ty, $C1: ty),($R2: ty, $C2: ty)
135 const $($D: ident),*;
137 for $($DimsDecl: ident),*;
139 where $($ConstraintType: ty: $ConstraintBound: ident$(<$($ConstraintBoundParams: ty $( = $EqBound: ty )*),*>)*),*;
141 $lhs: ident: $Lhs: ty, $rhs: ident: $Rhs: ty;
143 [val] => $action_val: expr;
145 [ref] => $action_ref: expr;) => {
146 md_assign_impl!(
147 $Op, $op $(where T: $($ScalarBounds),*)* $(for T::Element: $($ElementBounds),*)*;
148 ($R1, $C1),($R2, $C2)
149 const $($D),*;
150 for $($DimsDecl),*;
151 where $($ConstraintType: $ConstraintBound$(<$($ConstraintBoundParams $( = $EqBound )*),*>)*),*;
152 $lhs: $Lhs, $rhs: $Rhs;
153 $action_val; );
154
155 md_assign_impl!(
156 $Op, $op $(where T: $($ScalarBounds),*)* $(for T::Element: $($ElementBounds),*)*;
157 ($R1, $C1),($R2, $C2)
158 const $($D),*;
159 for $($DimsDecl),*;
160 where $($ConstraintType: $ConstraintBound$(<$($ConstraintBoundParams $( = $EqBound )*),*>)*),*;
161 $lhs: $Lhs, $rhs: &'b $Rhs;
162 $action_ref; 'b);
163 }
164);
165
166macro_rules! add_sub_impl(
169 ($Op: ident, $op: ident, $bound: ident;
170 ($R1: ty, $C1: ty),($R2: ty, $C2: ty) $(-> ($RRes: ty, $CRes: ty))*
171 const $($D: ident),*;
173 for $($DimsDecl: ident),*;
175 where $($ConstraintType: ty: $ConstraintBound: ident$(<$($ConstraintBoundParams: ty $( = $EqBound: ty )*),*>)*),*;
177 $lhs: ident: $Lhs: ty, $rhs: ident: $Rhs: ty, Output = $Result: ty;
178 $action: expr; $($lives: tt),*) => {
179 impl<$($lives ,)* T $(, $DimsDecl)* $(, const $D: usize)*> $Op<$Rhs> for $Lhs
180 where T: Scalar + $bound,
181 ShapeConstraint: SameNumberOfRows<$R1, $R2 $(, Representative = $RRes)*> +
182 SameNumberOfColumns<$C1, $C2 $(, Representative = $CRes)*>,
183 $( $ConstraintType: $ConstraintBound$(<$( $ConstraintBoundParams $( = $EqBound )*),*>)* ),* {
184 type Output = $Result;
185
186 #[inline]
187 fn $op($lhs, $rhs: $Rhs) -> Self::Output {
188 $action
189 }
190 }
191 }
192);
193
194macro_rules! add_sub_assign_impl(
197 ($Op: ident, $op: ident, $bound: ident;
198 $(const $D: ident),*;
199 $lhs: ident: $Lhs: ty, $rhs: ident: $Rhs: ty;
200 $action: expr; $($lives: tt),*) => {
201 impl<$($lives ,)* T $(, const $D: usize),*> $Op<$Rhs> for $Lhs
202 where T: Scalar + $bound {
203 #[inline]
204 fn $op(&mut $lhs, $rhs: $Rhs) {
205 $action
206 }
207 }
208 }
209);