pub trait Tree:
Leaves
+ Clone
+ 'static {
// Required method
fn visit_mut(&mut self, v: &mut VisitMut<'_>);
// Provided methods
fn for_each(&self, f: impl FnMut(&str, &Array)) { ... }
fn map(&self, f: impl FnMut(&str, &Array) -> Array) -> Self { ... }
fn leaves(&self) -> Vec<Array> { ... }
fn paths(&self) -> Vec<String> { ... }
fn flatten(&self) -> Vec<(String, Array)> { ... }
fn unflatten(&self, leaves: impl IntoIterator<Item = Array>) -> Result<Self> { ... }
fn load_flat(
&mut self,
named: impl IntoIterator<Item = (String, Array)>,
mode: LoadMode,
) -> Result<()> { ... }
fn len(&self) -> usize { ... }
fn is_empty(&self) -> bool { ... }
fn def(&self) -> TreeDef { ... }
}Expand description
Required Methods§
Sourcefn visit_mut(&mut self, v: &mut VisitMut<'_>)
fn visit_mut(&mut self, v: &mut VisitMut<'_>)
Reports every leaf (and child tree and mode flag) to v mutably, in the order of
Leaves::visit.
Provided Methods§
Sourcefn map(&self, f: impl FnMut(&str, &Array) -> Array) -> Self
fn map(&self, f: impl FnMut(&str, &Array) -> Array) -> Self
The tree with every leaf replaced by f(path, leaf) (same structure; parameters keep
their frozen flag).
Sourcefn flatten(&self) -> Vec<(String, Array)>
fn flatten(&self) -> Vec<(String, Array)>
The leaves with their paths, in order (MLX’s tree_flatten).
Sourcefn unflatten(&self, leaves: impl IntoIterator<Item = Array>) -> Result<Self>
fn unflatten(&self, leaves: impl IntoIterator<Item = Array>) -> Result<Self>
A tree of this structure (self is the template) with leaves in order: exactly
Tree::len of them, else an error naming both counts.
Sourcefn load_flat(
&mut self,
named: impl IntoIterator<Item = (String, Array)>,
mode: LoadMode,
) -> Result<()>
fn load_flat( &mut self, named: impl IntoIterator<Item = (String, Array)>, mode: LoadMode, ) -> Result<()>
Replaces leaves by path. LoadMode::Strict requires exactly the tree’s paths with
matching shapes; LoadMode::Partial assigns the matching names and ignores
unknown ones (shapes must still match). Loaded dtypes are kept. On any problem the
error lists every one (missing, unknown and mismatched names, sorted) and the tree is
unchanged. Duplicate paths (in the tree or in named) are an error.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".