Skip to main content

FdMatrix

Struct FdMatrix 

Source
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

Source

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.

Source

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.

Source

pub fn zeros(nrows: usize, ncols: usize) -> Self

Create a zero-filled matrix.

Source

pub fn nrows(&self) -> usize

Number of rows.

Source

pub fn ncols(&self) -> usize

Number of columns.

Source

pub fn shape(&self) -> (usize, usize)

Dimensions as (nrows, ncols).

Source

pub fn len(&self) -> usize

Total number of elements.

Source

pub fn is_empty(&self) -> bool

Whether the matrix is empty.

Source

pub fn column(&self, col: usize) -> &[f64]

Get a contiguous column slice (zero-copy).

§Panics

Panics if col >= ncols.

Source

pub fn column_mut(&mut self, col: usize) -> &mut [f64]

Get a mutable contiguous column slice (zero-copy).

§Panics

Panics if col >= ncols.

Source

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.

Source

pub fn rows(&self) -> Vec<Vec<f64>>

Extract all rows as Vec<Vec<f64>>.

Equivalent to the former extract_curves function.

Source

pub fn as_slice(&self) -> &[f64]

Flat slice of the underlying column-major data (zero-copy).

Source

pub fn as_mut_slice(&mut self) -> &mut [f64]

Mutable flat slice of the underlying column-major data.

Source

pub fn into_vec(self) -> Vec<f64>

Consume and return the underlying Vec<f64>.

Source

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.

Source

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.

Source

pub fn get(&self, row: usize, col: usize) -> Option<f64>

Get element at (row, col) with bounds checking.

Source

pub fn set(&mut self, row: usize, col: usize, value: f64) -> bool

Set element at (row, col) with bounds checking.

Trait Implementations§

Source§

impl Clone for FdMatrix

Source§

fn clone(&self) -> FdMatrix

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 FdMatrix

Source§

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

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

impl Display for FdMatrix

Source§

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

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

impl Index<(usize, usize)> for FdMatrix

Source§

type Output = f64

The returned type after indexing.
Source§

fn index(&self, (row, col): (usize, usize)) -> &f64

Performs the indexing (container[index]) operation. Read more
Source§

impl IndexMut<(usize, usize)> for FdMatrix

Source§

fn index_mut(&mut self, (row, col): (usize, usize)) -> &mut f64

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl PartialEq for FdMatrix

Source§

fn eq(&self, other: &FdMatrix) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for FdMatrix

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> 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<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> Scalar for T
where T: 'static + Clone + PartialEq + Debug,