pub trait Mapping<F> {
type Error;
// Required method
fn value(&mut self, x: &[F], out: &mut [F]) -> Result<(), Self::Error>;
// Provided methods
fn has_vjp(&self) -> bool { ... }
fn vjp(
&mut self,
u: &[F],
x: &[F],
out: &mut [F],
) -> Result<(), Self::Error> { ... }
fn has_jvp(&self) -> bool { ... }
fn jvp(
&mut self,
v: &[F],
x: &[F],
out: &mut [F],
) -> Result<bool, Self::Error> { ... }
fn jacobian(&mut self, x: &[F], j: &mut [F]) -> Result<bool, Self::Error>
where F: Native { ... }
fn has_preconditioner(&self) -> bool { ... }
fn precondition(
&mut self,
v: &[F],
out: &mut [F],
) -> Result<(), Self::Error> { ... }
}Expand description
A function from a slice of F to a slice of F, for solve and solve_linear. A closure that writes the values into its second argument and returns a Result is one. Differentiable adds vector–Jacobian products.
Required Associated Types§
Required Methods§
Provided Methods§
Sourcefn has_vjp(&self) -> bool
fn has_vjp(&self) -> bool
Whether vjp gives vector–Jacobian products. Least squares in solve_linear needs them.
Sourcefn vjp(&mut self, u: &[F], x: &[F], out: &mut [F]) -> Result<(), Self::Error>
fn vjp(&mut self, u: &[F], x: &[F], out: &mut [F]) -> Result<(), Self::Error>
uᵀJ, the product of u with the Jacobian at x, into out. For a linear mapping it’s the product of the transpose with u, at any x. Methods call it only where has_vjp is true.
Sourcefn jvp(&mut self, v: &[F], x: &[F], out: &mut [F]) -> Result<bool, Self::Error>
fn jvp(&mut self, v: &[F], x: &[F], out: &mut [F]) -> Result<bool, Self::Error>
Jv, the product of the Jacobian at x with v, into out. For a linear mapping it’s the product of the matrix with v, at any x. It gives false where it declines, as for a function it can’t differentiate at x, and the caller then takes differences instead. Methods call it only where has_jvp is true.
Sourcefn jacobian(&mut self, x: &[F], j: &mut [F]) -> Result<bool, Self::Error>where
F: Native,
fn jacobian(&mut self, x: &[F], j: &mut [F]) -> Result<bool, Self::Error>where
F: Native,
The Jacobian at x, with a row of x.len() items for each value, into j, or false where Levenberg–Marquardt should take forward differences instead. By default, a mapping builds it from vjp, one row per product, when it has no more values than variables or no jvp. Otherwise it builds it from jvp, one column per product. Each takes no more calls than differences do. It gives false for a mapping with neither, or where jvp declines.
Sourcefn has_preconditioner(&self) -> bool
fn has_preconditioner(&self) -> bool
Whether precondition gives a preconditioner’s products. solve_linear runs without one otherwise.
Sourcefn precondition(&mut self, v: &[F], out: &mut [F]) -> Result<(), Self::Error>
fn precondition(&mut self, v: &[F], out: &mut [F]) -> Result<(), Self::Error>
The product with v of a preconditioner for solve_linear, into out: M, an approximation to the inverse of the matrix, or of AᵀA for least squares. CG and MINRES need M symmetric positive definite. Methods call it only where has_preconditioner is true.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".