pub trait ForwardDiffable<StaticArgs>: Diffable<StaticArgs> {
// Required method
fn eval_forward_grad(
&self,
x: &<Self as Diffable<StaticArgs>>::Input,
dx: &<Self as Diffable<StaticArgs>>::Input,
static_args: &StaticArgs,
) -> (<Self as Diffable<StaticArgs>>::Output, <Self as Diffable<StaticArgs>>::Output);
// Provided methods
fn eval_forward(
&self,
x: &<Self as Diffable<StaticArgs>>::Input,
static_args: &StaticArgs,
) -> <Self as Diffable<StaticArgs>>::Output { ... }
fn forward_grad(
&self,
x: &<Self as Diffable<StaticArgs>>::Input,
dx: &<Self as Diffable<StaticArgs>>::Input,
static_args: &StaticArgs,
) -> <Self as Diffable<StaticArgs>>::Output { ... }
}Required Methods§
Sourcefn eval_forward_grad(
&self,
x: &<Self as Diffable<StaticArgs>>::Input,
dx: &<Self as Diffable<StaticArgs>>::Input,
static_args: &StaticArgs,
) -> (<Self as Diffable<StaticArgs>>::Output, <Self as Diffable<StaticArgs>>::Output)
fn eval_forward_grad( &self, x: &<Self as Diffable<StaticArgs>>::Input, dx: &<Self as Diffable<StaticArgs>>::Input, static_args: &StaticArgs, ) -> (<Self as Diffable<StaticArgs>>::Output, <Self as Diffable<StaticArgs>>::Output)
Evaluate the function and its gradient in forward mode for a given input x, derivative dx, and static arguments
Returns (f(x, static_args): <Self as Diffable<StaticArgs>>::Output, df(x, dx, static_args): <Self as Diffable<StaticArgs>>::Output)
By default, df = df/dx * dx. However, this can be overridden in cases where this equality
does not hold (e.g. complex valued functions), or where a more efficient implementation is possible (e.g. functions whose arguments and return types are arrays)
NOTE: The multiplication here is not the same as normal multiplication. Instead in reality
df = (df/dx).forward_mul(dx). For many types, this is equivalent to normal multiplication (all primitives which implement Mul). However, for arrays this is tensor contraction over the last few axes, such that the number of dimensions of df match that of f.
Similarly, this cannot be implemented for complex numbers, which will require a custom
eval_forward_grad implementation.
Provided Methods§
Sourcefn eval_forward(
&self,
x: &<Self as Diffable<StaticArgs>>::Input,
static_args: &StaticArgs,
) -> <Self as Diffable<StaticArgs>>::Output
fn eval_forward( &self, x: &<Self as Diffable<StaticArgs>>::Input, static_args: &StaticArgs, ) -> <Self as Diffable<StaticArgs>>::Output
Evaluate the function for a given input x and static arguments
Sourcefn forward_grad(
&self,
x: &<Self as Diffable<StaticArgs>>::Input,
dx: &<Self as Diffable<StaticArgs>>::Input,
static_args: &StaticArgs,
) -> <Self as Diffable<StaticArgs>>::Output
fn forward_grad( &self, x: &<Self as Diffable<StaticArgs>>::Input, dx: &<Self as Diffable<StaticArgs>>::Input, static_args: &StaticArgs, ) -> <Self as Diffable<StaticArgs>>::Output
Evaluate the gradient in forward mode for a given input x, derivative dx, and static arguments
Implementors§
impl<S, I, P: InstOne> ForwardDiffable<S> for Monomial<S, I, P>
impl<S, I: Clone + GradientType<O, GradientType = O>, O> ForwardDiffable<S> for Polynomial<S, I, O>
impl<S, I: Clone + InstOne + InstZero + GradientType<I> + GradientIdentity> ForwardDiffable<S> for Identity<S, I>
impl<StaticArgs, InnerInput, InnerOutput, OuterInput, OuterOutput, Outer, Inner> ForwardDiffable<StaticArgs> for ADCompose<Outer, Inner>where
Outer: ForwardDiffable<StaticArgs, Input = OuterInput, Output = OuterOutput>,
Inner: ForwardDiffable<StaticArgs, Input = InnerInput, Output = InnerOutput>,
OuterInput: From<InnerOutput>,
impl<StaticArgs, Input, AOutput, BOutput, Output, A, B> ForwardDiffable<StaticArgs> for ADAdd<A, B>where
A: ForwardDiffable<StaticArgs, Input = Input, Output = AOutput>,
B: ForwardDiffable<StaticArgs, Input = Input, Output = BOutput>,
AOutput: Add<BOutput, Output = Output>,
impl<StaticArgs, Input, AOutput, BOutput, Output, A, B> ForwardDiffable<StaticArgs> for ADSub<A, B>where
A: ForwardDiffable<StaticArgs, Input = Input, Output = AOutput>,
B: ForwardDiffable<StaticArgs, Input = Input, Output = BOutput>,
AOutput: Sub<BOutput, Output = Output>,
impl<StaticArgs, Input, Output, A> ForwardDiffable<StaticArgs> for ADAbs<A>where
A: ForwardDiffable<StaticArgs, Input = Input, Output = Output>,
Output: Signed + Mul<Output, Output = Output>,
impl<StaticArgs, Input, Output, A> ForwardDiffable<StaticArgs> for ADSignum<A>where
A: ForwardDiffable<StaticArgs, Input = Input, Output = Output>,
Output: Signed + InstZero + UpperBounded,
impl<StaticArgs, Input, Output, AOutput, A> ForwardDiffable<StaticArgs> for ADNeg<A>where
A: ForwardDiffable<StaticArgs, Input = Input, Output = AOutput>,
AOutput: Neg<Output = Output>,
impl<StaticArgs, Input, Output, AOutput, A, B> ForwardDiffable<StaticArgs> for ADConstantAdd<A, B>where
A: ForwardDiffable<StaticArgs, Input = Input, Output = AOutput>,
AOutput: Add<B, Output = Output>,
B: Clone + InstZero,
impl<StaticArgs, Input, Output, AOutput, A, B> ForwardDiffable<StaticArgs> for ADConstantDiv<A, B>where
A: ForwardDiffable<StaticArgs, Input = Input, Output = AOutput>,
AOutput: Div<B, Output = Output>,
B: Clone,
impl<StaticArgs, Input, Output, AOutput, A, B> ForwardDiffable<StaticArgs> for ADConstantMul<A, B>where
A: ForwardDiffable<StaticArgs, Input = Input, Output = AOutput>,
AOutput: Mul<B, Output = Output>,
B: Clone,
impl<StaticArgs, Input, Output, AOutput, A, B> ForwardDiffable<StaticArgs> for ADConstantSub<A, B>where
A: ForwardDiffable<StaticArgs, Input = Input, Output = AOutput>,
AOutput: Sub<B, Output = Output>,
B: Clone + InstZero,
impl<StaticArgs, Input, Output, AOutput, APBB, A, B> ForwardDiffable<StaticArgs> for ADConstantPow<A, B>
impl<StaticArgs, Input, Output, AOutput, BOutput, A, B> ForwardDiffable<StaticArgs> for ADMul<A, B>where
A: ForwardDiffable<StaticArgs, Input = Input, Output = AOutput>,
B: ForwardDiffable<StaticArgs, Input = Input, Output = BOutput>,
AOutput: Clone + Mul<BOutput, Output = Output>,
BOutput: Clone,
Output: Add<Output, Output = Output>,
impl<StaticArgs, Input, Output, AOutput, BOutput, BB, AB, ABOVBB, A, B> ForwardDiffable<StaticArgs> for ADDiv<A, B>where
A: ForwardDiffable<StaticArgs, Input = Input, Output = AOutput>,
B: ForwardDiffable<StaticArgs, Input = Input, Output = BOutput>,
AOutput: Clone + Div<BOutput, Output = Output> + Mul<BOutput, Output = AB>,
BOutput: Clone + Mul<BOutput, Output = BB>,
AB: Div<BB, Output = ABOVBB>,
Output: Sub<ABOVBB, Output = Output>,
impl<StaticArgs, Input, Output, NewInput, NewOutput, A> ForwardDiffable<StaticArgs> for ADCoerce<A, NewInput, NewOutput>where
A: ForwardDiffable<StaticArgs, Input = Input, Output = Output>,
NewInput: Clone,
Input: From<NewInput>,
NewOutput: From<Output>,
impl<StaticArgs, Input, Output, T> ForwardDiffable<StaticArgs> for AutoDiff<StaticArgs, T>where
T: ForwardDiffable<StaticArgs, Input = Input, Output = Output>,
Impl of ForwardDiffable for AutoDiff