src/mapping.rs

branch
dev
changeset 105
103aa137fcb2
parent 102
aead46a19767
child 110
a1278320be26
equal deleted inserted replaced
104:e7f1cb4bec78 105:103aa137fcb2
7 use crate::norms::{Norm, NormExponent}; 7 use crate::norms::{Norm, NormExponent};
8 use crate::operator_arithmetic::{Constant, Weighted}; 8 use crate::operator_arithmetic::{Constant, Weighted};
9 use crate::types::{ClosedMul, Float, Num}; 9 use crate::types::{ClosedMul, Float, Num};
10 use std::borrow::Cow; 10 use std::borrow::Cow;
11 use std::marker::PhantomData; 11 use std::marker::PhantomData;
12 use std::ops::Mul;
12 13
13 /// A mapping from `Domain` to `Self::Codomain`. 14 /// A mapping from `Domain` to `Self::Codomain`.
14 pub trait Mapping<Domain: Space> { 15 pub trait Mapping<Domain: Space> {
15 type Codomain: Space; 16 type Codomain: Space;
16 17
281 fn apply<I: Instance<X>>(&self, x: I) -> Self::Codomain { 282 fn apply<I: Instance<X>>(&self, x: I) -> Self::Codomain {
282 self.outer.apply(self.inner.apply(x)) 283 self.outer.apply(self.inner.apply(x))
283 } 284 }
284 } 285 }
285 286
287 /// Helper trait for implementing [`DifferentiableMapping`]
288 impl<S, T, X, E, Y> DifferentiableImpl<X> for Composition<S, T, E>
289 where
290 X: Space,
291 T: DifferentiableImpl<X> + Mapping<X>,
292 S: DifferentiableImpl<T::Codomain>,
293 E: Copy,
294 //Composition<S::Derivative, T::Derivative, E>: Space,
295 S::Derivative: Mul<T::Derivative, Output = Y>,
296 Y: Space,
297 {
298 //type Derivative = Composition<S::Derivative, T::Derivative, E>;
299 type Derivative = Y;
300
301 /// Compute the differential of `self` at `x`, consuming the input.
302 fn differential_impl<I: Instance<X>>(&self, x: I) -> Self::Derivative {
303 // Composition {
304 // outer: self
305 // .outer
306 // .differential_impl(self.inner.apply(x.ref_instance())),
307 // inner: self.inner.differential_impl(x),
308 // intermediate_norm_exponent: self.intermediate_norm_exponent,
309 // }
310 self.outer
311 .differential_impl(self.inner.apply(x.ref_instance()))
312 * self.inner.differential_impl(x)
313 }
314 }
315
286 mod quadratic; 316 mod quadratic;
287 pub use quadratic::Quadratic; 317 pub use quadratic::Quadratic;
318 mod dataterm;
319 pub use dataterm::DataTerm;
288 320
289 /// Trait for indicating that `Self` is Lipschitz with respect to the (semi)norm `D`. 321 /// Trait for indicating that `Self` is Lipschitz with respect to the (semi)norm `D`.
290 pub trait Lipschitz<M> { 322 pub trait Lipschitz<M> {
291 /// The type of floats 323 /// The type of floats
292 type FloatType: Float; 324 type FloatType: Float;

mercurial