#[non_exhaustive]pub struct DenseMatrix { /* private fields */ }Expand description
A contiguous, column-major dense matrix.
Layout: data[col * n_rows + row].
This replaces Vec<Vec<f64>> for feature storage, providing:
- Zero-cost column slicing via
col - Single contiguous allocation instead of N+1 heap blocks
- Cache-friendly access patterns for column-oriented ML algorithms
Implementations§
Source§impl DenseMatrix
impl DenseMatrix
Sourcepub fn new(data: Vec<f64>, n_rows: usize, n_cols: usize) -> Result<Self>
pub fn new(data: Vec<f64>, n_rows: usize, n_cols: usize) -> Result<Self>
Create a matrix from a flat column-major buffer.
Returns an error if data.len() != n_rows * n_cols.
Sourcepub fn from_col_major(cols: Vec<Vec<f64>>) -> Result<Self>
pub fn from_col_major(cols: Vec<Vec<f64>>) -> Result<Self>
Build from column-major Vec<Vec<f64>> (each inner vec is one column).
Returns an error if columns have different lengths.
Sourcepub fn from_row_major(rows: &[&[f64]], n_rows: usize, n_cols: usize) -> Self
pub fn from_row_major(rows: &[&[f64]], n_rows: usize, n_cols: usize) -> Self
Build from row-major data, transposing into column-major storage.
Sourcepub fn row_iter(&self, i: usize) -> impl Iterator<Item = f64> + '_
pub fn row_iter(&self, i: usize) -> impl Iterator<Item = f64> + '_
Iterate over values in row i (strided access across columns).
Sourcepub fn row_to_vec(&self, i: usize) -> Vec<f64>
pub fn row_to_vec(&self, i: usize) -> Vec<f64>
Collect row i into a Vec<f64>.
Sourcepub fn from_col_major_ref(cols: &[Vec<f64>]) -> Result<Self>
pub fn from_col_major_ref(cols: &[Vec<f64>]) -> Result<Self>
Build from a reference to column-major &[Vec<f64>] (no ownership transfer).
Same as from_col_major but borrows the columns
instead of consuming them, avoiding a clone of the outer Vec.
Sourcepub fn to_col_vecs(&self) -> Vec<Vec<f64>>
pub fn to_col_vecs(&self) -> Vec<Vec<f64>>
Convert back to Vec<Vec<f64>> column-major (backward compat).
Trait Implementations§
Source§impl Clone for DenseMatrix
impl Clone for DenseMatrix
Source§fn clone(&self) -> DenseMatrix
fn clone(&self) -> DenseMatrix
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for DenseMatrix
impl Debug for DenseMatrix
Auto Trait Implementations§
impl Freeze for DenseMatrix
impl RefUnwindSafe for DenseMatrix
impl Send for DenseMatrix
impl Sync for DenseMatrix
impl Unpin for DenseMatrix
impl UnsafeUnpin for DenseMatrix
impl UnwindSafe for DenseMatrix
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