Skip to main content

PackageWriter

Struct PackageWriter 

Source
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

Source

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.

Source

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.

Source

pub fn finish( self, kind: &str, extra: Map<String, Value>, ) -> Result<(), ExportError>

Writes the manifest, with the package’s kind (such as "env") and extra fields (such as "env", the description of an environment).

§Errors

Returns an error if the manifest cannot be written.

Trait Implementations§

Source§

impl Debug for PackageWriter

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.