pub struct Vmap<F> { /* private fields */ }Expand description
A batched function; see vmap.
Implementations§
Source§impl<F> Vmap<F>
impl<F> Vmap<F>
Sourcepub fn call<I, O>(&self, examples: &[I]) -> Vec<O::On<Native>>
pub fn call<I, O>(&self, examples: &[I]) -> Vec<O::On<Native>>
Runs the batched program on examples with the interpreter and
returns one output per example.
§Panics
Panics if there are no examples, if they differ in structure or types, or if a primitive cannot be batched.
Sourcepub fn call_xla<I, O>(
&self,
examples: &[I],
) -> Result<Vec<O::On<Native>>, Error>
pub fn call_xla<I, O>( &self, examples: &[I], ) -> Result<Vec<O::On<Native>>, Error>
Runs the batched program on examples with XLA and returns one
output per example.
§Errors
Returns an error if no PJRT plugin is configured, or if compiling or running fails.
§Panics
See Vmap::call.
Sourcepub fn call_traced<I, O>(&self, examples: I) -> O
pub fn call_traced<I, O>(&self, examples: I) -> O
Calls the batched function inside another trace on examples,
pytrees of Trace values whose arrays are stacked along a new
leading dimension (the number of examples). The batched body becomes
a jit equation of the outer IR. Values that f captures from the
outer trace are shared by all examples (not batched).
The stacked values have the types of one example, so a stacked
Scalar holds an array of rank 1: pass such values
on (to another vmap, a loop’s carry, or an output) without
computing with them, and return arrays of rank 0 from f for values
to compute with afterwards.
§Examples
use ruxla_core::{Array, F32, Trace, interpret, vmap};
let f = |(xs, y): (Array<Trace, f32>, F32<Trace>)| {
vmap(|x: Array<Trace, f32>| x * y).call_traced(xs)
};
let out = interpret(f, &(Array::from_vec(vec![1.0f32, 2.0, 3.0], [3]), F32::new(2.0)));
assert_eq!(out.to_vec(), [2.0, 4.0, 6.0]);§Panics
Panics if the leaves of examples do not have the same leading
dimension, or if a primitive cannot be batched.