Skip to main content

AdCx

Trait AdCx 

Source
pub trait AdCx {
    // Required methods
    fn bind(
        &mut self,
        prim: Prim,
        inputs: &[Atom],
        params: Params,
    ) -> Result<Vec<Atom>>;
    fn constant(&mut self, value: HostArray) -> Atom;
    fn build_function(
        &mut self,
        in_avals: &[AVal],
        body: &mut AdBuildBody<'_>,
    ) -> Result<Function>;
    fn jvp_function(
        &mut self,
        f: &Function,
        nonzero: &[bool],
        instantiate: &[bool],
    ) -> Result<(Function, Vec<bool>)>;
    fn transpose_function(
        &mut self,
        f: &Function,
        linear: &[bool],
    ) -> Result<Function>;
}
Expand description

A context that emits the operations of a differentiated function.

Required Methods§

Source

fn bind( &mut self, prim: Prim, inputs: &[Atom], params: Params, ) -> Result<Vec<Atom>>

Applies a primitive and returns its outputs.

§Errors

Returns an error if the primitive rejects the inputs.

Source

fn constant(&mut self, value: HostArray) -> Atom

Returns an atom holding a constant array.

Source

fn build_function( &mut self, in_avals: &[AVal], body: &mut AdBuildBody<'_>, ) -> Result<Function>

Builds a new function with inputs in_avals from the operations that body emits through the context it receives. Atoms of this context must not be used inside body.

§Errors

Returns an error from body.

Source

fn jvp_function( &mut self, f: &Function, nonzero: &[bool], instantiate: &[bool], ) -> Result<(Function, Vec<bool>)>

Differentiates a nested function (the body of cond, scan, …) in forward mode.

The result takes the primal inputs, then the tangents of the inputs marked nonzero, and returns the primal outputs, then the tangents of the outputs it reports as nonzero. instantiate[i] makes the tangent of output i nonzero (with zeros if needed).

§Errors

Returns an error if a primitive of f has no JVP rule.

Source

fn transpose_function( &mut self, f: &Function, linear: &[bool], ) -> Result<Function>

Transposes a nested function that is linear in the inputs marked linear.

The result takes the other inputs, then a cotangent for every output, and returns the cotangents of the linear inputs (zeros where they do not depend on the outputs).

§Errors

Returns an error if a primitive of f that the linear inputs reach has no transpose rule.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§