src/direct_product.rs

Sun, 27 Apr 2025 20:29:43 -0500

author
Tuomo Valkonen <tuomov@iki.fi>
date
Sun, 27 Apr 2025 20:29:43 -0500
changeset 94
1f19c6bbf07b
parent 64
4f6ca107ccb1
permissions
-rw-r--r--

Fix build with stable rust.

For optimisations, build.rs now automatically sets a nightly cfg flag,
so problems with the nightly feature are avoided. It is still used for
required for additional nightly-only features.

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_binop {
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, $refl:ident, $refr:ident) => {
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
44 impl_binop!(@doit: $a, $b, $trait, $fn;
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
45 maybe_lifetime!($refl, &'l Pair<$a,$b>),
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
46 (maybe_lifetime!($refl, &'l $a),
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
47 maybe_lifetime!($refl, &'l $b));
57
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
48 maybe_lifetime!($refr, &'r Pair<Ai,Bi>),
59
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
49 (maybe_lifetime!($refr, &'r Ai),
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
50 maybe_lifetime!($refr, &'r Bi));
57
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
51 $refl, $refr);
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
52 };
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
53
59
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
54 (@doit: $a:ty, $b:ty,
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
55 $trait:ident, $fn:ident;
57
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
56 $self:ty, ($aself:ty, $bself:ty);
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
57 $in:ty, ($ain:ty, $bin:ty);
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
58 $refl:ident, $refr:ident) => {
59
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
59 impl<'l, 'r, Ai, Bi> $trait<$in>
57
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
60 for $self
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
61 where $aself: $trait<$ain>,
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
62 $bself: $trait<$bin> {
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
63 type Output = Pair<<$aself as $trait<$ain>>::Output,
59
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
64 <$bself as $trait<$bin>>::Output>;
57
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 #[inline]
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
67 fn $fn(self, y : $in) -> Self::Output {
59
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
68 Pair(maybe_ref!($refl, self.0).$fn(maybe_ref!($refr, y.0)),
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
69 maybe_ref!($refl, self.1).$fn(maybe_ref!($refr, y.1)))
57
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
70 }
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
71 }
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
72 };
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
73 }
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
74
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
75 macro_rules! impl_assignop {
59
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
76 (($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
77 impl_assignop!(@doit: $a, $b,
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
78 $trait, $fn;
57
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
79 maybe_lifetime!($refr, &'r Pair<Ai,Bi>),
59
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
80 (maybe_lifetime!($refr, &'r Ai),
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
81 maybe_lifetime!($refr, &'r Bi));
57
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
82 $refr);
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
83 };
59
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
84 (@doit: $a : ty, $b : ty,
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
85 $trait:ident, $fn:ident;
57
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
86 $in:ty, ($ain:ty, $bin:ty);
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
87 $refr:ident) => {
59
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
88 impl<'r, Ai, Bi> $trait<$in>
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
89 for Pair<$a,$b>
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
90 where $a: $trait<$ain>,
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
91 $b: $trait<$bin> {
57
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
92 #[inline]
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
93 fn $fn(&mut self, y : $in) -> () {
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
94 self.0.$fn(maybe_ref!($refr, y.0));
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
95 self.1.$fn(maybe_ref!($refr, y.1));
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
96 }
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
97 }
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
98 }
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
99 }
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
100
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
101 macro_rules! impl_scalarop {
59
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
102 (($a : ty, $b : ty), $field : ty, $trait : ident, $fn : ident, $refl:ident) => {
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
103 impl_scalarop!(@doit: $field,
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
104 $trait, $fn;
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
105 maybe_lifetime!($refl, &'l Pair<$a,$b>),
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
106 (maybe_lifetime!($refl, &'l $a),
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
107 maybe_lifetime!($refl, &'l $b));
57
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
108 $refl);
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
109 };
59
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
110 (@doit: $field : ty,
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
111 $trait:ident, $fn:ident;
57
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
112 $self:ty, ($aself:ty, $bself:ty);
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
113 $refl:ident) => {
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
114 // Scalar as Rhs
59
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
115 impl<'l> $trait<$field>
57
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
116 for $self
59
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
117 where $aself: $trait<$field>,
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
118 $bself: $trait<$field> {
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
119 type Output = Pair<<$aself as $trait<$field>>::Output,
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
120 <$bself as $trait<$field>>::Output>;
57
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
121 #[inline]
59
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
122 fn $fn(self, a : $field) -> Self::Output {
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
123 Pair(maybe_ref!($refl, self.0).$fn(a),
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
124 maybe_ref!($refl, self.1).$fn(a))
57
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 }
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
128 }
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
129
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
130 // Not used due to compiler overflow
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
131 #[allow(unused_macros)]
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
132 macro_rules! impl_scalarlhs_op {
59
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
133 (($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
134 impl_scalarlhs_op!(@doit: $trait, $fn,
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
135 maybe_lifetime!($refr, &'r Pair<$a,$b>),
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
136 (maybe_lifetime!($refr, &'r $a),
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
137 maybe_lifetime!($refr, &'r $b));
57
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
138 $refr, $field);
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
139 };
59
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
140 (@doit: $trait:ident, $fn:ident,
57
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
141 $in:ty, ($ain:ty, $bin:ty);
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
142 $refr:ident, $field:ty) => {
59
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
143 impl<'r> $trait<$in>
57
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
144 for $field
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
145 where $field : $trait<$ain>
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
146 + $trait<$bin> {
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
147 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
148 <$field as $trait<$bin>>::Output>;
57
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
149 #[inline]
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
150 fn $fn(self, x : $in) -> Self::Output {
59
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
151 Pair(self.$fn(maybe_ref!($refr, x.0)),
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
152 self.$fn(maybe_ref!($refr, x.1)))
57
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 };
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
156 }
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
157
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
158 macro_rules! impl_scalar_assignop {
59
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
159 (($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
160 impl<'r> $trait<$field> for Pair<$a, $b>
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
161 where
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
162 $a: $trait<$field>,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
163 $b: $trait<$field>,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
164 {
57
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
165 #[inline]
94
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
166 fn $fn(&mut self, a: $field) -> () {
57
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
167 self.0.$fn(a);
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
168 self.1.$fn(a);
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 }
94
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
171 };
57
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
172 }
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
173
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
174 macro_rules! impl_unaryop {
59
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
175 (($a : ty, $b : ty), $trait:ident, $fn:ident, $refl:ident) => {
57
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
176 impl_unaryop!(@doit: $trait, $fn;
59
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
177 maybe_lifetime!($refl, &'l Pair<$a,$b>),
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
178 (maybe_lifetime!($refl, &'l $a),
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
179 maybe_lifetime!($refl, &'l $b));
57
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
180 $refl);
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
181 };
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
182 (@doit: $trait:ident, $fn:ident;
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
183 $self:ty, ($aself:ty, $bself:ty);
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
184 $refl : ident) => {
59
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
185 impl<'l> $trait
57
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
186 for $self
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
187 where $aself: $trait,
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
188 $bself: $trait {
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
189 type Output = Pair<<$aself as $trait>::Output,
59
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
190 <$bself as $trait>::Output>;
57
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
191 #[inline]
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
192 fn $fn(self) -> Self::Output {
59
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
193 Pair(maybe_ref!($refl, self.0).$fn(),
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
194 maybe_ref!($refl, self.1).$fn())
57
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
195 }
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
196 }
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 }
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
199
59
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
200 #[macro_export]
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
201 macro_rules! impl_pair_vectorspace_ops {
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
202 (($a:ty, $b:ty), $field:ty) => {
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
203 impl_pair_vectorspace_ops!(@binary, ($a, $b), Add, add);
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
204 impl_pair_vectorspace_ops!(@binary, ($a, $b), Sub, sub);
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
205 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
206 impl_pair_vectorspace_ops!(@assign, ($a, $b), SubAssign, sub_assign);
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
207 impl_pair_vectorspace_ops!(@scalar, ($a, $b), $field, Mul, mul);
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
208 impl_pair_vectorspace_ops!(@scalar, ($a, $b), $field, Div, div);
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
209 // Compiler overflow
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
210 // $(
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
211 // 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
212 // )*
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
213 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
214 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
215 impl_pair_vectorspace_ops!(@unary, ($a, $b), Neg, neg);
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
216 };
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
217 (@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
218 impl_binop!(($a, $b), $trait, $fn, ref, ref);
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
219 impl_binop!(($a, $b), $trait, $fn, ref, noref);
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
220 impl_binop!(($a, $b), $trait, $fn, noref, ref);
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
221 impl_binop!(($a, $b), $trait, $fn, noref, noref);
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
222 };
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
223 (@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
224 impl_assignop!(($a, $b), $trait, $fn, ref);
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
225 impl_assignop!(($a, $b), $trait, $fn, noref);
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
226 };
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
227 (@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
228 impl_scalarop!(($a, $b), $field, $trait, $fn, ref);
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
229 impl_scalarop!(($a, $b), $field, $trait, $fn, noref);
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
230 };
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
231 (@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
232 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
233 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
234 };
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
235 (@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
236 impl_scalar_assignop!(($a, $b), $field, $trait, $fn);
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
237 };
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
238 (@unary, ($a : ty, $b : ty), $trait : ident, $fn : ident) => {
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
239 impl_unaryop!(($a, $b), $trait, $fn, ref);
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
240 impl_unaryop!(($a, $b), $trait, $fn, noref);
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
241 };
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
242 }
57
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
243
59
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
244 impl_pair_vectorspace_ops!((f32, f32), f32);
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
245 impl_pair_vectorspace_ops!((f64, f64), f64);
57
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
246
59
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
247 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
248
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
249 impl<A, B, F> Euclidean<F> for Pair<A, B>
57
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
250 where
94
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
251 A: Euclidean<F>,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
252 B: Euclidean<F>,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
253 F: Float,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
254 PairOutput<F, A, B>: Euclidean<F>,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
255 Self: Sized
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
256 + Mul<F, Output = PairOutput<F, A, B>>
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
257 + MulAssign<F>
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
258 + Div<F, Output = PairOutput<F, A, B>>
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
259 + DivAssign<F>
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
260 + Add<Self, Output = PairOutput<F, A, B>>
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
261 + Sub<Self, Output = PairOutput<F, A, B>>
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
262 + for<'b> Add<&'b Self, Output = PairOutput<F, A, B>>
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
263 + for<'b> Sub<&'b Self, Output = PairOutput<F, A, B>>
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
264 + AddAssign<Self>
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
265 + for<'b> AddAssign<&'b Self>
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
266 + SubAssign<Self>
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
267 + for<'b> SubAssign<&'b Self>
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
268 + Neg<Output = PairOutput<F, A, B>>,
57
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
269 {
59
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
270 type Output = PairOutput<F, A, B>;
57
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
271
94
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
272 fn dot<I: Instance<Self>>(&self, other: I) -> F {
63
f7b87d84864d Extra reflexivity and hilbert-like requirements for Euclidean. Fuse Dot into Euclidean.
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
273 let Pair(u, v) = other.decompose();
f7b87d84864d Extra reflexivity and hilbert-like requirements for Euclidean. Fuse Dot into Euclidean.
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
274 self.0.dot(u) + self.1.dot(v)
f7b87d84864d Extra reflexivity and hilbert-like requirements for Euclidean. Fuse Dot into Euclidean.
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
275 }
f7b87d84864d Extra reflexivity and hilbert-like requirements for Euclidean. Fuse Dot into Euclidean.
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
276
f7b87d84864d Extra reflexivity and hilbert-like requirements for Euclidean. Fuse Dot into Euclidean.
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
277 fn norm2_squared(&self) -> F {
f7b87d84864d Extra reflexivity and hilbert-like requirements for Euclidean. Fuse Dot into Euclidean.
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
278 self.0.norm2_squared() + self.1.norm2_squared()
f7b87d84864d Extra reflexivity and hilbert-like requirements for Euclidean. Fuse Dot into Euclidean.
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
279 }
f7b87d84864d Extra reflexivity and hilbert-like requirements for Euclidean. Fuse Dot into Euclidean.
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
280
94
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
281 fn dist2_squared<I: Instance<Self>>(&self, other: I) -> F {
64
4f6ca107ccb1 More Instance parametrisation
Tuomo Valkonen <tuomov@iki.fi>
parents: 63
diff changeset
282 let Pair(u, v) = other.decompose();
57
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
283 self.0.dist2_squared(u) + self.1.dist2_squared(v)
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
284 }
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
285 }
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
286
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
287 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
288 where
94
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
289 U: Space,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
290 V: Space,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
291 A: AXPY<F, U>,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
292 B: AXPY<F, V>,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
293 F: Num,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
294 Self: MulAssign<F>,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
295 Pair<A, B>: MulAssign<F>,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
296 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
297 {
62
d8305c9b6fdf Move origin stuff to AXPY form Euclidean
Tuomo Valkonen <tuomov@iki.fi>
parents: 60
diff changeset
298 type Owned = Pair<A::Owned, B::Owned>;
d8305c9b6fdf Move origin stuff to AXPY form Euclidean
Tuomo Valkonen <tuomov@iki.fi>
parents: 60
diff changeset
299
94
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
300 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
301 let Pair(u, v) = x.decompose();
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
302 self.0.axpy(α, u, β);
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
303 self.1.axpy(α, v, β);
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
304 }
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
305
94
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
306 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
307 let Pair(u, v) = x.decompose();
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
308 self.0.copy_from(u);
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
309 self.1.copy_from(v);
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
310 }
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
311
94
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
312 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
313 let Pair(u, v) = x.decompose();
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
314 self.0.scale_from(α, u);
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
315 self.1.scale_from(α, v);
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
316 }
62
d8305c9b6fdf Move origin stuff to AXPY form Euclidean
Tuomo Valkonen <tuomov@iki.fi>
parents: 60
diff changeset
317
d8305c9b6fdf Move origin stuff to AXPY form Euclidean
Tuomo Valkonen <tuomov@iki.fi>
parents: 60
diff changeset
318 /// Return a similar zero as `self`.
d8305c9b6fdf Move origin stuff to AXPY form Euclidean
Tuomo Valkonen <tuomov@iki.fi>
parents: 60
diff changeset
319 fn similar_origin(&self) -> Self::Owned {
d8305c9b6fdf Move origin stuff to AXPY form Euclidean
Tuomo Valkonen <tuomov@iki.fi>
parents: 60
diff changeset
320 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
321 }
d8305c9b6fdf Move origin stuff to AXPY form Euclidean
Tuomo Valkonen <tuomov@iki.fi>
parents: 60
diff changeset
322
d8305c9b6fdf Move origin stuff to AXPY form Euclidean
Tuomo Valkonen <tuomov@iki.fi>
parents: 60
diff changeset
323 /// Set self to zero.
d8305c9b6fdf Move origin stuff to AXPY form Euclidean
Tuomo Valkonen <tuomov@iki.fi>
parents: 60
diff changeset
324 fn set_zero(&mut self) {
d8305c9b6fdf Move origin stuff to AXPY form Euclidean
Tuomo Valkonen <tuomov@iki.fi>
parents: 60
diff changeset
325 self.0.set_zero();
d8305c9b6fdf Move origin stuff to AXPY form Euclidean
Tuomo Valkonen <tuomov@iki.fi>
parents: 60
diff changeset
326 self.1.set_zero();
d8305c9b6fdf Move origin stuff to AXPY form Euclidean
Tuomo Valkonen <tuomov@iki.fi>
parents: 60
diff changeset
327 }
59
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
328 }
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
329
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
330 /// [`Decomposition`] for working with [`Pair`]s.
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
331 #[derive(Copy, Clone, Debug)]
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
332 pub struct PairDecomposition<D, Q>(D, Q);
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
333
94
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
334 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
335 type Decomp = PairDecomposition<A::Decomp, B::Decomp>;
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
336 }
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
337
94
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
338 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
339 where
94
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
340 A: Space,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
341 B: Space,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
342 D: Decomposition<A>,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
343 Q: Decomposition<B>,
59
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
344 {
94
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
345 type Decomposition<'b>
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
346 = Pair<D::Decomposition<'b>, Q::Decomposition<'b>>
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
347 where
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
348 Pair<A, B>: 'b;
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
349 type Reference<'b>
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
350 = Pair<D::Reference<'b>, Q::Reference<'b>>
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
351 where
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
352 Pair<A, B>: 'b;
59
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
353
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
354 #[inline]
94
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
355 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
356 Pair(D::lift(u), Q::lift(v))
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
357 }
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
358 }
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
359
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
360 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
361 where
94
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
362 A: Space,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
363 B: Space,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
364 D: Decomposition<A>,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
365 Q: Decomposition<B>,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
366 U: Instance<A, D>,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
367 V: Instance<B, Q>,
59
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
368 {
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
369 #[inline]
94
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
370 fn decompose<'b>(
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
371 self,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
372 ) -> <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
373 where
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
374 Self: 'b,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
375 Pair<A, B>: 'b,
59
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
376 {
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
377 Pair(self.0.decompose(), self.1.decompose())
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
378 }
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
379
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
380 #[inline]
94
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
381 fn ref_instance(
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
382 &self,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
383 ) -> <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
384 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
385 }
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
386
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
387 #[inline]
94
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
388 fn cow<'b>(self) -> MyCow<'b, Pair<A, B>>
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
389 where
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
390 Self: 'b,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
391 {
59
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
392 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
393 }
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
394
59
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
395 #[inline]
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
396 fn own(self) -> Pair<A, B> {
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
397 Pair(self.0.own(), self.1.own())
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
398 }
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
399 }
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
400
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
401 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
402 where
94
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
403 A: Space,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
404 B: Space,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
405 D: Decomposition<A>,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
406 Q: Decomposition<B>,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
407 U: Instance<A, D>,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
408 V: Instance<B, Q>,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
409 &'a U: Instance<A, D>,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
410 &'a V: Instance<B, Q>,
59
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
411 {
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
412 #[inline]
94
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
413 fn decompose<'b>(
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
414 self,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
415 ) -> <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
416 where
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
417 Self: 'b,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
418 Pair<A, B>: 'b,
59
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
419 {
94
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
420 Pair(
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
421 D::lift(self.0.ref_instance()),
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
422 Q::lift(self.1.ref_instance()),
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
423 )
59
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
424 }
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
425
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
426 #[inline]
94
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
427 fn ref_instance(
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
428 &self,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
429 ) -> <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
430 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
431 }
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
432
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
433 #[inline]
94
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
434 fn cow<'b>(self) -> MyCow<'b, Pair<A, B>>
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
435 where
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
436 Self: 'b,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
437 {
59
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
438 MyCow::Owned(self.own())
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
439 }
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
440
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
441 #[inline]
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
442 fn own(self) -> Pair<A, B> {
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
443 let Pair(ref u, ref v) = self;
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
444 Pair(u.own(), v.own())
57
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
445 }
59
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
446 }
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
447
94
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
448 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
449 where
94
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
450 A: Space,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
451 B: Space,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
452 D: DecompositionMut<A>,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
453 Q: DecompositionMut<B>,
59
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
454 {
94
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
455 type ReferenceMut<'b>
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
456 = Pair<D::ReferenceMut<'b>, Q::ReferenceMut<'b>>
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
457 where
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
458 Pair<A, B>: 'b;
59
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 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
462 where
94
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
463 A: Space,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
464 B: Space,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
465 D: DecompositionMut<A>,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
466 Q: DecompositionMut<B>,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
467 U: InstanceMut<A, D>,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
468 V: InstanceMut<B, Q>,
59
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
469 {
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
470 #[inline]
94
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
471 fn ref_instance_mut(
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
472 &mut self,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
473 ) -> <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
474 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
475 }
59
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
476 }
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
477
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
478 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
479 where
94
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
480 A: Space,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
481 B: Space,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
482 D: DecompositionMut<A>,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
483 Q: DecompositionMut<B>,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
484 U: InstanceMut<A, D>,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
485 V: InstanceMut<B, Q>,
59
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
486 {
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
487 #[inline]
94
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
488 fn ref_instance_mut(
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
489 &mut self,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
490 ) -> <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
491 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
492 }
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
493 }
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
494
94
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
495 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
496 where
94
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
497 F: Num,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
498 ExpA: NormExponent,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
499 ExpB: NormExponent,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
500 ExpJ: NormExponent,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
501 A: Norm<F, ExpA>,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
502 B: Norm<F, ExpB>,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
503 Loc<F, 2>: Norm<F, ExpJ>,
59
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
504 {
94
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
505 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
506 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
507 }
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
508 }
9226980e45a7 Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents: 57
diff changeset
509
94
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
510 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
511 where
94
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
512 A: Normed<F>,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
513 B: Normed<F>,
60
848ecc05becf More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 59
diff changeset
514 {
848ecc05becf More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 59
diff changeset
515 type NormExp = PairNorm<A::NormExp, B::NormExp, L2>;
848ecc05becf More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 59
diff changeset
516
848ecc05becf More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 59
diff changeset
517 #[inline]
848ecc05becf More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 59
diff changeset
518 fn norm_exponent(&self) -> Self::NormExp {
848ecc05becf More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 59
diff changeset
519 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
520 }
848ecc05becf More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 59
diff changeset
521
848ecc05becf More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 59
diff changeset
522 #[inline]
848ecc05becf More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 59
diff changeset
523 fn is_zero(&self) -> bool {
848ecc05becf More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 59
diff changeset
524 self.0.is_zero() && self.1.is_zero()
848ecc05becf More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 59
diff changeset
525 }
848ecc05becf More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 59
diff changeset
526 }
848ecc05becf More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 59
diff changeset
527
94
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
528 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
529 where
94
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
530 A: HasDual<F>,
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 64
diff changeset
531 B: HasDual<F>,
60
848ecc05becf More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 59
diff changeset
532 {
848ecc05becf More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 59
diff changeset
533 type DualSpace = Pair<A::DualSpace, B::DualSpace>;
848ecc05becf More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 59
diff changeset
534 }

mercurial