Skip to main content

TruenoNativeModel

Struct TruenoNativeModel 

Source
pub struct TruenoNativeModel {
    pub model_type: ModelType,
    pub n_params: u32,
    pub n_features: u32,
    pub n_outputs: u32,
    pub params: Option<AlignedVec<f32>>,
    pub bias: Option<AlignedVec<f32>>,
    pub extra: Option<ModelExtra>,
}
Expand description

Model format optimized for Trueno SIMD operations (spec §5.2)

Memory layout guarantees:

  • 64-byte alignment (AVX-512 compatible)
  • Contiguous storage (no pointer chasing)
  • Row-major ordering (matches Trueno convention)
  • Padding to SIMD width boundaries

§Example

use aprender::native::{TruenoNativeModel, AlignedVec, ModelExtra};
use aprender::format::ModelType;

let params = AlignedVec::from_slice(&[0.5, -0.3, 0.8, 0.2]);
let bias = AlignedVec::from_slice(&[1.0]);

let model = TruenoNativeModel::new(
    ModelType::LinearRegression,
    4,   // n_params
    4,   // n_features
    1,   // n_outputs
)
.with_params(params)
.with_bias(bias);

assert_eq!(model.n_params, 4);
assert!(model.is_aligned());

Fields§

§model_type: ModelType

Model type identifier

§n_params: u32

Number of parameters

§n_features: u32

Number of features expected in input

§n_outputs: u32

Number of outputs (classes for classification, 1 for regression)

§params: Option<AlignedVec<f32>>

Model parameters (64-byte aligned)

§bias: Option<AlignedVec<f32>>

Bias terms (64-byte aligned)

§extra: Option<ModelExtra>

Additional model-specific data

Implementations§

Source§

impl TruenoNativeModel

Source

pub const fn new( model_type: ModelType, n_params: u32, n_features: u32, n_outputs: u32, ) -> TruenoNativeModel

Create a new native model skeleton

Source

pub fn with_params(self, params: AlignedVec<f32>) -> TruenoNativeModel

Set model parameters

Source

pub fn with_bias(self, bias: AlignedVec<f32>) -> TruenoNativeModel

Set bias terms

Source

pub fn with_extra(self, extra: ModelExtra) -> TruenoNativeModel

Set extra model data

Source

pub fn is_aligned(&self) -> bool

Check if all buffers are properly aligned

Source

pub fn size_bytes(&self) -> usize

Total size in bytes (including alignment padding)

Source

pub fn validate(&self) -> Result<(), NativeModelError>

Validate model structure

Source

pub fn params_ptr(&self) -> Option<*const f32>

Get raw pointer to parameters for SIMD operations

§Safety

Caller must ensure the returned pointer is not used after the model is dropped.

Source

pub fn bias_ptr(&self) -> Option<*const f32>

Get raw pointer to bias for SIMD operations

§Safety

Caller must ensure the returned pointer is not used after the model is dropped.

Source

pub fn predict_linear(&self, features: &[f32]) -> Result<f32, NativeModelError>

Predict for a single sample (linear models only)

Uses naive implementation for validation; production code should use Trueno SIMD operations.

Trait Implementations§

Source§

impl Clone for TruenoNativeModel

Source§

fn clone(&self) -> TruenoNativeModel

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 Debug for TruenoNativeModel

Source§

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

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

impl Default for TruenoNativeModel

Source§

fn default() -> TruenoNativeModel

Returns the “default value” for a type. 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
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> Downcast<T> for T

Source§

fn downcast(&self) -> &T

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,