pub struct DenseMatrix { /* private fields */ }Expand description
Row-major dense matrix stored as a flat Vec<f64>.
Indexing is row * cols + col. All public mutating operations return
&mut Self or take &mut self — there are no hidden reallocations after
construction.
§Examples
use hisab::num::DenseMatrix;
let mut m = DenseMatrix::zeros(2, 3);
m.set(0, 1, 7.0);
assert_eq!(m.get(0, 1), 7.0);Implementations§
Source§impl DenseMatrix
impl DenseMatrix
Sourcepub fn from_rows(
rows: usize,
cols: usize,
data: Vec<f64>,
) -> Result<Self, HisabError>
pub fn from_rows( rows: usize, cols: usize, data: Vec<f64>, ) -> Result<Self, HisabError>
Construct from a flat row-major Vec<f64>.
§Errors
Returns HisabError::InvalidInput if data.len() != rows * cols.
Sourcepub fn from_vec_of_vec(v: &[Vec<f64>]) -> Result<Self, HisabError>
pub fn from_vec_of_vec(v: &[Vec<f64>]) -> Result<Self, HisabError>
Construct from a slice of row vectors.
All rows must have the same length.
§Errors
Returns HisabError::InvalidInput if the input is empty or rows have
inconsistent lengths.
Sourcepub fn to_vec_of_vec(&self) -> Vec<Vec<f64>>
pub fn to_vec_of_vec(&self) -> Vec<Vec<f64>>
Convert to Vec<Vec<f64>> (row-major).
Sourcepub fn get(&self, row: usize, col: usize) -> f64
pub fn get(&self, row: usize, col: usize) -> f64
Read the element at (row, col).
§Panics
Panics in debug builds if row >= self.rows || col >= self.cols.
Sourcepub fn get_mut(&mut self, row: usize, col: usize) -> &mut f64
pub fn get_mut(&mut self, row: usize, col: usize) -> &mut f64
Mutable reference to the element at (row, col).
§Panics
Panics in debug builds if row >= self.rows || col >= self.cols.
Sourcepub fn set(&mut self, row: usize, col: usize, val: f64)
pub fn set(&mut self, row: usize, col: usize, val: f64)
Set the element at (row, col) to val.
§Panics
Panics in debug builds if row >= self.rows || col >= self.cols.
Sourcepub fn mul_vec(&self, x: &[f64]) -> Result<Vec<f64>, HisabError>
pub fn mul_vec(&self, x: &[f64]) -> Result<Vec<f64>, HisabError>
Matrix-vector multiply: A · x, returning y = Ax.
§Errors
Returns HisabError::InvalidInput if x.len() != self.cols.
Sourcepub fn mul_mat(&self, other: &DenseMatrix) -> Result<DenseMatrix, HisabError>
pub fn mul_mat(&self, other: &DenseMatrix) -> Result<DenseMatrix, HisabError>
Matrix-matrix multiply: self · other.
§Errors
Returns HisabError::InvalidInput if self.cols != other.rows.
Sourcepub fn transpose(&self) -> DenseMatrix
pub fn transpose(&self) -> DenseMatrix
Transpose: returns a new cols × rows matrix.
Sourcepub fn frobenius_norm(&self) -> f64
pub fn frobenius_norm(&self) -> f64
Frobenius norm: √(∑ aᵢⱼ²).
Trait Implementations§
Source§impl Clone for DenseMatrix
impl Clone for DenseMatrix
Source§fn clone(&self) -> DenseMatrix
fn clone(&self) -> DenseMatrix
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more