Skip to main content

BatchCx

Trait BatchCx 

Source
pub trait BatchCx {
    // Required methods
    fn axis_size(&self) -> usize;
    fn bind(
        &mut self,
        prim: Prim,
        inputs: &[Atom],
        params: Params,
    ) -> Result<Vec<Atom>>;
    fn constant(&mut self, value: HostArray) -> Atom;
    fn batch_function(
        &mut self,
        f: &Function,
        in_axes: &[Option<usize>],
        force: &[Option<bool>],
    ) -> Result<(Function, Vec<bool>)>;
    fn build_function(
        &mut self,
        in_avals: &[AVal],
        body: &mut BuildBody<'_>,
    ) -> Result<Function>;
}
Expand description

A context that emits the operations of a batched function.

Required Methods§

Source

fn axis_size(&self) -> usize

Returns the size of the batch.

Source

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

Applies a primitive to atoms of the batched function 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 batch_function( &mut self, f: &Function, in_axes: &[Option<usize>], force: &[Option<bool>], ) -> Result<(Function, Vec<bool>)>

Batches a nested function (the body of jit, scan, …) whose inputs have the batch dimensions in_axes.

In the result, batched outputs have their batch dimension first. force[i] requires output i to be batched (Some(true), by broadcasting it if needed) or unbatched (Some(false)); None leaves it as it comes. Returns the function and which outputs are batched.

§Errors

Returns an error if a primitive of f cannot be batched, or if an output that must be unbatched is batched.

Source

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

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

§Errors

Returns an error from body.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§