src/direct_product.rs

Thu, 01 May 2025 01:25:27 -0500

author
Tuomo Valkonen <tuomov@iki.fi>
date
Thu, 01 May 2025 01:25:27 -0500
branch
dev
changeset 116
6f22e4d277b4
parent 115
f9aec20d0286
child 117
9b782aa6b452
permissions
-rw-r--r--

binops

57
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
1 /*!
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
2 Direct products of the form $A \times B$.
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
3
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
4 TODO: This could be easily much more generic if `derive_more` could derive arithmetic
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
5 operations on references.
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
6 */
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
7
63
f7b87d84864d Extra reflexivity and hilbert-like requirements for Euclidean. Fuse Dot into Euclidean.
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
8 use crate::euclidean::Euclidean;
94
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
9 use crate::instance::{Decomposition, DecompositionMut, Instance, InstanceMut, MyCow};
59
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
10 use crate::linops::AXPY;
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
11 use crate::loc::Loc;
94
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
12 use crate::mapping::Space;
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
13 use crate::norms::{HasDual, Norm, NormExponent, Normed, PairNorm, L2};
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
14 use crate::types::{Float, Num};
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
15 use core::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, Sub, SubAssign};
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
16 use serde::{Deserialize, Serialize};
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
17 use std::clone::Clone;
57
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
18
94
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
19 #[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
20 pub struct Pair<A, B>(pub A, pub B);
57
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
21
94
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
22 impl<A, B> Pair<A, B> {
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
23 pub fn new(a: A, b: B) -> Pair<A, B> {
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
24 Pair(a, b)
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
25 }
57
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
26 }
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
27
94
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
28 impl<A, B> From<(A, B)> for Pair<A, B> {
57
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
29 #[inline]
94
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
30 fn from((a, b): (A, B)) -> Pair<A, B> {
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
31 Pair(a, b)
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
32 }
59
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
33 }
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
34
94
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
35 impl<A, B> From<Pair<A, B>> for (A, B) {
59
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
36 #[inline]
94
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
37 fn from(Pair(a, b): Pair<A, B>) -> (A, B) {
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
38 (a, b)
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
39 }
57
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
40 }
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
41
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
42 macro_rules! impl_assignop {
59
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
43 (($a : ty, $b : ty), $trait : ident, $fn : ident, $refr:ident) => {
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
44 impl_assignop!(@doit: $a, $b,
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
45 $trait, $fn;
57
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
46 maybe_lifetime!($refr, &'r Pair<Ai,Bi>),
59
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
47 (maybe_lifetime!($refr, &'r Ai),
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
48 maybe_lifetime!($refr, &'r Bi));
57
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
49 $refr);
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
50 };
59
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
51 (@doit: $a : ty, $b : ty,
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
52 $trait:ident, $fn:ident;
57
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
53 $in:ty, ($ain:ty, $bin:ty);
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
54 $refr:ident) => {
59
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
55 impl<'r, Ai, Bi> $trait<$in>
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
56 for Pair<$a,$b>
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
57 where $a: $trait<$ain>,
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
58 $b: $trait<$bin> {
57
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
59 #[inline]
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
60 fn $fn(&mut self, y : $in) -> () {
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
61 self.0.$fn(maybe_ref!($refr, y.0));
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
62 self.1.$fn(maybe_ref!($refr, y.1));
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
63 }
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
64 }
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
65 }
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
66 }
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
67
103
e98e1da2530d Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents: 94
diff changeset
68 // macro_rules! impl_scalarop {
e98e1da2530d Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents: 94
diff changeset
69 // (($a : ty, $b : ty), $field : ty, $trait : ident, $fn : ident, $refl:ident) => {
e98e1da2530d Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents: 94
diff changeset
70 // impl_scalarop!(@doit: $field,
e98e1da2530d Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents: 94
diff changeset
71 // $trait, $fn;
e98e1da2530d Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents: 94
diff changeset
72 // maybe_lifetime!($refl, &'l Pair<$a,$b>),
e98e1da2530d Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents: 94
diff changeset
73 // (maybe_lifetime!($refl, &'l $a),
e98e1da2530d Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents: 94
diff changeset
74 // maybe_lifetime!($refl, &'l $b));
e98e1da2530d Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents: 94
diff changeset
75 // $refl);
e98e1da2530d Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents: 94
diff changeset
76 // };
e98e1da2530d Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents: 94
diff changeset
77 // (@doit: $field : ty,
e98e1da2530d Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents: 94
diff changeset
78 // $trait:ident, $fn:ident;
e98e1da2530d Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents: 94
diff changeset
79 // $self:ty, ($aself:ty, $bself:ty);
e98e1da2530d Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents: 94
diff changeset
80 // $refl:ident) => {
e98e1da2530d Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents: 94
diff changeset
81 // // Scalar as Rhs
e98e1da2530d Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents: 94
diff changeset
82 // impl<'l> $trait<$field>
e98e1da2530d Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents: 94
diff changeset
83 // for $self
e98e1da2530d Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents: 94
diff changeset
84 // where $aself: $trait<$field>,
e98e1da2530d Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents: 94
diff changeset
85 // $bself: $trait<$field> {
e98e1da2530d Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents: 94
diff changeset
86 // type Output = Pair<<$aself as $trait<$field>>::Output,
e98e1da2530d Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents: 94
diff changeset
87 // <$bself as $trait<$field>>::Output>;
e98e1da2530d Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents: 94
diff changeset
88 // #[inline]
e98e1da2530d Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents: 94
diff changeset
89 // fn $fn(self, a : $field) -> Self::Output {
e98e1da2530d Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents: 94
diff changeset
90 // Pair(maybe_ref!($refl, self.0).$fn(a),
e98e1da2530d Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents: 94
diff changeset
91 // maybe_ref!($refl, self.1).$fn(a))
e98e1da2530d Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents: 94
diff changeset
92 // }
e98e1da2530d Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents: 94
diff changeset
93 // }
e98e1da2530d Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents: 94
diff changeset
94 // }
e98e1da2530d Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents: 94
diff changeset
95 // }
e98e1da2530d Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents: 94
diff changeset
96 //
e98e1da2530d Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents: 94
diff changeset
97
e98e1da2530d Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents: 94
diff changeset
98 macro_rules! impl_scalarop_gen {
e98e1da2530d Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents: 94
diff changeset
99 ($field : ty, $trait : ident, $fn : ident, $refl:ident) => {
e98e1da2530d Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents: 94
diff changeset
100 impl_scalarop_gen!(@doit: $field,
59
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
101 $trait, $fn;
103
e98e1da2530d Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents: 94
diff changeset
102 maybe_lifetime!($refl, &'l Pair<A,B>),
e98e1da2530d Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents: 94
diff changeset
103 (maybe_lifetime!($refl, &'l A),
e98e1da2530d Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents: 94
diff changeset
104 maybe_lifetime!($refl, &'l B));
57
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
105 $refl);
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
106 };
59
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
107 (@doit: $field : ty,
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
108 $trait:ident, $fn:ident;
57
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
109 $self:ty, ($aself:ty, $bself:ty);
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
110 $refl:ident) => {
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
111 // Scalar as Rhs
103
e98e1da2530d Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents: 94
diff changeset
112 impl<'l, A, B> $trait<$field>
57
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
113 for $self
59
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
114 where $aself: $trait<$field>,
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
115 $bself: $trait<$field> {
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
116 type Output = Pair<<$aself as $trait<$field>>::Output,
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
117 <$bself as $trait<$field>>::Output>;
57
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
118 #[inline]
59
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
119 fn $fn(self, a : $field) -> Self::Output {
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
120 Pair(maybe_ref!($refl, self.0).$fn(a),
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
121 maybe_ref!($refl, self.1).$fn(a))
57
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
122 }
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
123 }
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
124 }
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
125 }
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
126
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
127 // Not used due to compiler overflow
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
128 #[allow(unused_macros)]
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
129 macro_rules! impl_scalarlhs_op {
59
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
130 (($a : ty, $b : ty), $field : ty, $trait:ident, $fn:ident, $refr:ident) => {
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
131 impl_scalarlhs_op!(@doit: $trait, $fn,
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
132 maybe_lifetime!($refr, &'r Pair<$a,$b>),
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
133 (maybe_lifetime!($refr, &'r $a),
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
134 maybe_lifetime!($refr, &'r $b));
57
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
135 $refr, $field);
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
136 };
59
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
137 (@doit: $trait:ident, $fn:ident,
57
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
138 $in:ty, ($ain:ty, $bin:ty);
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
139 $refr:ident, $field:ty) => {
59
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
140 impl<'r> $trait<$in>
57
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
141 for $field
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
142 where $field : $trait<$ain>
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
143 + $trait<$bin> {
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
144 type Output = Pair<<$field as $trait<$ain>>::Output,
59
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
145 <$field as $trait<$bin>>::Output>;
57
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
146 #[inline]
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
147 fn $fn(self, x : $in) -> Self::Output {
59
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
148 Pair(self.$fn(maybe_ref!($refr, x.0)),
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
149 self.$fn(maybe_ref!($refr, x.1)))
57
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
150 }
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
151 }
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
152 };
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
153 }
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
154
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
155 macro_rules! impl_scalar_assignop {
59
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
156 (($a : ty, $b : ty), $field : ty, $trait : ident, $fn : ident) => {
94
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
157 impl<'r> $trait<$field> for Pair<$a, $b>
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
158 where
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
159 $a: $trait<$field>,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
160 $b: $trait<$field>,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
161 {
57
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
162 #[inline]
94
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
163 fn $fn(&mut self, a: $field) -> () {
57
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
164 self.0.$fn(a);
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
165 self.1.$fn(a);
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
166 }
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
167 }
94
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
168 };
57
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
169 }
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
170
115
Tuomo Valkonen <tuomov@iki.fi>
parents: 114
diff changeset
171 macro_rules! impl_unary {
Tuomo Valkonen <tuomov@iki.fi>
parents: 114
diff changeset
172 ($trait:ident, $fn:ident) => {
Tuomo Valkonen <tuomov@iki.fi>
parents: 114
diff changeset
173 impl<A, B> $trait for Pair<A, B>
Tuomo Valkonen <tuomov@iki.fi>
parents: 114
diff changeset
174 where
Tuomo Valkonen <tuomov@iki.fi>
parents: 114
diff changeset
175 A: $trait,
Tuomo Valkonen <tuomov@iki.fi>
parents: 114
diff changeset
176 B: $trait,
Tuomo Valkonen <tuomov@iki.fi>
parents: 114
diff changeset
177 {
Tuomo Valkonen <tuomov@iki.fi>
parents: 114
diff changeset
178 type Output = Pair<A::Output, B::Output>;
57
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
179 fn $fn(self) -> Self::Output {
115
Tuomo Valkonen <tuomov@iki.fi>
parents: 114
diff changeset
180 let Pair(a, b) = self;
Tuomo Valkonen <tuomov@iki.fi>
parents: 114
diff changeset
181 Pair(a.$fn(), b.$fn())
57
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
182 }
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
183 }
115
Tuomo Valkonen <tuomov@iki.fi>
parents: 114
diff changeset
184
Tuomo Valkonen <tuomov@iki.fi>
parents: 114
diff changeset
185 impl<'a, A, B> $trait for &'a Pair<A, B>
Tuomo Valkonen <tuomov@iki.fi>
parents: 114
diff changeset
186 where
Tuomo Valkonen <tuomov@iki.fi>
parents: 114
diff changeset
187 &'a A: $trait,
Tuomo Valkonen <tuomov@iki.fi>
parents: 114
diff changeset
188 &'a B: $trait,
Tuomo Valkonen <tuomov@iki.fi>
parents: 114
diff changeset
189 {
Tuomo Valkonen <tuomov@iki.fi>
parents: 114
diff changeset
190 type Output = Pair<<&'a A as $trait>::Output, <&'a B as $trait>::Output>;
Tuomo Valkonen <tuomov@iki.fi>
parents: 114
diff changeset
191 fn $fn(self) -> Self::Output {
Tuomo Valkonen <tuomov@iki.fi>
parents: 114
diff changeset
192 let Pair(ref a, ref b) = self;
Tuomo Valkonen <tuomov@iki.fi>
parents: 114
diff changeset
193 Pair(a.$fn(), b.$fn())
Tuomo Valkonen <tuomov@iki.fi>
parents: 114
diff changeset
194 }
Tuomo Valkonen <tuomov@iki.fi>
parents: 114
diff changeset
195 }
Tuomo Valkonen <tuomov@iki.fi>
parents: 114
diff changeset
196 };
57
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
197 }
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
198
115
Tuomo Valkonen <tuomov@iki.fi>
parents: 114
diff changeset
199 impl_unary!(Neg, neg);
Tuomo Valkonen <tuomov@iki.fi>
parents: 114
diff changeset
200
116
Tuomo Valkonen <tuomov@iki.fi>
parents: 115
diff changeset
201 macro_rules! impl_binary {
Tuomo Valkonen <tuomov@iki.fi>
parents: 115
diff changeset
202 ($trait:ident, $fn:ident) => {
Tuomo Valkonen <tuomov@iki.fi>
parents: 115
diff changeset
203 impl<A, B, C, D> $trait<Pair<C, D>> for Pair<A, B>
Tuomo Valkonen <tuomov@iki.fi>
parents: 115
diff changeset
204 where
Tuomo Valkonen <tuomov@iki.fi>
parents: 115
diff changeset
205 A: $trait<C>,
Tuomo Valkonen <tuomov@iki.fi>
parents: 115
diff changeset
206 B: $trait<D>,
Tuomo Valkonen <tuomov@iki.fi>
parents: 115
diff changeset
207 {
Tuomo Valkonen <tuomov@iki.fi>
parents: 115
diff changeset
208 type Output = Pair<A::Output, B::Output>;
Tuomo Valkonen <tuomov@iki.fi>
parents: 115
diff changeset
209 fn $fn(self, Pair(c, d): Pair<C, D>) -> Self::Output {
Tuomo Valkonen <tuomov@iki.fi>
parents: 115
diff changeset
210 let Pair(a, b) = self;
Tuomo Valkonen <tuomov@iki.fi>
parents: 115
diff changeset
211 Pair(a.$fn(c), b.$fn(d))
Tuomo Valkonen <tuomov@iki.fi>
parents: 115
diff changeset
212 }
Tuomo Valkonen <tuomov@iki.fi>
parents: 115
diff changeset
213 }
Tuomo Valkonen <tuomov@iki.fi>
parents: 115
diff changeset
214
Tuomo Valkonen <tuomov@iki.fi>
parents: 115
diff changeset
215 impl<'a, A, B, C, D> $trait<Pair<C, D>> for &'a Pair<A, B>
Tuomo Valkonen <tuomov@iki.fi>
parents: 115
diff changeset
216 where
Tuomo Valkonen <tuomov@iki.fi>
parents: 115
diff changeset
217 &'a A: $trait<C>,
Tuomo Valkonen <tuomov@iki.fi>
parents: 115
diff changeset
218 &'a B: $trait<D>,
Tuomo Valkonen <tuomov@iki.fi>
parents: 115
diff changeset
219 {
Tuomo Valkonen <tuomov@iki.fi>
parents: 115
diff changeset
220 type Output = Pair<<&'a A as $trait<C>>::Output, <&'a B as $trait<D>>::Output>;
Tuomo Valkonen <tuomov@iki.fi>
parents: 115
diff changeset
221 fn $fn(self, Pair(c, d): Pair<C, D>) -> Self::Output {
Tuomo Valkonen <tuomov@iki.fi>
parents: 115
diff changeset
222 let Pair(ref a, ref b) = self;
Tuomo Valkonen <tuomov@iki.fi>
parents: 115
diff changeset
223 Pair(a.$fn(c), b.$fn(d))
Tuomo Valkonen <tuomov@iki.fi>
parents: 115
diff changeset
224 }
Tuomo Valkonen <tuomov@iki.fi>
parents: 115
diff changeset
225 }
Tuomo Valkonen <tuomov@iki.fi>
parents: 115
diff changeset
226
Tuomo Valkonen <tuomov@iki.fi>
parents: 115
diff changeset
227 impl<'a, 'b, A, B, C, D> $trait<&'b Pair<C, D>> for &'a Pair<A, B>
Tuomo Valkonen <tuomov@iki.fi>
parents: 115
diff changeset
228 where
Tuomo Valkonen <tuomov@iki.fi>
parents: 115
diff changeset
229 &'a A: $trait<&'b C>,
Tuomo Valkonen <tuomov@iki.fi>
parents: 115
diff changeset
230 &'a B: $trait<&'b D>,
Tuomo Valkonen <tuomov@iki.fi>
parents: 115
diff changeset
231 {
Tuomo Valkonen <tuomov@iki.fi>
parents: 115
diff changeset
232 type Output = Pair<<&'a A as $trait<&'b C>>::Output, <&'a B as $trait<&'b D>>::Output>;
Tuomo Valkonen <tuomov@iki.fi>
parents: 115
diff changeset
233 fn $fn(self, Pair(ref c, ref d): &'b Pair<C, D>) -> Self::Output {
Tuomo Valkonen <tuomov@iki.fi>
parents: 115
diff changeset
234 let Pair(ref a, ref b) = self;
Tuomo Valkonen <tuomov@iki.fi>
parents: 115
diff changeset
235 Pair(a.$fn(c), b.$fn(d))
Tuomo Valkonen <tuomov@iki.fi>
parents: 115
diff changeset
236 }
Tuomo Valkonen <tuomov@iki.fi>
parents: 115
diff changeset
237 }
Tuomo Valkonen <tuomov@iki.fi>
parents: 115
diff changeset
238
Tuomo Valkonen <tuomov@iki.fi>
parents: 115
diff changeset
239 impl<'b, A, B, C, D> $trait<&'b Pair<C, D>> for Pair<A, B>
Tuomo Valkonen <tuomov@iki.fi>
parents: 115
diff changeset
240 where
Tuomo Valkonen <tuomov@iki.fi>
parents: 115
diff changeset
241 A: $trait<&'b C>,
Tuomo Valkonen <tuomov@iki.fi>
parents: 115
diff changeset
242 B: $trait<&'b D>,
Tuomo Valkonen <tuomov@iki.fi>
parents: 115
diff changeset
243 {
Tuomo Valkonen <tuomov@iki.fi>
parents: 115
diff changeset
244 type Output = Pair<<A as $trait<&'b C>>::Output, <B as $trait<&'b D>>::Output>;
Tuomo Valkonen <tuomov@iki.fi>
parents: 115
diff changeset
245 fn $fn(self, Pair(ref c, ref d): &'b Pair<C, D>) -> Self::Output {
Tuomo Valkonen <tuomov@iki.fi>
parents: 115
diff changeset
246 let Pair(a, b) = self;
Tuomo Valkonen <tuomov@iki.fi>
parents: 115
diff changeset
247 Pair(a.$fn(c), b.$fn(d))
Tuomo Valkonen <tuomov@iki.fi>
parents: 115
diff changeset
248 }
Tuomo Valkonen <tuomov@iki.fi>
parents: 115
diff changeset
249 }
Tuomo Valkonen <tuomov@iki.fi>
parents: 115
diff changeset
250 };
Tuomo Valkonen <tuomov@iki.fi>
parents: 115
diff changeset
251 }
Tuomo Valkonen <tuomov@iki.fi>
parents: 115
diff changeset
252
Tuomo Valkonen <tuomov@iki.fi>
parents: 115
diff changeset
253 impl_binary!(Add, add);
Tuomo Valkonen <tuomov@iki.fi>
parents: 115
diff changeset
254 impl_binary!(Sub, sub);
Tuomo Valkonen <tuomov@iki.fi>
parents: 115
diff changeset
255
59
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
256 #[macro_export]
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
257 macro_rules! impl_pair_vectorspace_ops {
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
258 (($a:ty, $b:ty), $field:ty) => {
116
Tuomo Valkonen <tuomov@iki.fi>
parents: 115
diff changeset
259 //impl_pair_vectorspace_ops!(@binary, ($a, $b), Add, add);
Tuomo Valkonen <tuomov@iki.fi>
parents: 115
diff changeset
260 //impl_pair_vectorspace_ops!(@binary, ($a, $b), Sub, sub);
59
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
261 impl_pair_vectorspace_ops!(@assign, ($a, $b), AddAssign, add_assign);
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
262 impl_pair_vectorspace_ops!(@assign, ($a, $b), SubAssign, sub_assign);
103
e98e1da2530d Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents: 94
diff changeset
263 // impl_pair_vectorspace_ops!(@scalar, ($a, $b), $field, Mul, mul);
e98e1da2530d Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents: 94
diff changeset
264 // impl_pair_vectorspace_ops!(@scalar, ($a, $b), $field, Div, div);
59
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
265 // Compiler overflow
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
266 // $(
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
267 // impl_pair_vectorspace_ops!(@scalar_lhs, ($a, $b), $field, $impl_scalarlhs_op, Mul, mul);
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
268 // )*
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
269 impl_pair_vectorspace_ops!(@scalar_assign, ($a, $b), $field, MulAssign, mul_assign);
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
270 impl_pair_vectorspace_ops!(@scalar_assign, ($a, $b), $field, DivAssign, div_assign);
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
271 };
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
272 (@binary, ($a : ty, $b : ty), $trait : ident, $fn : ident) => {
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
273 impl_binop!(($a, $b), $trait, $fn, ref, ref);
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
274 impl_binop!(($a, $b), $trait, $fn, ref, noref);
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
275 impl_binop!(($a, $b), $trait, $fn, noref, ref);
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
276 impl_binop!(($a, $b), $trait, $fn, noref, noref);
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
277 };
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
278 (@assign, ($a : ty, $b : ty), $trait : ident, $fn :ident) => {
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
279 impl_assignop!(($a, $b), $trait, $fn, ref);
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
280 impl_assignop!(($a, $b), $trait, $fn, noref);
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
281 };
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
282 (@scalar, ($a : ty, $b : ty), $field : ty, $trait : ident, $fn :ident) => {
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
283 impl_scalarop!(($a, $b), $field, $trait, $fn, ref);
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
284 impl_scalarop!(($a, $b), $field, $trait, $fn, noref);
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
285 };
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
286 (@scalar_lhs, ($a : ty, $b : ty), $field : ty, $trait : ident, $fn : ident) => {
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
287 impl_scalarlhs_op!(($a, $b), $field, $trait, $fn, ref);
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
288 impl_scalarlhs_op!(($a, $b), $field, $trait, $fn, noref);
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
289 };
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
290 (@scalar_assign, ($a : ty, $b : ty), $field : ty, $trait : ident, $fn : ident) => {
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
291 impl_scalar_assignop!(($a, $b), $field, $trait, $fn);
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
292 };
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
293 }
57
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
294
103
e98e1da2530d Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents: 94
diff changeset
295 // TODO: add what we can here.
e98e1da2530d Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents: 94
diff changeset
296 #[macro_export]
e98e1da2530d Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents: 94
diff changeset
297 macro_rules! impl_pair_vectorspace_ops_gen {
e98e1da2530d Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents: 94
diff changeset
298 ($field:ty) => {
e98e1da2530d Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents: 94
diff changeset
299 // impl_pair_vectorspace_ops_gen!(@binary, Add, add);
e98e1da2530d Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents: 94
diff changeset
300 // impl_pair_vectorspace_ops_gen!(@binary, Sub, sub);
e98e1da2530d Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents: 94
diff changeset
301 // impl_pair_vectorspace_ops_gen!(@assign, AddAssign, add_assign);
e98e1da2530d Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents: 94
diff changeset
302 // impl_pair_vectorspace_ops_gen!(@assign, SubAssign, sub_assign);
e98e1da2530d Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents: 94
diff changeset
303 impl_pair_vectorspace_ops_gen!(@scalar, $field, Mul, mul);
e98e1da2530d Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents: 94
diff changeset
304 impl_pair_vectorspace_ops_gen!(@scalar, $field, Div, div);
e98e1da2530d Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents: 94
diff changeset
305 // impl_pair_vectorspace_ops_gen!(@scalar_assign, $field, MulAssign, mul_assign);
e98e1da2530d Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents: 94
diff changeset
306 // impl_pair_vectorspace_ops_gen!(@scalar_assign, $field, DivAssign, div_assign);
e98e1da2530d Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents: 94
diff changeset
307 };
e98e1da2530d Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents: 94
diff changeset
308 // (@binary, $trait : ident, $fn : ident) => {
e98e1da2530d Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents: 94
diff changeset
309 // impl_binop_gen!(($a, $b), $trait, $fn, ref, ref);
e98e1da2530d Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents: 94
diff changeset
310 // impl_binop_gen!(($a, $b), $trait, $fn, ref, noref);
e98e1da2530d Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents: 94
diff changeset
311 // impl_binop_gen!(($a, $b), $trait, $fn, noref, ref);
e98e1da2530d Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents: 94
diff changeset
312 // impl_binop_gen!(($a, $b), $trait, $fn, noref, noref);
e98e1da2530d Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents: 94
diff changeset
313 // };
e98e1da2530d Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents: 94
diff changeset
314 // (@assign, $trait : ident, $fn :ident) => {
e98e1da2530d Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents: 94
diff changeset
315 // impl_assignop_gen!(($a, $b), $trait, $fn, ref);
e98e1da2530d Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents: 94
diff changeset
316 // impl_assignop_gen!(($a, $b), $trait, $fn, noref);
e98e1da2530d Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents: 94
diff changeset
317 // };
e98e1da2530d Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents: 94
diff changeset
318 (@scalar, $field : ty, $trait : ident, $fn :ident) => {
e98e1da2530d Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents: 94
diff changeset
319 impl_scalarop_gen!($field, $trait, $fn, ref);
e98e1da2530d Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents: 94
diff changeset
320 impl_scalarop_gen!($field, $trait, $fn, noref);
e98e1da2530d Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents: 94
diff changeset
321 };
e98e1da2530d Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents: 94
diff changeset
322 // (@scalar_lhs, $field : ty, $trait : ident, $fn : ident) => {
e98e1da2530d Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents: 94
diff changeset
323 // impl_scalarlhs_op_gen!(($a, $b), $field, $trait, $fn, ref);
e98e1da2530d Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents: 94
diff changeset
324 // impl_scalarlhs_op_gen!(($a, $b), $field, $trait, $fn, noref);
e98e1da2530d Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents: 94
diff changeset
325 // };
e98e1da2530d Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents: 94
diff changeset
326 // (@scalar_assign, $field : ty, $trait : ident, $fn : ident) => {
e98e1da2530d Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents: 94
diff changeset
327 // impl_scalar_assignop_gen!(($a, $b), $field, $trait, $fn);
e98e1da2530d Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents: 94
diff changeset
328 // };
e98e1da2530d Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents: 94
diff changeset
329 }
e98e1da2530d Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents: 94
diff changeset
330
e98e1da2530d Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents: 94
diff changeset
331 impl_pair_vectorspace_ops_gen!(f32);
e98e1da2530d Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents: 94
diff changeset
332 impl_pair_vectorspace_ops_gen!(f64);
e98e1da2530d Add generic scalar right multiplication for Pair
Tuomo Valkonen <tuomov@iki.fi>
parents: 94
diff changeset
333
59
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
334 impl_pair_vectorspace_ops!((f32, f32), f32);
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
335 impl_pair_vectorspace_ops!((f64, f64), f64);
57
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
336
59
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
337 type PairOutput<F, A, B> = Pair<<A as Euclidean<F>>::Output, <B as Euclidean<F>>::Output>;
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
338
114
b53806de0be0 impl_euclidean with fixed field
Tuomo Valkonen <tuomov@iki.fi>
parents: 103
diff changeset
339 /// We need to restrict `A` and `B` as [`Euclidean`] to have closed `Output`
b53806de0be0 impl_euclidean with fixed field
Tuomo Valkonen <tuomov@iki.fi>
parents: 103
diff changeset
340 /// to avoid compiler overflows that the requirement
b53806de0be0 impl_euclidean with fixed field
Tuomo Valkonen <tuomov@iki.fi>
parents: 103
diff changeset
341 /// ```
b53806de0be0 impl_euclidean with fixed field
Tuomo Valkonen <tuomov@iki.fi>
parents: 103
diff changeset
342 /// Pair<<A as Euclidean<F>>::Output, <B as Euclidean<F>>::Output> : Euclidean<F>
b53806de0be0 impl_euclidean with fixed field
Tuomo Valkonen <tuomov@iki.fi>
parents: 103
diff changeset
343 /// ```
b53806de0be0 impl_euclidean with fixed field
Tuomo Valkonen <tuomov@iki.fi>
parents: 103
diff changeset
344 /// would generate.
57
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
345
114
b53806de0be0 impl_euclidean with fixed field
Tuomo Valkonen <tuomov@iki.fi>
parents: 103
diff changeset
346 macro_rules! impl_euclidean {
b53806de0be0 impl_euclidean with fixed field
Tuomo Valkonen <tuomov@iki.fi>
parents: 103
diff changeset
347 ($field:ty) => {
b53806de0be0 impl_euclidean with fixed field
Tuomo Valkonen <tuomov@iki.fi>
parents: 103
diff changeset
348 impl<A, B> Euclidean<$field> for Pair<A, B>
b53806de0be0 impl_euclidean with fixed field
Tuomo Valkonen <tuomov@iki.fi>
parents: 103
diff changeset
349 where
b53806de0be0 impl_euclidean with fixed field
Tuomo Valkonen <tuomov@iki.fi>
parents: 103
diff changeset
350 A: Euclidean<$field>,
b53806de0be0 impl_euclidean with fixed field
Tuomo Valkonen <tuomov@iki.fi>
parents: 103
diff changeset
351 B: Euclidean<$field>,
b53806de0be0 impl_euclidean with fixed field
Tuomo Valkonen <tuomov@iki.fi>
parents: 103
diff changeset
352 PairOutput<$field, A, B>: Euclidean<$field>,
b53806de0be0 impl_euclidean with fixed field
Tuomo Valkonen <tuomov@iki.fi>
parents: 103
diff changeset
353 Self: Sized
b53806de0be0 impl_euclidean with fixed field
Tuomo Valkonen <tuomov@iki.fi>
parents: 103
diff changeset
354 + Mul<$field, Output = PairOutput<$field, A, B>>
b53806de0be0 impl_euclidean with fixed field
Tuomo Valkonen <tuomov@iki.fi>
parents: 103
diff changeset
355 + MulAssign<$field>
b53806de0be0 impl_euclidean with fixed field
Tuomo Valkonen <tuomov@iki.fi>
parents: 103
diff changeset
356 + Div<$field, Output = PairOutput<$field, A, B>>
b53806de0be0 impl_euclidean with fixed field
Tuomo Valkonen <tuomov@iki.fi>
parents: 103
diff changeset
357 + DivAssign<$field>
b53806de0be0 impl_euclidean with fixed field
Tuomo Valkonen <tuomov@iki.fi>
parents: 103
diff changeset
358 + Add<Self, Output = PairOutput<$field, A, B>>
b53806de0be0 impl_euclidean with fixed field
Tuomo Valkonen <tuomov@iki.fi>
parents: 103
diff changeset
359 + Sub<Self, Output = PairOutput<$field, A, B>>
b53806de0be0 impl_euclidean with fixed field
Tuomo Valkonen <tuomov@iki.fi>
parents: 103
diff changeset
360 + for<'b> Add<&'b Self, Output = PairOutput<$field, A, B>>
b53806de0be0 impl_euclidean with fixed field
Tuomo Valkonen <tuomov@iki.fi>
parents: 103
diff changeset
361 + for<'b> Sub<&'b Self, Output = PairOutput<$field, A, B>>
b53806de0be0 impl_euclidean with fixed field
Tuomo Valkonen <tuomov@iki.fi>
parents: 103
diff changeset
362 + AddAssign<Self>
b53806de0be0 impl_euclidean with fixed field
Tuomo Valkonen <tuomov@iki.fi>
parents: 103
diff changeset
363 + for<'b> AddAssign<&'b Self>
b53806de0be0 impl_euclidean with fixed field
Tuomo Valkonen <tuomov@iki.fi>
parents: 103
diff changeset
364 + SubAssign<Self>
115
Tuomo Valkonen <tuomov@iki.fi>
parents: 114
diff changeset
365 + for<'b> SubAssign<&'b Self>, //+ Neg<Output = PairOutput<$field, A, B>>,
114
b53806de0be0 impl_euclidean with fixed field
Tuomo Valkonen <tuomov@iki.fi>
parents: 103
diff changeset
366 {
b53806de0be0 impl_euclidean with fixed field
Tuomo Valkonen <tuomov@iki.fi>
parents: 103
diff changeset
367 type Output = PairOutput<$field, A, B>;
63
f7b87d84864d Extra reflexivity and hilbert-like requirements for Euclidean. Fuse Dot into Euclidean.
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
368
114
b53806de0be0 impl_euclidean with fixed field
Tuomo Valkonen <tuomov@iki.fi>
parents: 103
diff changeset
369 fn dot<I: Instance<Self>>(&self, other: I) -> $field {
b53806de0be0 impl_euclidean with fixed field
Tuomo Valkonen <tuomov@iki.fi>
parents: 103
diff changeset
370 let Pair(u, v) = other.decompose();
b53806de0be0 impl_euclidean with fixed field
Tuomo Valkonen <tuomov@iki.fi>
parents: 103
diff changeset
371 self.0.dot(u) + self.1.dot(v)
b53806de0be0 impl_euclidean with fixed field
Tuomo Valkonen <tuomov@iki.fi>
parents: 103
diff changeset
372 }
b53806de0be0 impl_euclidean with fixed field
Tuomo Valkonen <tuomov@iki.fi>
parents: 103
diff changeset
373
b53806de0be0 impl_euclidean with fixed field
Tuomo Valkonen <tuomov@iki.fi>
parents: 103
diff changeset
374 fn norm2_squared(&self) -> $field {
b53806de0be0 impl_euclidean with fixed field
Tuomo Valkonen <tuomov@iki.fi>
parents: 103
diff changeset
375 self.0.norm2_squared() + self.1.norm2_squared()
b53806de0be0 impl_euclidean with fixed field
Tuomo Valkonen <tuomov@iki.fi>
parents: 103
diff changeset
376 }
63
f7b87d84864d Extra reflexivity and hilbert-like requirements for Euclidean. Fuse Dot into Euclidean.
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
377
114
b53806de0be0 impl_euclidean with fixed field
Tuomo Valkonen <tuomov@iki.fi>
parents: 103
diff changeset
378 fn dist2_squared<I: Instance<Self>>(&self, other: I) -> $field {
b53806de0be0 impl_euclidean with fixed field
Tuomo Valkonen <tuomov@iki.fi>
parents: 103
diff changeset
379 let Pair(u, v) = other.decompose();
b53806de0be0 impl_euclidean with fixed field
Tuomo Valkonen <tuomov@iki.fi>
parents: 103
diff changeset
380 self.0.dist2_squared(u) + self.1.dist2_squared(v)
b53806de0be0 impl_euclidean with fixed field
Tuomo Valkonen <tuomov@iki.fi>
parents: 103
diff changeset
381 }
b53806de0be0 impl_euclidean with fixed field
Tuomo Valkonen <tuomov@iki.fi>
parents: 103
diff changeset
382 }
b53806de0be0 impl_euclidean with fixed field
Tuomo Valkonen <tuomov@iki.fi>
parents: 103
diff changeset
383 };
57
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
384 }
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
385
114
b53806de0be0 impl_euclidean with fixed field
Tuomo Valkonen <tuomov@iki.fi>
parents: 103
diff changeset
386 impl_euclidean!(f32);
b53806de0be0 impl_euclidean with fixed field
Tuomo Valkonen <tuomov@iki.fi>
parents: 103
diff changeset
387 impl_euclidean!(f64);
b53806de0be0 impl_euclidean with fixed field
Tuomo Valkonen <tuomov@iki.fi>
parents: 103
diff changeset
388
57
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
389 impl<F, A, B, U, V> AXPY<F, Pair<U, V>> for Pair<A, B>
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
390 where
94
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
391 U: Space,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
392 V: Space,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
393 A: AXPY<F, U>,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
394 B: AXPY<F, V>,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
395 F: Num,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
396 Self: MulAssign<F>,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
397 Pair<A, B>: MulAssign<F>,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
398 Pair<A::Owned, B::Owned>: AXPY<F, Pair<U, V>>,
57
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
399 {
62
d8305c9b6fdf Move origin stuff to AXPY form Euclidean
Tuomo Valkonen <tuomov@iki.fi>
parents: 60
diff changeset
400 type Owned = Pair<A::Owned, B::Owned>;
d8305c9b6fdf Move origin stuff to AXPY form Euclidean
Tuomo Valkonen <tuomov@iki.fi>
parents: 60
diff changeset
401
94
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
402 fn axpy<I: Instance<Pair<U, V>>>(&mut self, α: F, x: I, β: F) {
59
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
403 let Pair(u, v) = x.decompose();
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
404 self.0.axpy(α, u, β);
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
405 self.1.axpy(α, v, β);
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
406 }
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
407
94
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
408 fn copy_from<I: Instance<Pair<U, V>>>(&mut self, x: I) {
59
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
409 let Pair(u, v) = x.decompose();
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
410 self.0.copy_from(u);
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
411 self.1.copy_from(v);
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
412 }
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
413
94
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
414 fn scale_from<I: Instance<Pair<U, V>>>(&mut self, α: F, x: I) {
59
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
415 let Pair(u, v) = x.decompose();
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
416 self.0.scale_from(α, u);
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
417 self.1.scale_from(α, v);
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
418 }
62
d8305c9b6fdf Move origin stuff to AXPY form Euclidean
Tuomo Valkonen <tuomov@iki.fi>
parents: 60
diff changeset
419
d8305c9b6fdf Move origin stuff to AXPY form Euclidean
Tuomo Valkonen <tuomov@iki.fi>
parents: 60
diff changeset
420 /// Return a similar zero as `self`.
d8305c9b6fdf Move origin stuff to AXPY form Euclidean
Tuomo Valkonen <tuomov@iki.fi>
parents: 60
diff changeset
421 fn similar_origin(&self) -> Self::Owned {
d8305c9b6fdf Move origin stuff to AXPY form Euclidean
Tuomo Valkonen <tuomov@iki.fi>
parents: 60
diff changeset
422 Pair(self.0.similar_origin(), self.1.similar_origin())
d8305c9b6fdf Move origin stuff to AXPY form Euclidean
Tuomo Valkonen <tuomov@iki.fi>
parents: 60
diff changeset
423 }
d8305c9b6fdf Move origin stuff to AXPY form Euclidean
Tuomo Valkonen <tuomov@iki.fi>
parents: 60
diff changeset
424
d8305c9b6fdf Move origin stuff to AXPY form Euclidean
Tuomo Valkonen <tuomov@iki.fi>
parents: 60
diff changeset
425 /// Set self to zero.
d8305c9b6fdf Move origin stuff to AXPY form Euclidean
Tuomo Valkonen <tuomov@iki.fi>
parents: 60
diff changeset
426 fn set_zero(&mut self) {
d8305c9b6fdf Move origin stuff to AXPY form Euclidean
Tuomo Valkonen <tuomov@iki.fi>
parents: 60
diff changeset
427 self.0.set_zero();
d8305c9b6fdf Move origin stuff to AXPY form Euclidean
Tuomo Valkonen <tuomov@iki.fi>
parents: 60
diff changeset
428 self.1.set_zero();
d8305c9b6fdf Move origin stuff to AXPY form Euclidean
Tuomo Valkonen <tuomov@iki.fi>
parents: 60
diff changeset
429 }
59
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
430 }
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
431
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
432 /// [`Decomposition`] for working with [`Pair`]s.
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
433 #[derive(Copy, Clone, Debug)]
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
434 pub struct PairDecomposition<D, Q>(D, Q);
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
435
94
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
436 impl<A: Space, B: Space> Space for Pair<A, B> {
59
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
437 type Decomp = PairDecomposition<A::Decomp, B::Decomp>;
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
438 }
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
439
94
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
440 impl<A, B, D, Q> Decomposition<Pair<A, B>> for PairDecomposition<D, Q>
59
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
441 where
94
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
442 A: Space,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
443 B: Space,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
444 D: Decomposition<A>,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
445 Q: Decomposition<B>,
59
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
446 {
94
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
447 type Decomposition<'b>
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
448 = Pair<D::Decomposition<'b>, Q::Decomposition<'b>>
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
449 where
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
450 Pair<A, B>: 'b;
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
451 type Reference<'b>
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
452 = Pair<D::Reference<'b>, Q::Reference<'b>>
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
453 where
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
454 Pair<A, B>: 'b;
59
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
455
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
456 #[inline]
94
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
457 fn lift<'b>(Pair(u, v): Self::Reference<'b>) -> Self::Decomposition<'b> {
59
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
458 Pair(D::lift(u), Q::lift(v))
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
459 }
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
460 }
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
461
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
462 impl<A, B, U, V, D, Q> Instance<Pair<A, B>, PairDecomposition<D, Q>> for Pair<U, V>
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
463 where
94
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
464 A: Space,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
465 B: Space,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
466 D: Decomposition<A>,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
467 Q: Decomposition<B>,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
468 U: Instance<A, D>,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
469 V: Instance<B, Q>,
59
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
470 {
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
471 #[inline]
94
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
472 fn decompose<'b>(
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
473 self,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
474 ) -> <PairDecomposition<D, Q> as Decomposition<Pair<A, B>>>::Decomposition<'b>
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
475 where
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
476 Self: 'b,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
477 Pair<A, B>: 'b,
59
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
478 {
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
479 Pair(self.0.decompose(), self.1.decompose())
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
480 }
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
481
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
482 #[inline]
94
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
483 fn ref_instance(
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
484 &self,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
485 ) -> <PairDecomposition<D, Q> as Decomposition<Pair<A, B>>>::Reference<'_> {
59
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
486 Pair(self.0.ref_instance(), self.1.ref_instance())
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
487 }
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
488
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
489 #[inline]
94
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
490 fn cow<'b>(self) -> MyCow<'b, Pair<A, B>>
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
491 where
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
492 Self: 'b,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
493 {
59
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
494 MyCow::Owned(Pair(self.0.own(), self.1.own()))
57
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
495 }
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
496
59
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
497 #[inline]
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
498 fn own(self) -> Pair<A, B> {
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
499 Pair(self.0.own(), self.1.own())
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
500 }
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
501 }
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
502
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
503 impl<'a, A, B, U, V, D, Q> Instance<Pair<A, B>, PairDecomposition<D, Q>> for &'a Pair<U, V>
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
504 where
94
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
505 A: Space,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
506 B: Space,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
507 D: Decomposition<A>,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
508 Q: Decomposition<B>,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
509 U: Instance<A, D>,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
510 V: Instance<B, Q>,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
511 &'a U: Instance<A, D>,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
512 &'a V: Instance<B, Q>,
59
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
513 {
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
514 #[inline]
94
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
515 fn decompose<'b>(
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
516 self,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
517 ) -> <PairDecomposition<D, Q> as Decomposition<Pair<A, B>>>::Decomposition<'b>
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
518 where
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
519 Self: 'b,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
520 Pair<A, B>: 'b,
59
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
521 {
94
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
522 Pair(
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
523 D::lift(self.0.ref_instance()),
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
524 Q::lift(self.1.ref_instance()),
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
525 )
59
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
526 }
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
527
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
528 #[inline]
94
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
529 fn ref_instance(
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
530 &self,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
531 ) -> <PairDecomposition<D, Q> as Decomposition<Pair<A, B>>>::Reference<'_> {
59
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
532 Pair(self.0.ref_instance(), self.1.ref_instance())
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
533 }
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
534
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
535 #[inline]
94
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
536 fn cow<'b>(self) -> MyCow<'b, Pair<A, B>>
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
537 where
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
538 Self: 'b,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
539 {
59
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
540 MyCow::Owned(self.own())
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
541 }
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
542
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
543 #[inline]
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
544 fn own(self) -> Pair<A, B> {
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
545 let Pair(ref u, ref v) = self;
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
546 Pair(u.own(), v.own())
57
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
547 }
59
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
548 }
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
549
94
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
550 impl<A, B, D, Q> DecompositionMut<Pair<A, B>> for PairDecomposition<D, Q>
59
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
551 where
94
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
552 A: Space,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
553 B: Space,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
554 D: DecompositionMut<A>,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
555 Q: DecompositionMut<B>,
59
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
556 {
94
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
557 type ReferenceMut<'b>
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
558 = Pair<D::ReferenceMut<'b>, Q::ReferenceMut<'b>>
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
559 where
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
560 Pair<A, B>: 'b;
59
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
561 }
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
562
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
563 impl<A, B, U, V, D, Q> InstanceMut<Pair<A, B>, PairDecomposition<D, Q>> for Pair<U, V>
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
564 where
94
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
565 A: Space,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
566 B: Space,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
567 D: DecompositionMut<A>,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
568 Q: DecompositionMut<B>,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
569 U: InstanceMut<A, D>,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
570 V: InstanceMut<B, Q>,
59
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
571 {
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
572 #[inline]
94
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
573 fn ref_instance_mut(
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
574 &mut self,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
575 ) -> <PairDecomposition<D, Q> as DecompositionMut<Pair<A, B>>>::ReferenceMut<'_> {
59
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
576 Pair(self.0.ref_instance_mut(), self.1.ref_instance_mut())
57
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
577 }
59
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
578 }
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
579
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
580 impl<'a, A, B, U, V, D, Q> InstanceMut<Pair<A, B>, PairDecomposition<D, Q>> for &'a mut Pair<U, V>
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
581 where
94
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
582 A: Space,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
583 B: Space,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
584 D: DecompositionMut<A>,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
585 Q: DecompositionMut<B>,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
586 U: InstanceMut<A, D>,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
587 V: InstanceMut<B, Q>,
59
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
588 {
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
589 #[inline]
94
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
590 fn ref_instance_mut(
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
591 &mut self,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
592 ) -> <PairDecomposition<D, Q> as DecompositionMut<Pair<A, B>>>::ReferenceMut<'_> {
59
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
593 Pair(self.0.ref_instance_mut(), self.1.ref_instance_mut())
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
594 }
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
595 }
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
596
94
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
597 impl<F, A, B, ExpA, ExpB, ExpJ> Norm<F, PairNorm<ExpA, ExpB, ExpJ>> for Pair<A, B>
59
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
598 where
94
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
599 F: Num,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
600 ExpA: NormExponent,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
601 ExpB: NormExponent,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
602 ExpJ: NormExponent,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
603 A: Norm<F, ExpA>,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
604 B: Norm<F, ExpB>,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
605 Loc<F, 2>: Norm<F, ExpJ>,
59
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
606 {
94
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
607 fn norm(&self, PairNorm(expa, expb, expj): PairNorm<ExpA, ExpB, ExpJ>) -> F {
59
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
608 Loc([self.0.norm(expa), self.1.norm(expb)]).norm(expj)
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
609 }
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
610 }
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
611
94
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
612 impl<F: Float, A, B> Normed<F> for Pair<A, B>
60
848ecc05becf More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 59
diff changeset
613 where
94
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
614 A: Normed<F>,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
615 B: Normed<F>,
60
848ecc05becf More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 59
diff changeset
616 {
848ecc05becf More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 59
diff changeset
617 type NormExp = PairNorm<A::NormExp, B::NormExp, L2>;
848ecc05becf More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 59
diff changeset
618
848ecc05becf More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 59
diff changeset
619 #[inline]
848ecc05becf More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 59
diff changeset
620 fn norm_exponent(&self) -> Self::NormExp {
848ecc05becf More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 59
diff changeset
621 PairNorm(self.0.norm_exponent(), self.1.norm_exponent(), L2)
848ecc05becf More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 59
diff changeset
622 }
848ecc05becf More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 59
diff changeset
623
848ecc05becf More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 59
diff changeset
624 #[inline]
848ecc05becf More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 59
diff changeset
625 fn is_zero(&self) -> bool {
848ecc05becf More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 59
diff changeset
626 self.0.is_zero() && self.1.is_zero()
848ecc05becf More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 59
diff changeset
627 }
848ecc05becf More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 59
diff changeset
628 }
848ecc05becf More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 59
diff changeset
629
94
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
630 impl<F: Float, A, B> HasDual<F> for Pair<A, B>
60
848ecc05becf More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 59
diff changeset
631 where
94
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
632 A: HasDual<F>,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
633 B: HasDual<F>,
60
848ecc05becf More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 59
diff changeset
634 {
848ecc05becf More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 59
diff changeset
635 type DualSpace = Pair<A::DualSpace, B::DualSpace>;
848ecc05becf More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 59
diff changeset
636 }

mercurial