pub struct MlxClosure(/* private fields */);Expand description
Owned MLX closure handle released exactly once through the C API.
Implementations§
Source§impl MlxClosure
impl MlxClosure
Sourcepub fn compiled(&self, shapeless: bool) -> Result<Self, MlxCError>
pub fn compiled(&self, shapeless: bool) -> Result<Self, MlxCError>
Wraps the closure so every call is compiled and cached by MLX.
Sourcepub fn checkpointed(&self) -> Result<Self, MlxCError>
pub fn checkpointed(&self) -> Result<Self, MlxCError>
Wraps the closure so calls stop at the traced boundary, matching MLX’s checkpoint transform.
Sourcepub fn with_custom_vjp(
&self,
backward: &MlxClosureCustom,
) -> Result<Self, MlxCError>
pub fn with_custom_vjp( &self, backward: &MlxClosureCustom, ) -> Result<Self, MlxCError>
Wraps the closure with a custom vector-Jacobian product.
Sourcepub fn with_custom_rules(
&self,
backward: &MlxClosureCustom,
forward: &MlxClosureCustomJvp,
linearize: &MlxClosureCustomVmap,
) -> Result<Self, MlxCError>
pub fn with_custom_rules( &self, backward: &MlxClosureCustom, forward: &MlxClosureCustomJvp, linearize: &MlxClosureCustomVmap, ) -> Result<Self, MlxCError>
Wraps the closure with custom VJP, JVP, and VMAP rules.
Source§impl MlxClosure
impl MlxClosure
Sourcepub fn compile_detailed(
&self,
function_identity: usize,
shapeless: bool,
constants: &[u64],
) -> Result<Self, MlxCError>
pub fn compile_detailed( &self, function_identity: usize, shapeless: bool, constants: &[u64], ) -> Result<Self, MlxCError>
Compiles the closure with explicit tracing details into the process compile cache.
The constants array is the identity MLX uses for compile-time
constant folding.
§Errors
Returns the captured MLX-C description when compilation fails.
Source§impl MlxClosure
impl MlxClosure
Sourcepub fn from_fn<F>(callback: F) -> Result<Self, MlxCError>
pub fn from_fn<F>(callback: F) -> Result<Self, MlxCError>
Builds an owned closure from a Rust callable mapping input arrays to output arrays.
Sourcepub fn set(&mut self, source: &Self) -> Result<(), MlxCError>
pub fn set(&mut self, source: &Self) -> Result<(), MlxCError>
Copies the source closure handle into this handle.
Sourcepub fn apply(&self, input: &MlxArrayVector) -> Result<MlxArrayVector, MlxCError>
pub fn apply(&self, input: &MlxArrayVector) -> Result<MlxArrayVector, MlxCError>
Applies the closure to the input arrays on the caller’s behalf.
§Errors
Returns the captured MLX-C description when application fails.