| 3 */ |
3 */ |
| 4 |
4 |
| 5 use serde::Serialize; |
5 use serde::Serialize; |
| 6 use crate::types::*; |
6 use crate::types::*; |
| 7 use crate::instance::{Space, Instance}; |
7 use crate::instance::{Space, Instance}; |
| 8 use crate::mapping::{Mapping, DifferentiableImpl, DifferentiableMapping}; |
8 use crate::mapping::{Mapping, ArithmeticTrue, DifferentiableImpl, DifferentiableMapping}; |
| 9 |
9 |
| 10 /// A trait for encoding constant [`Float`] values |
10 /// A trait for encoding constant [`Float`] values |
| 11 pub trait Constant : Copy + Sync + Send + 'static + std::fmt::Debug + Into<Self::Type> { |
11 pub trait Constant : Copy + Sync + Send + 'static + std::fmt::Debug + Into<Self::Type> { |
| 12 /// The type of the value |
12 /// The type of the value |
| 13 type Type : Float; |
13 type Type : Float; |
| 38 T : Mapping<D, Codomain=V>, |
38 T : Mapping<D, Codomain=V>, |
| 39 V : Space + ClosedMul<F>, |
39 V : Space + ClosedMul<F>, |
| 40 C : Constant<Type=F> |
40 C : Constant<Type=F> |
| 41 { |
41 { |
| 42 type Codomain = V; |
42 type Codomain = V; |
| |
43 type ArithmeticOptIn = ArithmeticTrue; |
| 43 |
44 |
| 44 #[inline] |
45 #[inline] |
| 45 fn apply<I : Instance<D>>(&self, x : I) -> Self::Codomain { |
46 fn apply<I : Instance<D>>(&self, x : I) -> Self::Codomain { |
| 46 self.base_fn.apply(x) * self.weight.value() |
47 self.base_fn.apply(x) * self.weight.value() |
| 47 } |
48 } |