pub struct EnsembleView<'a> { /* private fields */ }Expand description
Zero-copy view over a packed ensemble binary.
All validation happens in from_bytes. After
construction, predictions use get_unchecked for zero-overhead indexing
(all bounds have been verified).
§Lifetime
The view borrows the input buffer — the buffer must outlive the view.
Implementations§
Source§impl<'a> EnsembleView<'a>
impl<'a> EnsembleView<'a>
Sourcepub fn from_bytes(data: &'a [u8]) -> Result<Self, FormatError>
pub fn from_bytes(data: &'a [u8]) -> Result<Self, FormatError>
Parse and validate a packed ensemble binary.
Validates:
- Magic bytes match
"IRIT" - Format version is supported
- Buffer is large enough for header + tree table + all nodes
- Every internal node’s child indices are within bounds
- Every internal node’s feature index is <
n_features
§Errors
Returns FormatError if any validation check fails.
Sourcepub fn predict(&self, features: &[f32]) -> f32
pub fn predict(&self, features: &[f32]) -> f32
Predict a single sample. Zero allocation.
Returns base_prediction + sum(tree_predictions).
§Precondition
features.len() must be >= self.n_features(). Passing fewer
features than the model expects causes undefined behavior (out-of-bounds
read via get_unchecked in the traversal hot path). A debug_assert
catches this in debug builds.
Sourcepub fn predict_batch(&self, samples: &[&[f32]], out: &mut [f32])
pub fn predict_batch(&self, samples: &[&[f32]], out: &mut [f32])
Sourcepub fn n_features(&self) -> u16
pub fn n_features(&self) -> u16
Expected number of input features.
Sourcepub fn base_prediction(&self) -> f32
pub fn base_prediction(&self) -> f32
Base prediction value.
Sourcepub fn total_nodes(&self) -> usize
pub fn total_nodes(&self) -> usize
Total number of packed nodes across all trees.
Trait Implementations§
Source§impl<'a> Clone for EnsembleView<'a>
impl<'a> Clone for EnsembleView<'a>
Source§fn clone(&self) -> EnsembleView<'a>
fn clone(&self) -> EnsembleView<'a>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more