Tue, 02 Sep 2025 15:18:30 -0500
Viewable hack not needed now
| 0 | 1 | /*! |
| 2 | Norms, projections, etc. | |
| 3 | */ | |
| 4 | ||
|
100
411c6be29fe5
Remove Send + Sync + 'static requirement on NormExponent. Allow Zed to reindent norms.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
72
diff
changeset
|
5 | use crate::euclidean::*; |
| 150 | 6 | use crate::instance::Ownable; |
| 151 | 7 | use crate::linops::{ClosedVectorSpace, VectorSpace}; |
|
100
411c6be29fe5
Remove Send + Sync + 'static requirement on NormExponent. Allow Zed to reindent norms.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
72
diff
changeset
|
8 | use crate::mapping::{Instance, Mapping, Space}; |
|
411c6be29fe5
Remove Send + Sync + 'static requirement on NormExponent. Allow Zed to reindent norms.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
72
diff
changeset
|
9 | use crate::types::*; |
| 106 | 10 | use serde::{Deserialize, Serialize}; |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
33
diff
changeset
|
11 | use std::marker::PhantomData; |
| 0 | 12 | |
| 13 | // | |
| 14 | // Abstract norms | |
| 15 | // | |
| 16 | ||
| 106 | 17 | #[derive(Copy, Clone, Debug, Serialize, Deserialize)] |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
33
diff
changeset
|
18 | /// Helper structure to convert a [`NormExponent`] into a [`Mapping`] |
|
100
411c6be29fe5
Remove Send + Sync + 'static requirement on NormExponent. Allow Zed to reindent norms.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
72
diff
changeset
|
19 | pub struct NormMapping<F: Float, E: NormExponent> { |
|
411c6be29fe5
Remove Send + Sync + 'static requirement on NormExponent. Allow Zed to reindent norms.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
72
diff
changeset
|
20 | pub(crate) exponent: E, |
|
411c6be29fe5
Remove Send + Sync + 'static requirement on NormExponent. Allow Zed to reindent norms.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
72
diff
changeset
|
21 | _phantoms: PhantomData<F>, |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
33
diff
changeset
|
22 | } |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
33
diff
changeset
|
23 | |
|
6
d80b87b8acd0
Added NormExponent trait for exponents of norms
Tuomo Valkonen <tuomov@iki.fi>
parents:
5
diff
changeset
|
24 | /// An exponent for norms. |
|
d80b87b8acd0
Added NormExponent trait for exponents of norms
Tuomo Valkonen <tuomov@iki.fi>
parents:
5
diff
changeset
|
25 | /// |
| 33 | 26 | // Just a collection of desirable attributes for a marker type |
|
100
411c6be29fe5
Remove Send + Sync + 'static requirement on NormExponent. Allow Zed to reindent norms.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
72
diff
changeset
|
27 | pub trait NormExponent: Copy { |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
33
diff
changeset
|
28 | /// Return the norm as a mappin |
|
100
411c6be29fe5
Remove Send + Sync + 'static requirement on NormExponent. Allow Zed to reindent norms.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
72
diff
changeset
|
29 | fn as_mapping<F: Float>(self) -> NormMapping<F, Self> { |
|
145
0b9aecd7bb76
Dist argument order changed to reflect other changes
Tuomo Valkonen <tuomov@iki.fi>
parents:
138
diff
changeset
|
30 | NormMapping { exponent: self, _phantoms: PhantomData } |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
33
diff
changeset
|
31 | } |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
33
diff
changeset
|
32 | } |
|
6
d80b87b8acd0
Added NormExponent trait for exponents of norms
Tuomo Valkonen <tuomov@iki.fi>
parents:
5
diff
changeset
|
33 | |
| 5 | 34 | /// Exponent type for the 1-[`Norm`]. |
|
100
411c6be29fe5
Remove Send + Sync + 'static requirement on NormExponent. Allow Zed to reindent norms.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
72
diff
changeset
|
35 | #[derive(Copy, Debug, Clone, Serialize, Eq, PartialEq)] |
| 0 | 36 | pub struct L1; |
|
6
d80b87b8acd0
Added NormExponent trait for exponents of norms
Tuomo Valkonen <tuomov@iki.fi>
parents:
5
diff
changeset
|
37 | impl NormExponent for L1 {} |
| 0 | 38 | |
| 5 | 39 | /// Exponent type for the 2-[`Norm`]. |
|
100
411c6be29fe5
Remove Send + Sync + 'static requirement on NormExponent. Allow Zed to reindent norms.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
72
diff
changeset
|
40 | #[derive(Copy, Debug, Clone, Serialize, Eq, PartialEq)] |
| 0 | 41 | pub struct L2; |
|
6
d80b87b8acd0
Added NormExponent trait for exponents of norms
Tuomo Valkonen <tuomov@iki.fi>
parents:
5
diff
changeset
|
42 | impl NormExponent for L2 {} |
| 0 | 43 | |
| 5 | 44 | /// Exponent type for the ∞-[`Norm`]. |
|
100
411c6be29fe5
Remove Send + Sync + 'static requirement on NormExponent. Allow Zed to reindent norms.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
72
diff
changeset
|
45 | #[derive(Copy, Debug, Clone, Serialize, Eq, PartialEq)] |
| 0 | 46 | pub struct Linfinity; |
|
6
d80b87b8acd0
Added NormExponent trait for exponents of norms
Tuomo Valkonen <tuomov@iki.fi>
parents:
5
diff
changeset
|
47 | impl NormExponent for Linfinity {} |
| 0 | 48 | |
| 5 | 49 | /// Exponent type for 2,1-[`Norm`]. |
| 50 | /// (1-norm over a domain Ω, 2-norm of a vector at each point of the domain.) | |
|
100
411c6be29fe5
Remove Send + Sync + 'static requirement on NormExponent. Allow Zed to reindent norms.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
72
diff
changeset
|
51 | #[derive(Copy, Debug, Clone, Serialize, Eq, PartialEq)] |
| 0 | 52 | pub struct L21; |
|
6
d80b87b8acd0
Added NormExponent trait for exponents of norms
Tuomo Valkonen <tuomov@iki.fi>
parents:
5
diff
changeset
|
53 | impl NormExponent for L21 {} |
| 0 | 54 | |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
33
diff
changeset
|
55 | /// Norms for pairs (a, b). ‖(a,b)‖ = ‖(‖a‖_A, ‖b‖_B)‖_J |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
33
diff
changeset
|
56 | /// For use with [`crate::direct_product::Pair`] |
|
100
411c6be29fe5
Remove Send + Sync + 'static requirement on NormExponent. Allow Zed to reindent norms.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
72
diff
changeset
|
57 | #[derive(Copy, Debug, Clone, Serialize, Eq, PartialEq)] |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
33
diff
changeset
|
58 | pub struct PairNorm<A, B, J>(pub A, pub B, pub J); |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
33
diff
changeset
|
59 | |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
33
diff
changeset
|
60 | impl<A, B, J> NormExponent for PairNorm<A, B, J> |
|
100
411c6be29fe5
Remove Send + Sync + 'static requirement on NormExponent. Allow Zed to reindent norms.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
72
diff
changeset
|
61 | where |
|
411c6be29fe5
Remove Send + Sync + 'static requirement on NormExponent. Allow Zed to reindent norms.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
72
diff
changeset
|
62 | A: NormExponent, |
|
411c6be29fe5
Remove Send + Sync + 'static requirement on NormExponent. Allow Zed to reindent norms.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
72
diff
changeset
|
63 | B: NormExponent, |
|
411c6be29fe5
Remove Send + Sync + 'static requirement on NormExponent. Allow Zed to reindent norms.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
72
diff
changeset
|
64 | J: NormExponent, |
|
411c6be29fe5
Remove Send + Sync + 'static requirement on NormExponent. Allow Zed to reindent norms.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
72
diff
changeset
|
65 | { |
|
411c6be29fe5
Remove Send + Sync + 'static requirement on NormExponent. Allow Zed to reindent norms.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
72
diff
changeset
|
66 | } |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
33
diff
changeset
|
67 | |
| 5 | 68 | /// A Huber/Moreau–Yosida smoothed [`L1`] norm. (Not a norm itself.) |
| 69 | /// | |
| 70 | /// The parameter γ of this type is the smoothing factor. Zero means no smoothing, and higher | |
| 71 | /// values more smoothing. Behaviour with γ < 0 is undefined. | |
|
100
411c6be29fe5
Remove Send + Sync + 'static requirement on NormExponent. Allow Zed to reindent norms.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
72
diff
changeset
|
72 | #[derive(Copy, Debug, Clone, Serialize, Eq, PartialEq)] |
|
411c6be29fe5
Remove Send + Sync + 'static requirement on NormExponent. Allow Zed to reindent norms.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
72
diff
changeset
|
73 | pub struct HuberL1<F: Float>(pub F); |
|
411c6be29fe5
Remove Send + Sync + 'static requirement on NormExponent. Allow Zed to reindent norms.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
72
diff
changeset
|
74 | impl<F: Float> NormExponent for HuberL1<F> {} |
| 0 | 75 | |
| 5 | 76 | /// A Huber/Moreau–Yosida smoothed [`L21`] norm. (Not a norm itself.) |
| 77 | /// | |
| 78 | /// The parameter γ of this type is the smoothing factor. Zero means no smoothing, and higher | |
| 79 | /// values more smoothing. Behaviour with γ < 0 is undefined. | |
|
100
411c6be29fe5
Remove Send + Sync + 'static requirement on NormExponent. Allow Zed to reindent norms.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
72
diff
changeset
|
80 | #[derive(Copy, Debug, Clone, Serialize, Eq, PartialEq)] |
|
411c6be29fe5
Remove Send + Sync + 'static requirement on NormExponent. Allow Zed to reindent norms.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
72
diff
changeset
|
81 | pub struct HuberL21<F: Float>(pub F); |
|
411c6be29fe5
Remove Send + Sync + 'static requirement on NormExponent. Allow Zed to reindent norms.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
72
diff
changeset
|
82 | impl<F: Float> NormExponent for HuberL21<F> {} |
| 0 | 83 | |
| 5 | 84 | /// A normed space (type) with exponent or other type `Exponent` for the norm. |
| 85 | /// | |
| 86 | /// Use as | |
| 87 | /// ``` | |
| 88 | /// # use alg_tools::norms::{Norm, L1, L2, Linfinity}; | |
| 89 | /// # use alg_tools::loc::Loc; | |
| 90 | /// let x = Loc([1.0, 2.0, 3.0]); | |
| 91 | /// | |
| 92 | /// println!("{}, {} {}", x.norm(L1), x.norm(L2), x.norm(Linfinity)) | |
| 93 | /// ``` | |
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
113
diff
changeset
|
94 | pub trait Norm<Exponent: NormExponent, F: Num = f64> { |
| 5 | 95 | /// Calculate the norm. |
|
100
411c6be29fe5
Remove Send + Sync + 'static requirement on NormExponent. Allow Zed to reindent norms.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
72
diff
changeset
|
96 | fn norm(&self, _p: Exponent) -> F; |
| 0 | 97 | } |
| 98 | ||
| 5 | 99 | /// Indicates that the `Self`-[`Norm`] is dominated by the `Exponent`-`Norm` on the space |
| 100 | /// `Elem` with the corresponding field `F`. | |
|
100
411c6be29fe5
Remove Send + Sync + 'static requirement on NormExponent. Allow Zed to reindent norms.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
72
diff
changeset
|
101 | pub trait Dominated<F: Num, Exponent: NormExponent, Elem> { |
| 0 | 102 | /// Indicates the factor $c$ for the inequality $‖x‖ ≤ C ‖x‖_p$. |
|
100
411c6be29fe5
Remove Send + Sync + 'static requirement on NormExponent. Allow Zed to reindent norms.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
72
diff
changeset
|
103 | fn norm_factor(&self, p: Exponent) -> F; |
| 0 | 104 | /// Given a norm-value $‖x‖_p$, calculates $C‖x‖_p$ such that $‖x‖ ≤ C‖x‖_p$ |
| 105 | #[inline] | |
|
100
411c6be29fe5
Remove Send + Sync + 'static requirement on NormExponent. Allow Zed to reindent norms.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
72
diff
changeset
|
106 | fn from_norm(&self, p_norm: F, p: Exponent) -> F { |
| 0 | 107 | p_norm * self.norm_factor(p) |
| 108 | } | |
| 109 | } | |
| 110 | ||
| 5 | 111 | /// Trait for distances with respect to a norm. |
|
145
0b9aecd7bb76
Dist argument order changed to reflect other changes
Tuomo Valkonen <tuomov@iki.fi>
parents:
138
diff
changeset
|
112 | pub trait Dist<Exponent: NormExponent, F: Num = f64>: Norm<Exponent, F> + Space { |
| 0 | 113 | /// Calculate the distance |
|
100
411c6be29fe5
Remove Send + Sync + 'static requirement on NormExponent. Allow Zed to reindent norms.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
72
diff
changeset
|
114 | fn dist<I: Instance<Self>>(&self, other: I, _p: Exponent) -> F; |
| 0 | 115 | } |
| 116 | ||
| 5 | 117 | /// Trait for Euclidean projections to the `Exponent`-[`Norm`]-ball. |
| 118 | /// | |
| 119 | /// Use as | |
| 120 | /// ``` | |
| 121 | /// # use alg_tools::norms::{Projection, L2, Linfinity}; | |
| 122 | /// # use alg_tools::loc::Loc; | |
| 123 | /// let x = Loc([1.0, 2.0, 3.0]); | |
| 124 | /// | |
| 125 | /// println!("{:?}, {:?}", x.proj_ball(1.0, L2), x.proj_ball(0.5, Linfinity)); | |
| 126 | /// ``` | |
| 150 | 127 | pub trait Projection<F: Num, Exponent: NormExponent>: Ownable + Norm<Exponent, F> { |
| 5 | 128 | /// Projection of `self` to the `q`-norm-ball of radius ρ. |
| 150 | 129 | fn proj_ball(self, ρ: F, q: Exponent) -> Self::OwnedVariant; |
| 130 | } | |
| 0 | 131 | |
| 150 | 132 | pub trait ProjectionMut<F: Num, Exponent: NormExponent>: Projection<F, Exponent> { |
| 5 | 133 | /// In-place projection of `self` to the `q`-norm-ball of radius ρ. |
|
100
411c6be29fe5
Remove Send + Sync + 'static requirement on NormExponent. Allow Zed to reindent norms.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
72
diff
changeset
|
134 | fn proj_ball_mut(&mut self, ρ: F, q: Exponent); |
| 0 | 135 | } |
| 136 | ||
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
113
diff
changeset
|
137 | /*impl<F : Float, E : Euclidean<F>> Norm<L2, F> for E { |
| 0 | 138 | #[inline] |
| 139 | fn norm(&self, _p : L2) -> F { self.norm2() } | |
| 140 | ||
| 141 | fn dist(&self, other : &Self, _p : L2) -> F { self.dist2(other) } | |
| 142 | }*/ | |
| 143 | ||
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
113
diff
changeset
|
144 | impl<F: Float, E: Euclidean<F> + Norm<L2, F>> Projection<F, L2> for E { |
| 0 | 145 | #[inline] |
| 150 | 146 | fn proj_ball(self, ρ: F, _p: L2) -> Self::OwnedVariant { |
|
100
411c6be29fe5
Remove Send + Sync + 'static requirement on NormExponent. Allow Zed to reindent norms.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
72
diff
changeset
|
147 | self.proj_ball2(ρ) |
|
411c6be29fe5
Remove Send + Sync + 'static requirement on NormExponent. Allow Zed to reindent norms.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
72
diff
changeset
|
148 | } |
| 150 | 149 | } |
| 0 | 150 | |
| 150 | 151 | impl<F: Float, E: EuclideanMut<F> + Norm<L2, F>> ProjectionMut<F, L2> for E { |
| 0 | 152 | #[inline] |
|
100
411c6be29fe5
Remove Send + Sync + 'static requirement on NormExponent. Allow Zed to reindent norms.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
72
diff
changeset
|
153 | fn proj_ball_mut(&mut self, ρ: F, _p: L2) { |
|
411c6be29fe5
Remove Send + Sync + 'static requirement on NormExponent. Allow Zed to reindent norms.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
72
diff
changeset
|
154 | self.proj_ball2_mut(ρ) |
|
411c6be29fe5
Remove Send + Sync + 'static requirement on NormExponent. Allow Zed to reindent norms.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
72
diff
changeset
|
155 | } |
| 0 | 156 | } |
| 157 | ||
|
100
411c6be29fe5
Remove Send + Sync + 'static requirement on NormExponent. Allow Zed to reindent norms.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
72
diff
changeset
|
158 | impl<F: Float> HuberL1<F> { |
|
411c6be29fe5
Remove Send + Sync + 'static requirement on NormExponent. Allow Zed to reindent norms.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
72
diff
changeset
|
159 | fn apply(self, xnsq: F) -> F { |
| 0 | 160 | let HuberL1(γ) = self; |
| 161 | let xn = xnsq.sqrt(); | |
| 162 | if γ == F::ZERO { | |
| 163 | xn | |
| 164 | } else { | |
| 165 | if xn > γ { | |
|
100
411c6be29fe5
Remove Send + Sync + 'static requirement on NormExponent. Allow Zed to reindent norms.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
72
diff
changeset
|
166 | xn - γ / F::TWO |
|
411c6be29fe5
Remove Send + Sync + 'static requirement on NormExponent. Allow Zed to reindent norms.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
72
diff
changeset
|
167 | } else if xn < (-γ) { |
|
411c6be29fe5
Remove Send + Sync + 'static requirement on NormExponent. Allow Zed to reindent norms.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
72
diff
changeset
|
168 | -xn - γ / F::TWO |
| 0 | 169 | } else { |
| 5 | 170 | xnsq / (F::TWO * γ) |
| 0 | 171 | } |
| 172 | } | |
| 173 | } | |
| 174 | } | |
| 175 | ||
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
113
diff
changeset
|
176 | impl<F: Float, E: Euclidean<F> + Normed<F, NormExp = L2>> Norm<HuberL1<F>, F> for E { |
|
100
411c6be29fe5
Remove Send + Sync + 'static requirement on NormExponent. Allow Zed to reindent norms.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
72
diff
changeset
|
177 | fn norm(&self, huber: HuberL1<F>) -> F { |
| 0 | 178 | huber.apply(self.norm2_squared()) |
| 179 | } | |
| 180 | } | |
| 181 | ||
|
145
0b9aecd7bb76
Dist argument order changed to reflect other changes
Tuomo Valkonen <tuomov@iki.fi>
parents:
138
diff
changeset
|
182 | impl<F: Float, E: Euclidean<F> + Normed<F, NormExp = L2>> Dist<HuberL1<F>, F> for E { |
|
100
411c6be29fe5
Remove Send + Sync + 'static requirement on NormExponent. Allow Zed to reindent norms.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
72
diff
changeset
|
183 | fn dist<I: Instance<Self>>(&self, other: I, huber: HuberL1<F>) -> F { |
| 0 | 184 | huber.apply(self.dist2_squared(other)) |
| 185 | } | |
| 186 | } | |
| 187 | ||
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
113
diff
changeset
|
188 | // impl<F : Float, E : Norm<L2, F>> Norm<L21, F> for Vec<E> { |
|
64
4f6ca107ccb1
More Instance parametrisation
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
189 | // fn norm(&self, _l21 : L21) -> F { |
|
4f6ca107ccb1
More Instance parametrisation
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
190 | // self.iter().map(|e| e.norm(L2)).sum() |
|
4f6ca107ccb1
More Instance parametrisation
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
191 | // } |
|
4f6ca107ccb1
More Instance parametrisation
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
192 | // } |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
33
diff
changeset
|
193 | |
|
145
0b9aecd7bb76
Dist argument order changed to reflect other changes
Tuomo Valkonen <tuomov@iki.fi>
parents:
138
diff
changeset
|
194 | // impl<F : Float, E : Dist<F, L2>> Dist<L21, F> for Vec<E> { |
|
64
4f6ca107ccb1
More Instance parametrisation
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
195 | // fn dist<I : Instance<Self>>(&self, other : I, _l21 : L21) -> F { |
|
4f6ca107ccb1
More Instance parametrisation
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
196 | // self.iter().zip(other.iter()).map(|(e, g)| e.dist(g, L2)).sum() |
|
4f6ca107ccb1
More Instance parametrisation
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
197 | // } |
|
4f6ca107ccb1
More Instance parametrisation
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
198 | // } |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
33
diff
changeset
|
199 | |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
33
diff
changeset
|
200 | impl<E, F, Domain> Mapping<Domain> for NormMapping<F, E> |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
33
diff
changeset
|
201 | where |
|
100
411c6be29fe5
Remove Send + Sync + 'static requirement on NormExponent. Allow Zed to reindent norms.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
72
diff
changeset
|
202 | F: Float, |
|
411c6be29fe5
Remove Send + Sync + 'static requirement on NormExponent. Allow Zed to reindent norms.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
72
diff
changeset
|
203 | E: NormExponent, |
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
113
diff
changeset
|
204 | Domain: Space + Norm<E, F>, |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
33
diff
changeset
|
205 | { |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
33
diff
changeset
|
206 | type Codomain = F; |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
33
diff
changeset
|
207 | |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
33
diff
changeset
|
208 | #[inline] |
|
100
411c6be29fe5
Remove Send + Sync + 'static requirement on NormExponent. Allow Zed to reindent norms.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
72
diff
changeset
|
209 | fn apply<I: Instance<Domain>>(&self, x: I) -> F { |
|
59
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
33
diff
changeset
|
210 | x.eval(|r| r.norm(self.exponent)) |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
33
diff
changeset
|
211 | } |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
33
diff
changeset
|
212 | } |
|
9226980e45a7
Significantly simplify Mapping / Apply through Instance
Tuomo Valkonen <tuomov@iki.fi>
parents:
33
diff
changeset
|
213 | |
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
113
diff
changeset
|
214 | pub trait Normed<F: Num = f64>: Space + Norm<Self::NormExp, F> { |
|
100
411c6be29fe5
Remove Send + Sync + 'static requirement on NormExponent. Allow Zed to reindent norms.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
72
diff
changeset
|
215 | type NormExp: NormExponent; |
|
60
848ecc05becf
More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
59
diff
changeset
|
216 | |
|
848ecc05becf
More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
59
diff
changeset
|
217 | fn norm_exponent(&self) -> Self::NormExp; |
|
848ecc05becf
More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
59
diff
changeset
|
218 | |
|
848ecc05becf
More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
59
diff
changeset
|
219 | #[inline] |
|
848ecc05becf
More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
59
diff
changeset
|
220 | fn norm_(&self) -> F { |
|
848ecc05becf
More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
59
diff
changeset
|
221 | self.norm(self.norm_exponent()) |
|
848ecc05becf
More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
59
diff
changeset
|
222 | } |
|
848ecc05becf
More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
59
diff
changeset
|
223 | |
|
848ecc05becf
More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
59
diff
changeset
|
224 | // fn similar_origin(&self) -> Self; |
|
848ecc05becf
More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
59
diff
changeset
|
225 | |
| 113 | 226 | fn is_zero(&self) -> bool { |
| 227 | self.norm_() == F::ZERO | |
| 228 | } | |
|
60
848ecc05becf
More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
59
diff
changeset
|
229 | } |
|
848ecc05becf
More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
59
diff
changeset
|
230 | |
| 150 | 231 | pub trait HasDual<F: Num = f64>: Normed<F> + VectorSpace<Field = F> { |
| 151 | 232 | type DualSpace: Normed<F> + ClosedVectorSpace<Field = F>; |
| 138 | 233 | |
| 150 | 234 | fn dual_origin(&self) -> <Self::DualSpace as VectorSpace>::Owned; |
|
60
848ecc05becf
More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
59
diff
changeset
|
235 | } |
|
848ecc05becf
More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
59
diff
changeset
|
236 | |
|
63
f7b87d84864d
Extra reflexivity and hilbert-like requirements for Euclidean. Fuse Dot into Euclidean.
Tuomo Valkonen <tuomov@iki.fi>
parents:
60
diff
changeset
|
237 | /// Automatically implemented trait for reflexive spaces |
|
100
411c6be29fe5
Remove Send + Sync + 'static requirement on NormExponent. Allow Zed to reindent norms.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
72
diff
changeset
|
238 | pub trait Reflexive<F: Num = f64>: HasDual<F> |
|
60
848ecc05becf
More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
59
diff
changeset
|
239 | where |
| 151 | 240 | Self::DualSpace: HasDual<F, DualSpace = Self::OwnedSpace>, |
|
100
411c6be29fe5
Remove Send + Sync + 'static requirement on NormExponent. Allow Zed to reindent norms.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
72
diff
changeset
|
241 | { |
|
411c6be29fe5
Remove Send + Sync + 'static requirement on NormExponent. Allow Zed to reindent norms.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
72
diff
changeset
|
242 | } |
|
60
848ecc05becf
More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
59
diff
changeset
|
243 | |
| 151 | 244 | impl<F: Num, X: HasDual<F>> Reflexive<F> for X where |
| 245 | X::DualSpace: HasDual<F, DualSpace = Self::OwnedSpace> | |
| 246 | { | |
| 247 | } | |
|
60
848ecc05becf
More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
59
diff
changeset
|
248 | |
|
100
411c6be29fe5
Remove Send + Sync + 'static requirement on NormExponent. Allow Zed to reindent norms.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
72
diff
changeset
|
249 | pub trait HasDualExponent: NormExponent { |
|
411c6be29fe5
Remove Send + Sync + 'static requirement on NormExponent. Allow Zed to reindent norms.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
72
diff
changeset
|
250 | type DualExp: NormExponent; |
|
60
848ecc05becf
More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
59
diff
changeset
|
251 | |
|
848ecc05becf
More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
59
diff
changeset
|
252 | fn dual_exponent(&self) -> Self::DualExp; |
|
848ecc05becf
More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
59
diff
changeset
|
253 | } |
|
848ecc05becf
More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
59
diff
changeset
|
254 | |
|
848ecc05becf
More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
59
diff
changeset
|
255 | impl HasDualExponent for L2 { |
|
848ecc05becf
More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
59
diff
changeset
|
256 | type DualExp = L2; |
|
100
411c6be29fe5
Remove Send + Sync + 'static requirement on NormExponent. Allow Zed to reindent norms.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
72
diff
changeset
|
257 | |
|
60
848ecc05becf
More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
59
diff
changeset
|
258 | #[inline] |
|
848ecc05becf
More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
59
diff
changeset
|
259 | fn dual_exponent(&self) -> Self::DualExp { |
|
848ecc05becf
More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
59
diff
changeset
|
260 | L2 |
|
848ecc05becf
More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
59
diff
changeset
|
261 | } |
|
848ecc05becf
More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
59
diff
changeset
|
262 | } |
|
848ecc05becf
More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
59
diff
changeset
|
263 | |
|
848ecc05becf
More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
59
diff
changeset
|
264 | impl HasDualExponent for L1 { |
|
848ecc05becf
More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
59
diff
changeset
|
265 | type DualExp = Linfinity; |
|
100
411c6be29fe5
Remove Send + Sync + 'static requirement on NormExponent. Allow Zed to reindent norms.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
72
diff
changeset
|
266 | |
|
60
848ecc05becf
More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
59
diff
changeset
|
267 | #[inline] |
|
848ecc05becf
More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
59
diff
changeset
|
268 | fn dual_exponent(&self) -> Self::DualExp { |
|
848ecc05becf
More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
59
diff
changeset
|
269 | Linfinity |
|
848ecc05becf
More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
59
diff
changeset
|
270 | } |
|
848ecc05becf
More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
59
diff
changeset
|
271 | } |
|
848ecc05becf
More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
59
diff
changeset
|
272 | |
|
848ecc05becf
More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
59
diff
changeset
|
273 | impl HasDualExponent for Linfinity { |
|
848ecc05becf
More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
59
diff
changeset
|
274 | type DualExp = L1; |
|
100
411c6be29fe5
Remove Send + Sync + 'static requirement on NormExponent. Allow Zed to reindent norms.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
72
diff
changeset
|
275 | |
|
60
848ecc05becf
More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
59
diff
changeset
|
276 | #[inline] |
|
848ecc05becf
More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
59
diff
changeset
|
277 | fn dual_exponent(&self) -> Self::DualExp { |
|
848ecc05becf
More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
59
diff
changeset
|
278 | L1 |
|
848ecc05becf
More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
59
diff
changeset
|
279 | } |
|
848ecc05becf
More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
59
diff
changeset
|
280 | } |
|
848ecc05becf
More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
59
diff
changeset
|
281 | |
|
71
511bf440e24b
Need to construct weighted norms using macros due to compiler (overflow) bugs
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
282 | #[macro_export] |
|
511bf440e24b
Need to construct weighted norms using macros due to compiler (overflow) bugs
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
283 | macro_rules! impl_weighted_norm { |
|
511bf440e24b
Need to construct weighted norms using macros due to compiler (overflow) bugs
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
284 | ($exponent : ty) => { |
|
511bf440e24b
Need to construct weighted norms using macros due to compiler (overflow) bugs
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
285 | impl<C, F, D> Norm<F, Weighted<$exponent, C>> for D |
|
511bf440e24b
Need to construct weighted norms using macros due to compiler (overflow) bugs
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
286 | where |
|
100
411c6be29fe5
Remove Send + Sync + 'static requirement on NormExponent. Allow Zed to reindent norms.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
72
diff
changeset
|
287 | F: Float, |
|
124
6aa955ad8122
Transpose loc parameters to allow f64 defaults
Tuomo Valkonen <tuomov@iki.fi>
parents:
113
diff
changeset
|
288 | D: Norm<$exponent, F>, |
|
100
411c6be29fe5
Remove Send + Sync + 'static requirement on NormExponent. Allow Zed to reindent norms.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
72
diff
changeset
|
289 | C: Constant<Type = F>, |
|
71
511bf440e24b
Need to construct weighted norms using macros due to compiler (overflow) bugs
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
290 | { |
|
100
411c6be29fe5
Remove Send + Sync + 'static requirement on NormExponent. Allow Zed to reindent norms.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
72
diff
changeset
|
291 | fn norm(&self, e: Weighted<$exponent, C>) -> F { |
|
71
511bf440e24b
Need to construct weighted norms using macros due to compiler (overflow) bugs
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
292 | let v = e.weight.value(); |
|
511bf440e24b
Need to construct weighted norms using macros due to compiler (overflow) bugs
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
293 | assert!(v > F::ZERO); |
|
511bf440e24b
Need to construct weighted norms using macros due to compiler (overflow) bugs
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
294 | v * self.norm(e.base_fn) |
|
511bf440e24b
Need to construct weighted norms using macros due to compiler (overflow) bugs
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
295 | } |
|
511bf440e24b
Need to construct weighted norms using macros due to compiler (overflow) bugs
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
296 | } |
|
511bf440e24b
Need to construct weighted norms using macros due to compiler (overflow) bugs
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
297 | |
|
100
411c6be29fe5
Remove Send + Sync + 'static requirement on NormExponent. Allow Zed to reindent norms.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
72
diff
changeset
|
298 | impl<C: Constant> NormExponent for Weighted<$exponent, C> {} |
|
71
511bf440e24b
Need to construct weighted norms using macros due to compiler (overflow) bugs
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
299 | |
|
100
411c6be29fe5
Remove Send + Sync + 'static requirement on NormExponent. Allow Zed to reindent norms.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
72
diff
changeset
|
300 | impl<C: Constant> HasDualExponent for Weighted<$exponent, C> |
|
411c6be29fe5
Remove Send + Sync + 'static requirement on NormExponent. Allow Zed to reindent norms.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
72
diff
changeset
|
301 | where |
|
411c6be29fe5
Remove Send + Sync + 'static requirement on NormExponent. Allow Zed to reindent norms.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
72
diff
changeset
|
302 | $exponent: HasDualExponent, |
|
411c6be29fe5
Remove Send + Sync + 'static requirement on NormExponent. Allow Zed to reindent norms.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
72
diff
changeset
|
303 | { |
|
71
511bf440e24b
Need to construct weighted norms using macros due to compiler (overflow) bugs
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
304 | type DualExp = Weighted<<$exponent as HasDualExponent>::DualExp, C::Type>; |
|
60
848ecc05becf
More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
59
diff
changeset
|
305 | |
|
71
511bf440e24b
Need to construct weighted norms using macros due to compiler (overflow) bugs
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
306 | fn dual_exponent(&self) -> Self::DualExp { |
|
511bf440e24b
Need to construct weighted norms using macros due to compiler (overflow) bugs
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
307 | Weighted { |
|
100
411c6be29fe5
Remove Send + Sync + 'static requirement on NormExponent. Allow Zed to reindent norms.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
72
diff
changeset
|
308 | weight: C::Type::ONE / self.weight.value(), |
|
411c6be29fe5
Remove Send + Sync + 'static requirement on NormExponent. Allow Zed to reindent norms.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
72
diff
changeset
|
309 | base_fn: self.base_fn.dual_exponent(), |
|
71
511bf440e24b
Need to construct weighted norms using macros due to compiler (overflow) bugs
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
310 | } |
|
511bf440e24b
Need to construct weighted norms using macros due to compiler (overflow) bugs
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
311 | } |
|
511bf440e24b
Need to construct weighted norms using macros due to compiler (overflow) bugs
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
312 | } |
|
511bf440e24b
Need to construct weighted norms using macros due to compiler (overflow) bugs
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
313 | |
|
100
411c6be29fe5
Remove Send + Sync + 'static requirement on NormExponent. Allow Zed to reindent norms.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
72
diff
changeset
|
314 | impl<C, F, T> Projection<F, Weighted<$exponent, C>> for T |
|
71
511bf440e24b
Need to construct weighted norms using macros due to compiler (overflow) bugs
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
315 | where |
|
100
411c6be29fe5
Remove Send + Sync + 'static requirement on NormExponent. Allow Zed to reindent norms.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
72
diff
changeset
|
316 | T: Projection<F, $exponent>, |
|
411c6be29fe5
Remove Send + Sync + 'static requirement on NormExponent. Allow Zed to reindent norms.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
72
diff
changeset
|
317 | F: Float, |
|
411c6be29fe5
Remove Send + Sync + 'static requirement on NormExponent. Allow Zed to reindent norms.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
72
diff
changeset
|
318 | C: Constant<Type = F>, |
|
71
511bf440e24b
Need to construct weighted norms using macros due to compiler (overflow) bugs
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
319 | { |
|
100
411c6be29fe5
Remove Send + Sync + 'static requirement on NormExponent. Allow Zed to reindent norms.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
72
diff
changeset
|
320 | fn proj_ball(self, ρ: F, q: Weighted<$exponent, C>) -> Self { |
|
71
511bf440e24b
Need to construct weighted norms using macros due to compiler (overflow) bugs
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
321 | self.proj_ball(ρ / q.weight.value(), q.base_fn) |
|
511bf440e24b
Need to construct weighted norms using macros due to compiler (overflow) bugs
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
322 | } |
|
511bf440e24b
Need to construct weighted norms using macros due to compiler (overflow) bugs
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
323 | |
|
100
411c6be29fe5
Remove Send + Sync + 'static requirement on NormExponent. Allow Zed to reindent norms.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
72
diff
changeset
|
324 | fn proj_ball_mut(&mut self, ρ: F, q: Weighted<$exponent, C>) { |
|
71
511bf440e24b
Need to construct weighted norms using macros due to compiler (overflow) bugs
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
325 | self.proj_ball_mut(ρ / q.weight.value(), q.base_fn) |
|
511bf440e24b
Need to construct weighted norms using macros due to compiler (overflow) bugs
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
326 | } |
| 70 | 327 | } |
|
100
411c6be29fe5
Remove Send + Sync + 'static requirement on NormExponent. Allow Zed to reindent norms.rs.
Tuomo Valkonen <tuomov@iki.fi>
parents:
72
diff
changeset
|
328 | }; |
| 70 | 329 | } |
|
60
848ecc05becf
More convexity, normed spaces, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
59
diff
changeset
|
330 | |
|
71
511bf440e24b
Need to construct weighted norms using macros due to compiler (overflow) bugs
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
331 | //impl_weighted_norm!(L1); |
|
511bf440e24b
Need to construct weighted norms using macros due to compiler (overflow) bugs
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
332 | //impl_weighted_norm!(L2); |
|
511bf440e24b
Need to construct weighted norms using macros due to compiler (overflow) bugs
Tuomo Valkonen <tuomov@iki.fi>
parents:
70
diff
changeset
|
333 | //impl_weighted_norm!(Linfinity); |