pub struct FdMatrix { /* private fields */ }Expand description
Column-major matrix for functional data.
Stores data in a flat Vec<f64> with column-major (Fortran) layout:
element (row, col) is at index row + col * nrows.
§Conventions
For functional data, rows typically represent observations and columns
represent evaluation points. For 2D surfaces with m1 x m2 grids,
the surface is flattened into m1 * m2 columns.
§Examples
use fdars_core::matrix::FdMatrix;
// 3 observations, 4 evaluation points
let data = vec![
1.0, 2.0, 3.0, // column 0 (all obs at point 0)
4.0, 5.0, 6.0, // column 1
7.0, 8.0, 9.0, // column 2
10.0, 11.0, 12.0, // column 3
];
let mat = FdMatrix::from_column_major(data, 3, 4).unwrap();
assert_eq!(mat[(0, 0)], 1.0); // obs 0 at point 0
assert_eq!(mat[(1, 2)], 8.0); // obs 1 at point 2
assert_eq!(mat.column(0), &[1.0, 2.0, 3.0]);Implementations§
Source§impl FdMatrix
impl FdMatrix
Sourcepub fn from_column_major(
data: Vec<f64>,
nrows: usize,
ncols: usize,
) -> Option<Self>
pub fn from_column_major( data: Vec<f64>, nrows: usize, ncols: usize, ) -> Option<Self>
Create from flat column-major data with dimension validation.
Returns None if data.len() != nrows * ncols.
Sourcepub fn from_slice(data: &[f64], nrows: usize, ncols: usize) -> Option<Self>
pub fn from_slice(data: &[f64], nrows: usize, ncols: usize) -> Option<Self>
Create from a borrowed slice (copies the data).
Returns None if data.len() != nrows * ncols.
Sourcepub fn column_mut(&mut self, col: usize) -> &mut [f64]
pub fn column_mut(&mut self, col: usize) -> &mut [f64]
Sourcepub fn row(&self, row: usize) -> Vec<f64>
pub fn row(&self, row: usize) -> Vec<f64>
Extract a single row as a new Vec<f64>.
This is an O(ncols) operation because rows are not contiguous in column-major layout.
Sourcepub fn rows(&self) -> Vec<Vec<f64>>
pub fn rows(&self) -> Vec<Vec<f64>>
Extract all rows as Vec<Vec<f64>>.
Equivalent to the former extract_curves function.
Sourcepub fn as_mut_slice(&mut self) -> &mut [f64]
pub fn as_mut_slice(&mut self) -> &mut [f64]
Mutable flat slice of the underlying column-major data.
Sourcepub fn to_dmatrix(&self) -> DMatrix<f64>
pub fn to_dmatrix(&self) -> DMatrix<f64>
Convert to a nalgebra DMatrix<f64>.
This copies the data into nalgebra’s storage. Both use column-major layout, so the copy is a simple memcpy.
Sourcepub fn from_dmatrix(mat: &DMatrix<f64>) -> Self
pub fn from_dmatrix(mat: &DMatrix<f64>) -> Self
Create from a nalgebra DMatrix<f64>.
Both use column-major layout so this is a direct copy.
Trait Implementations§
impl StructuralPartialEq for FdMatrix
Auto Trait Implementations§
impl Freeze for FdMatrix
impl RefUnwindSafe for FdMatrix
impl Send for FdMatrix
impl Sync for FdMatrix
impl Unpin for FdMatrix
impl UnsafeUnpin for FdMatrix
impl UnwindSafe for FdMatrix
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.