Skip to main content

Mapping

Trait Mapping 

Source
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§

Source

type Error

What stops an evaluation, as for Objective.

Required Methods§

Source

fn value(&mut self, x: &[F], out: &mut [F]) -> Result<(), Self::Error>

The values at x, into out.

Provided Methods§

Source

fn has_vjp(&self) -> bool

Whether vjp gives vector–Jacobian products. Least squares in solve_linear needs them.

Source

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.

Source

fn has_jvp(&self) -> bool

Whether jvp gives Jacobian–vector products.

Source

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.

Source

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.

Source

fn has_preconditioner(&self) -> bool

Whether precondition gives a preconditioner’s products. solve_linear runs without one otherwise.

Source

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".

Implementors§

Source§

impl<F, E, V: FnMut(&[F], &mut [F]) -> Result<(), E>, G: FnMut(&[F], &[F], &mut [F]) -> Result<(), E>> Mapping<F> for Differentiable<V, G>

Source§

type Error = E

Source§

impl<F, E, V: FnMut(&[F], &mut [F]) -> Result<(), E>> Mapping<F> for V

Source§

type Error = E