| 63 base_fn: self, |
63 base_fn: self, |
| 64 } |
64 } |
| 65 } |
65 } |
| 66 } |
66 } |
| 67 |
67 |
| 68 /// Automatically implemented shorthand for referring to [`Mapping`]s from [`Loc<F, N>`] to `F`. |
68 /// Automatically implemented shorthand for referring to [`Mapping`]s from [`Loc<N, F>`] to `F`. |
| 69 pub trait RealMapping<F: Float, const N: usize>: Mapping<Loc<F, N>, Codomain = F> {} |
69 pub trait RealMapping<const N: usize, F: Float = f64>: Mapping<Loc<N, F>, Codomain = F> {} |
| 70 |
70 |
| 71 impl<F: Float, T, const N: usize> RealMapping<F, N> for T where T: Mapping<Loc<F, N>, Codomain = F> {} |
71 impl<F: Float, T, const N: usize> RealMapping<N, F> for T where T: Mapping<Loc<N, F>, Codomain = F> {} |
| 72 |
72 |
| 73 /// A helper trait alias for referring to [`Mapping`]s from [`Loc<F, N>`] to [`Loc<F, M>`]. |
73 /// A helper trait alias for referring to [`Mapping`]s from [`Loc<N, F>`] to [`Loc<M, F>`]. |
| 74 pub trait RealVectorField<F: Float, const N: usize, const M: usize>: |
74 pub trait RealVectorField<const N: usize, const M: usize, F: Float = f64>: |
| 75 Mapping<Loc<F, N>, Codomain = Loc<F, M>> |
75 Mapping<Loc<N, F>, Codomain = Loc<M, F>> |
| 76 { |
76 { |
| 77 } |
77 } |
| 78 |
78 |
| 79 impl<F: Float, T, const N: usize, const M: usize> RealVectorField<F, N, M> for T where |
79 impl<F: Float, T, const N: usize, const M: usize> RealVectorField<N, M, F> for T where |
| 80 T: Mapping<Loc<F, N>, Codomain = Loc<F, M>> |
80 T: Mapping<Loc<N, F>, Codomain = Loc<M, F>> |
| 81 { |
81 { |
| 82 } |
82 } |
| 83 |
83 |
| 84 /// A differentiable mapping from `Domain` to [`Mapping::Codomain`], with differentials |
84 /// A differentiable mapping from `Domain` to [`Mapping::Codomain`], with differentials |
| 85 /// `Differential`. |
85 /// `Differential`. |
| 100 /// Form the differential mapping of `self`. |
100 /// Form the differential mapping of `self`. |
| 101 fn diff_ref(&self) -> Self::Differential<'_>; |
101 fn diff_ref(&self) -> Self::Differential<'_>; |
| 102 } |
102 } |
| 103 |
103 |
| 104 /// Automatically implemented shorthand for referring to differentiable [`Mapping`]s from |
104 /// Automatically implemented shorthand for referring to differentiable [`Mapping`]s from |
| 105 /// [`Loc<F, N>`] to `F`. |
105 /// [`Loc<N, F>`] to `F`. |
| 106 pub trait DifferentiableRealMapping<F: Float, const N: usize>: |
106 pub trait DifferentiableRealMapping<const N: usize, F: Float>: |
| 107 DifferentiableMapping<Loc<F, N>, Codomain = F, DerivativeDomain = Loc<F, N>> |
107 DifferentiableMapping<Loc<N, F>, Codomain = F, DerivativeDomain = Loc<N, F>> |
| 108 { |
108 { |
| 109 } |
109 } |
| 110 |
110 |
| 111 impl<F: Float, T, const N: usize> DifferentiableRealMapping<F, N> for T where |
111 impl<F: Float, T, const N: usize> DifferentiableRealMapping<N, F> for T where |
| 112 T: DifferentiableMapping<Loc<F, N>, Codomain = F, DerivativeDomain = Loc<F, N>> |
112 T: DifferentiableMapping<Loc<N, F>, Codomain = F, DerivativeDomain = Loc<N, F>> |
| 113 { |
113 { |
| 114 } |
114 } |
| 115 |
115 |
| 116 /// Helper trait for implementing [`DifferentiableMapping`] |
116 /// Helper trait for implementing [`DifferentiableMapping`] |
| 117 pub trait DifferentiableImpl<X: Space>: Sized { |
117 pub trait DifferentiableImpl<X: Space>: Sized { |
| 184 } |
184 } |
| 185 |
185 |
| 186 impl<F: Space, X, G> Mapping<X> for FlattenedCodomain<X, F, G> |
186 impl<F: Space, X, G> Mapping<X> for FlattenedCodomain<X, F, G> |
| 187 where |
187 where |
| 188 X: Space, |
188 X: Space, |
| 189 G: Mapping<X, Codomain = Loc<F, 1>>, |
189 G: Mapping<X, Codomain = Loc<1, F>>, |
| 190 { |
190 { |
| 191 type Codomain = F; |
191 type Codomain = F; |
| 192 |
192 |
| 193 #[inline] |
193 #[inline] |
| 194 fn apply<I: Instance<X>>(&self, x: I) -> Self::Codomain { |
194 fn apply<I: Instance<X>>(&self, x: I) -> Self::Codomain { |
| 196 } |
196 } |
| 197 } |
197 } |
| 198 |
198 |
| 199 /// An auto-trait for constructing a [`FlattenCodomain`] structure for |
199 /// An auto-trait for constructing a [`FlattenCodomain`] structure for |
| 200 /// flattening the codomain of a [`Mapping`] from [`Loc`]`<F, 1>` to `F`. |
200 /// flattening the codomain of a [`Mapping`] from [`Loc`]`<F, 1>` to `F`. |
| 201 pub trait FlattenCodomain<X: Space, F>: Mapping<X, Codomain = Loc<F, 1>> + Sized { |
201 pub trait FlattenCodomain<X: Space, F>: Mapping<X, Codomain = Loc<1, F>> + Sized { |
| 202 /// Flatten the codomain from [`Loc`]`<F, 1>` to `F`. |
202 /// Flatten the codomain from [`Loc`]`<F, 1>` to `F`. |
| 203 fn flatten_codomain(self) -> FlattenedCodomain<X, F, Self> { |
203 fn flatten_codomain(self) -> FlattenedCodomain<X, F, Self> { |
| 204 FlattenedCodomain { |
204 FlattenedCodomain { |
| 205 g: self, |
205 g: self, |
| 206 _phantoms: PhantomData, |
206 _phantoms: PhantomData, |
| 207 } |
207 } |
| 208 } |
208 } |
| 209 } |
209 } |
| 210 |
210 |
| 211 impl<X: Space, F, G: Sized + Mapping<X, Codomain = Loc<F, 1>>> FlattenCodomain<X, F> for G {} |
211 impl<X: Space, F, G: Sized + Mapping<X, Codomain = Loc<1, F>>> FlattenCodomain<X, F> for G {} |
| 212 |
212 |
| 213 /// Container for dimensional slicing [`Loc`]`<F, N>` codomain of a [`Mapping`] to `F`. |
213 /// Container for dimensional slicing [`Loc`]`<N, F>` codomain of a [`Mapping`] to `F`. |
| 214 pub struct SlicedCodomain<'a, X, F, G: Clone, const N: usize> { |
214 pub struct SlicedCodomain<'a, X, F, G: Clone, const N: usize> { |
| 215 g: Cow<'a, G>, |
215 g: Cow<'a, G>, |
| 216 slice: usize, |
216 slice: usize, |
| 217 _phantoms: PhantomData<(X, F)>, |
217 _phantoms: PhantomData<(X, F)>, |
| 218 } |
218 } |
| 219 |
219 |
| 220 impl<'a, X, F, G, const N: usize> Mapping<X> for SlicedCodomain<'a, X, F, G, N> |
220 impl<'a, X, F, G, const N: usize> Mapping<X> for SlicedCodomain<'a, X, F, G, N> |
| 221 where |
221 where |
| 222 X: Space, |
222 X: Space, |
| 223 F: Copy + Space, |
223 F: Copy + Space, |
| 224 G: Mapping<X, Codomain = Loc<F, N>> + Clone, |
224 G: Mapping<X, Codomain = Loc<N, F>> + Clone, |
| 225 { |
225 { |
| 226 type Codomain = F; |
226 type Codomain = F; |
| 227 |
227 |
| 228 #[inline] |
228 #[inline] |
| 229 fn apply<I: Instance<X>>(&self, x: I) -> Self::Codomain { |
229 fn apply<I: Instance<X>>(&self, x: I) -> Self::Codomain { |
| 233 } |
233 } |
| 234 } |
234 } |
| 235 |
235 |
| 236 /// An auto-trait for constructing a [`FlattenCodomain`] structure for |
236 /// An auto-trait for constructing a [`FlattenCodomain`] structure for |
| 237 /// flattening the codomain of a [`Mapping`] from [`Loc`]`<F, 1>` to `F`. |
237 /// flattening the codomain of a [`Mapping`] from [`Loc`]`<F, 1>` to `F`. |
| 238 pub trait SliceCodomain<X: Space, F: Copy, const N: usize>: |
238 pub trait SliceCodomain<X: Space, const N: usize, F: Copy = f64>: |
| 239 Mapping<X, Codomain = Loc<F, N>> + Clone + Sized |
239 Mapping<X, Codomain = Loc<N, F>> + Clone + Sized |
| 240 { |
240 { |
| 241 /// Flatten the codomain from [`Loc`]`<F, 1>` to `F`. |
241 /// Flatten the codomain from [`Loc`]`<F, 1>` to `F`. |
| 242 fn slice_codomain(self, slice: usize) -> SlicedCodomain<'static, X, F, Self, N> { |
242 fn slice_codomain(self, slice: usize) -> SlicedCodomain<'static, X, F, Self, N> { |
| 243 assert!(slice < N); |
243 assert!(slice < N); |
| 244 SlicedCodomain { |
244 SlicedCodomain { |
| 257 _phantoms: PhantomData, |
257 _phantoms: PhantomData, |
| 258 } |
258 } |
| 259 } |
259 } |
| 260 } |
260 } |
| 261 |
261 |
| 262 impl<X: Space, F: Copy, G: Sized + Mapping<X, Codomain = Loc<F, N>> + Clone, const N: usize> |
262 impl<X: Space, F: Copy, G: Sized + Mapping<X, Codomain = Loc<N, F>> + Clone, const N: usize> |
| 263 SliceCodomain<X, F, N> for G |
263 SliceCodomain<X, N, F> for G |
| 264 { |
264 { |
| 265 } |
265 } |
| 266 |
266 |
| 267 /// The composition S ∘ T. `E` is for storing a `NormExponent` for the intermediate space. |
267 /// The composition S ∘ T. `E` is for storing a `NormExponent` for the intermediate space. |
| 268 pub struct Composition<S, T, E = ()> { |
268 pub struct Composition<S, T, E = ()> { |