pub struct Matrix {
pub rows: usize,
pub cols: usize,
pub data: Vec<f64>,
}Expand description
A dense row-major matrix.
Fields§
§rows: usizeNumber of rows.
cols: usizeNumber of columns.
data: Vec<f64>Row-major data.
Implementations§
Source§impl Matrix
impl Matrix
Sourcepub fn new(rows: usize, cols: usize, data: Vec<f64>) -> SolverResult<Self>
pub fn new(rows: usize, cols: usize, data: Vec<f64>) -> SolverResult<Self>
Creates a new matrix from shape and data.
Sourcepub fn matmul(&self, other: &Matrix) -> SolverResult<Matrix>
pub fn matmul(&self, other: &Matrix) -> SolverResult<Matrix>
Matrix multiplication: self * other.
Sourcepub fn frobenius_norm(&self) -> f64
pub fn frobenius_norm(&self) -> f64
Frobenius norm.
Sourcepub fn column_norms(&self) -> Vec<f64>
pub fn column_norms(&self) -> Vec<f64>
Column norms (L2 norm of each column).
Sourcepub fn normalize_columns(&mut self) -> Vec<f64>
pub fn normalize_columns(&mut self) -> Vec<f64>
Normalize columns in-place, returning the norms.
Sourcepub fn svd_truncated(
&self,
rank: usize,
) -> SolverResult<(Matrix, Vec<f64>, Matrix)>
pub fn svd_truncated( &self, rank: usize, ) -> SolverResult<(Matrix, Vec<f64>, Matrix)>
Truncated SVD via deflated power iteration.
Computes the top rank singular triplets one at a time, deflating the
matrix after each. Returns (U, sigma, V) where U is m×k, sigma has k
entries, V is n×k.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Matrix
impl RefUnwindSafe for Matrix
impl Send for Matrix
impl Sync for Matrix
impl Unpin for Matrix
impl UnsafeUnpin for Matrix
impl UnwindSafe for Matrix
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
Mutably borrows from an owned value. Read more