Skip to main content

vmap

Function vmap 

Source
pub fn vmap<F>(f: F) -> Vmap<F>
Expand description

Returns f batched over examples, like jax.vmap with every input and output batched at dimension 0.

f takes and returns pytrees of Trace values for one example. It is traced once, and the IR is batched by ruxla’s vmap (the same transformation that JAX’s vmap of an exported program uses), so the batched program has no loop. Vmap::call runs it with the interpreter and Vmap::call_xla with XLA. To run a generic program natively for many examples, call it in a loop (or use ruxla_env::VecEnv).

§Examples

use ruxla_core::{F32, Trace, vmap};

let f = vmap(|(x, y): (F32<Trace>, F32<Trace>)| x * y + 1.0);
let out = f.call(&[(F32::new(2.0), F32::new(3.0)), (F32::new(4.0), F32::new(0.5))]);
assert_eq!(out.iter().map(|v| v.value()).collect::<Vec<_>>(), [7.0, 3.0]);