src/direct_product.rs

branch
dev
changeset 115
f9aec20d0286
parent 114
b53806de0be0
child 116
6f22e4d277b4
equal deleted inserted replaced
114:b53806de0be0 115:f9aec20d0286
199 } 199 }
200 } 200 }
201 }; 201 };
202 } 202 }
203 203
204 macro_rules! impl_unaryop { 204 macro_rules! impl_unary {
205 (($a : ty, $b : ty), $trait:ident, $fn:ident, $refl:ident) => { 205 ($trait:ident, $fn:ident) => {
206 impl_unaryop!(@doit: $trait, $fn; 206 impl<A, B> $trait for Pair<A, B>
207 maybe_lifetime!($refl, &'l Pair<$a,$b>), 207 where
208 (maybe_lifetime!($refl, &'l $a), 208 A: $trait,
209 maybe_lifetime!($refl, &'l $b)); 209 B: $trait,
210 $refl); 210 {
211 }; 211 type Output = Pair<A::Output, B::Output>;
212 (@doit: $trait:ident, $fn:ident;
213 $self:ty, ($aself:ty, $bself:ty);
214 $refl : ident) => {
215 impl<'l> $trait
216 for $self
217 where $aself: $trait,
218 $bself: $trait {
219 type Output = Pair<<$aself as $trait>::Output,
220 <$bself as $trait>::Output>;
221 #[inline]
222 fn $fn(self) -> Self::Output { 212 fn $fn(self) -> Self::Output {
223 Pair(maybe_ref!($refl, self.0).$fn(), 213 let Pair(a, b) = self;
224 maybe_ref!($refl, self.1).$fn()) 214 Pair(a.$fn(), b.$fn())
225 } 215 }
226 } 216 }
227 } 217
228 } 218 impl<'a, A, B> $trait for &'a Pair<A, B>
219 where
220 &'a A: $trait,
221 &'a B: $trait,
222 {
223 type Output = Pair<<&'a A as $trait>::Output, <&'a B as $trait>::Output>;
224 fn $fn(self) -> Self::Output {
225 let Pair(ref a, ref b) = self;
226 Pair(a.$fn(), b.$fn())
227 }
228 }
229 };
230 }
231
232 impl_unary!(Neg, neg);
229 233
230 #[macro_export] 234 #[macro_export]
231 macro_rules! impl_pair_vectorspace_ops { 235 macro_rules! impl_pair_vectorspace_ops {
232 (($a:ty, $b:ty), $field:ty) => { 236 (($a:ty, $b:ty), $field:ty) => {
233 impl_pair_vectorspace_ops!(@binary, ($a, $b), Add, add); 237 impl_pair_vectorspace_ops!(@binary, ($a, $b), Add, add);
264 }; 268 };
265 (@scalar_assign, ($a : ty, $b : ty), $field : ty, $trait : ident, $fn : ident) => { 269 (@scalar_assign, ($a : ty, $b : ty), $field : ty, $trait : ident, $fn : ident) => {
266 impl_scalar_assignop!(($a, $b), $field, $trait, $fn); 270 impl_scalar_assignop!(($a, $b), $field, $trait, $fn);
267 }; 271 };
268 (@unary, ($a : ty, $b : ty), $trait : ident, $fn : ident) => { 272 (@unary, ($a : ty, $b : ty), $trait : ident, $fn : ident) => {
269 impl_unaryop!(($a, $b), $trait, $fn, ref); 273 //impl_unaryop!(($a, $b), $trait, $fn, ref);
270 impl_unaryop!(($a, $b), $trait, $fn, noref); 274 //impl_unaryop!(($a, $b), $trait, $fn, noref);
271 }; 275 };
272 } 276 }
273 277
274 // TODO: add what we can here. 278 // TODO: add what we can here.
275 #[macro_export] 279 #[macro_export]
281 // impl_pair_vectorspace_ops_gen!(@assign, SubAssign, sub_assign); 285 // impl_pair_vectorspace_ops_gen!(@assign, SubAssign, sub_assign);
282 impl_pair_vectorspace_ops_gen!(@scalar, $field, Mul, mul); 286 impl_pair_vectorspace_ops_gen!(@scalar, $field, Mul, mul);
283 impl_pair_vectorspace_ops_gen!(@scalar, $field, Div, div); 287 impl_pair_vectorspace_ops_gen!(@scalar, $field, Div, div);
284 // impl_pair_vectorspace_ops_gen!(@scalar_assign, $field, MulAssign, mul_assign); 288 // impl_pair_vectorspace_ops_gen!(@scalar_assign, $field, MulAssign, mul_assign);
285 // impl_pair_vectorspace_ops_gen!(@scalar_assign, $field, DivAssign, div_assign); 289 // impl_pair_vectorspace_ops_gen!(@scalar_assign, $field, DivAssign, div_assign);
286 // impl_pair_vectorspace_ops_gen!(@unary, Neg, neg); 290 //impl_unary!(Neg, neg);
287 }; 291 };
288 // (@binary, $trait : ident, $fn : ident) => { 292 // (@binary, $trait : ident, $fn : ident) => {
289 // impl_binop_gen!(($a, $b), $trait, $fn, ref, ref); 293 // impl_binop_gen!(($a, $b), $trait, $fn, ref, ref);
290 // impl_binop_gen!(($a, $b), $trait, $fn, ref, noref); 294 // impl_binop_gen!(($a, $b), $trait, $fn, ref, noref);
291 // impl_binop_gen!(($a, $b), $trait, $fn, noref, ref); 295 // impl_binop_gen!(($a, $b), $trait, $fn, noref, ref);
305 // }; 309 // };
306 // (@scalar_assign, $field : ty, $trait : ident, $fn : ident) => { 310 // (@scalar_assign, $field : ty, $trait : ident, $fn : ident) => {
307 // impl_scalar_assignop_gen!(($a, $b), $field, $trait, $fn); 311 // impl_scalar_assignop_gen!(($a, $b), $field, $trait, $fn);
308 // }; 312 // };
309 // (@unary, $trait : ident, $fn : ident) => { 313 // (@unary, $trait : ident, $fn : ident) => {
310 // impl_unaryop_gen!(($a, $b), $trait, $fn, ref); 314 // //impl_unaryop_gen!($trait, $fn, ref);
311 // impl_unaryop_gen!(($a, $b), $trait, $fn, noref); 315 // //impl_unaryop_gen!($trait, $fn, noref);
312 // }; 316 // };
313 } 317 }
314 318
315 impl_pair_vectorspace_ops_gen!(f32); 319 impl_pair_vectorspace_ops_gen!(f32);
316 impl_pair_vectorspace_ops_gen!(f64); 320 impl_pair_vectorspace_ops_gen!(f64);
344 + for<'b> Add<&'b Self, Output = PairOutput<$field, A, B>> 348 + for<'b> Add<&'b Self, Output = PairOutput<$field, A, B>>
345 + for<'b> Sub<&'b Self, Output = PairOutput<$field, A, B>> 349 + for<'b> Sub<&'b Self, Output = PairOutput<$field, A, B>>
346 + AddAssign<Self> 350 + AddAssign<Self>
347 + for<'b> AddAssign<&'b Self> 351 + for<'b> AddAssign<&'b Self>
348 + SubAssign<Self> 352 + SubAssign<Self>
349 + for<'b> SubAssign<&'b Self> 353 + for<'b> SubAssign<&'b Self>, //+ Neg<Output = PairOutput<$field, A, B>>,
350 + Neg<Output = PairOutput<$field, A, B>>,
351 { 354 {
352 type Output = PairOutput<$field, A, B>; 355 type Output = PairOutput<$field, A, B>;
353 356
354 fn dot<I: Instance<Self>>(&self, other: I) -> $field { 357 fn dot<I: Instance<Self>>(&self, other: I) -> $field {
355 let Pair(u, v) = other.decompose(); 358 let Pair(u, v) = other.decompose();

mercurial