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: ModelTypeModel type identifier
n_params: u32Number of parameters
n_features: u32Number of features expected in input
n_outputs: u32Number 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
impl TruenoNativeModel
Sourcepub const fn new(
model_type: ModelType,
n_params: u32,
n_features: u32,
n_outputs: u32,
) -> TruenoNativeModel
pub const fn new( model_type: ModelType, n_params: u32, n_features: u32, n_outputs: u32, ) -> TruenoNativeModel
Create a new native model skeleton
Sourcepub fn with_params(self, params: AlignedVec<f32>) -> TruenoNativeModel
pub fn with_params(self, params: AlignedVec<f32>) -> TruenoNativeModel
Set model parameters
Sourcepub fn with_bias(self, bias: AlignedVec<f32>) -> TruenoNativeModel
pub fn with_bias(self, bias: AlignedVec<f32>) -> TruenoNativeModel
Set bias terms
Sourcepub fn with_extra(self, extra: ModelExtra) -> TruenoNativeModel
pub fn with_extra(self, extra: ModelExtra) -> TruenoNativeModel
Set extra model data
Sourcepub fn is_aligned(&self) -> bool
pub fn is_aligned(&self) -> bool
Check if all buffers are properly aligned
Sourcepub fn size_bytes(&self) -> usize
pub fn size_bytes(&self) -> usize
Total size in bytes (including alignment padding)
Sourcepub fn validate(&self) -> Result<(), NativeModelError>
pub fn validate(&self) -> Result<(), NativeModelError>
Validate model structure
Sourcepub fn params_ptr(&self) -> Option<*const f32>
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.
Sourcepub fn bias_ptr(&self) -> Option<*const f32>
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.
Sourcepub fn predict_linear(&self, features: &[f32]) -> Result<f32, NativeModelError>
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
impl Clone for TruenoNativeModel
Source§fn clone(&self) -> TruenoNativeModel
fn clone(&self) -> TruenoNativeModel
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for TruenoNativeModel
impl Debug for TruenoNativeModel
Source§impl Default for TruenoNativeModel
impl Default for TruenoNativeModel
Source§fn default() -> TruenoNativeModel
fn default() -> TruenoNativeModel
Auto Trait Implementations§
impl Freeze for TruenoNativeModel
impl RefUnwindSafe for TruenoNativeModel
impl Send for TruenoNativeModel
impl Sync for TruenoNativeModel
impl Unpin for TruenoNativeModel
impl UnsafeUnpin for TruenoNativeModel
impl UnwindSafe for TruenoNativeModel
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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