pub struct PackageWriter { /* private fields */ }Expand description
Writes a .ruxlapkg package of any functions: each is traced and
written as IR, and finish writes the manifest. The
Python package ruxla loads it with ruxla.load and calls the functions
inside JAX programs through the primitive ruxla_call. export uses
it for environments.
§Examples
use ruxla_core::{Array, Native, Trace, jnp};
let mut package = ruxla_env::PackageWriter::new("sin.ruxlapkg")?;
package.function(
"sin",
|x: Array<Trace, f32>| jnp::sin(&x),
&Array::<Native, f32>::from_vec(vec![0.0; 3], [3]),
)?;
package.finish("functions", serde_json::Map::new())?;Implementations§
Source§impl PackageWriter
impl PackageWriter
Sourcepub fn new(path: impl AsRef<Path>) -> Result<Self, ExportError>
pub fn new(path: impl AsRef<Path>) -> Result<Self, ExportError>
Starts a package in the directory path, which is created if needed.
§Errors
Returns an error if the directory cannot be created.
Sourcepub fn function<I: Tree<Native>, O: Tree<Trace>>(
&mut self,
name: &str,
f: impl FnOnce(I::On<Trace>) -> O,
example: &I,
) -> Result<(), ExportError>
pub fn function<I: Tree<Native>, O: Tree<Trace>>( &mut self, name: &str, f: impl FnOnce(I::On<Trace>) -> O, example: &I, ) -> Result<(), ExportError>
Traces f on values shaped like example (with B = Trace) and
writes it as name, with the pytree structure of its inputs and
outputs.
§Errors
Returns an error if the file cannot be written.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for PackageWriter
impl RefUnwindSafe for PackageWriter
impl Send for PackageWriter
impl Sync for PackageWriter
impl Unpin for PackageWriter
impl UnsafeUnpin for PackageWriter
impl UnwindSafe for PackageWriter
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more