Skip to main content

EnsembleView

Struct EnsembleView 

Source
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>

Source

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.

Source

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.

Source

pub fn predict_batch(&self, samples: &[&[f32]], out: &mut [f32])

Batch predict. Uses x4 interleaving when samples.len() >= 4.

§Panics

Panics if out.len() < samples.len().

§Precondition

Every sample must have len() >= self.n_features(). See predict.

Source

pub fn n_trees(&self) -> u16

Number of trees in the ensemble.

Source

pub fn n_features(&self) -> u16

Expected number of input features.

Source

pub fn base_prediction(&self) -> f32

Base prediction value.

Source

pub fn total_nodes(&self) -> usize

Total number of packed nodes across all trees.

Trait Implementations§

Source§

impl<'a> Clone for EnsembleView<'a>

Source§

fn clone(&self) -> EnsembleView<'a>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Debug for EnsembleView<'a>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<'a> Copy for EnsembleView<'a>

Auto Trait Implementations§

§

impl<'a> Freeze for EnsembleView<'a>

§

impl<'a> RefUnwindSafe for EnsembleView<'a>

§

impl<'a> Send for EnsembleView<'a>

§

impl<'a> Sync for EnsembleView<'a>

§

impl<'a> Unpin for EnsembleView<'a>

§

impl<'a> UnsafeUnpin for EnsembleView<'a>

§

impl<'a> UnwindSafe for EnsembleView<'a>

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
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
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.

Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.