pub struct Mul<L, R>(pub L, pub R);
Expand description
Operator that applies f[g,h](x) = g(x) · h(x)
element-wise to a buffer.
Examples
x · y
let f = Mul(X.into_var(), Y.into_var());
assert_eq!(f.evaluate_dual(X, ctx!{X = 3.0, Y = 2.0}).unwrap(), dual!(6.0, 2.0));
assert_eq!(f.evaluate_dual(Y, ctx!{X = 3.0, Y = 2.0}).unwrap(), dual!(6.0, 3.0));
x · y^2
let f = Mul(X.into_var(), Y.into_var().pow(2.0f64.into_constant()));
assert_eq!(f.evaluate_dual(X, ctx!{X = 3.0, Y = 2.0}).unwrap(), dual!(12.0, 4.0));
assert_eq!(f.evaluate_dual(Y, ctx!{X = 3.0, Y = 2.0}).unwrap(), dual!(12.0, 12.0));
Tuple Fields§
§0: L
§1: R
Trait Implementations§
source§impl<T, L, R> Differentiable<T> for Mul<L, R>where
T: Identifier,
L: Differentiable<T> + Clone,
R: Differentiable<T> + Clone,
impl<T, L, R> Differentiable<T> for Mul<L, R>where
T: Identifier,
L: Differentiable<T> + Clone,
R: Differentiable<T> + Clone,
§type Adjoint = Add<Mul<<L as Differentiable<T>>::Adjoint, R>, Mul<<R as Differentiable<T>>::Adjoint, L>>
type Adjoint = Add<Mul<<L as Differentiable<T>>::Adjoint, R>, Mul<<R as Differentiable<T>>::Adjoint, L>>
The adjoint operator; i.e. the gradient.
source§fn evaluate_adjoint<C: Context, CR: AsRef<C>>(
&self,
target: T,
ctx: CR
) -> AegirResult<Self::Adjoint, C>where
Self: Function<C>,
Self::Adjoint: Function<C>,
fn evaluate_adjoint<C: Context, CR: AsRef<C>>(
&self,
target: T,
ctx: CR
) -> AegirResult<Self::Adjoint, C>where
Self: Function<C>,
Self::Adjoint: Function<C>,
Helper method that computes the adjoint and evaluates its value. Read more
source§fn evaluate_dual<C: Context, CR: AsRef<C>>(
&self,
target: T,
ctx: CR
) -> Result<DualOf<Self, C, T>, BinaryError<Self::Error, <AdjointOf<Self, T> as Function<C>>::Error, NoError>>where
Self: Function<C>,
Self::Adjoint: Function<C>,
fn evaluate_dual<C: Context, CR: AsRef<C>>(
&self,
target: T,
ctx: CR
) -> Result<DualOf<Self, C, T>, BinaryError<Self::Error, <AdjointOf<Self, T> as Function<C>>::Error, NoError>>where
Self: Function<C>,
Self::Adjoint: Function<C>,
Helper method that evaluates the function and its adjoint, wrapping up
in a Dual.
source§impl<C, F, L, LV, R, RV, OS, OC, OV> Function<C> for Mul<L, R>where
C: Context,
F: Scalar,
L: Function<C, Value = LV>,
LV: Buffer<Field = F> + ZipMap<RV, Output<F> = OV>,
LV::Shape: Broadcast<RV::Shape, Shape = OV::Shape>,
R: Function<C, Value = RV>,
RV: Buffer<Field = F> + ZipMap<LV, Output<F> = OV>,
RV::Shape: Broadcast<LV::Shape, Shape = OV::Shape>,
OS: Shape,
OC: Class<OS, Buffer<F> = OV>,
OV: Buffer<Field = F, Class = OC, Shape = OS>,
impl<C, F, L, LV, R, RV, OS, OC, OV> Function<C> for Mul<L, R>where
C: Context,
F: Scalar,
L: Function<C, Value = LV>,
LV: Buffer<Field = F> + ZipMap<RV, Output<F> = OV>,
LV::Shape: Broadcast<RV::Shape, Shape = OV::Shape>,
R: Function<C, Value = RV>,
RV: Buffer<Field = F> + ZipMap<LV, Output<F> = OV>,
RV::Shape: Broadcast<LV::Shape, Shape = OV::Shape>,
OS: Shape,
OC: Class<OS, Buffer<F> = OV>,
OV: Buffer<Field = F, Class = OC, Shape = OS>,
§type Error = BinaryError<<L as Function<C>>::Error, <R as Function<C>>::Error, IncompatibleShapes<<<L as Function<C>>::Value as Shaped>::Shape, <<R as Function<C>>::Value as Shaped>::Shape>>
type Error = BinaryError<<L as Function<C>>::Error, <R as Function<C>>::Error, IncompatibleShapes<<<L as Function<C>>::Value as Shaped>::Shape, <<R as Function<C>>::Value as Shaped>::Shape>>
The error type of the function.