pub struct Matrix<T> { /* private fields */ }
Expand description
A column‑major 2D matrix of T
. Index as Array(row, column)
.
Implementations§
Source§impl<T: Clone> Matrix<T>
impl<T: Clone> Matrix<T>
Sourcepub fn from_cols(cols_data: Vec<Vec<T>>) -> Self
pub fn from_cols(cols_data: Vec<Vec<T>>) -> Self
Build from columns (each inner Vec is one column)
Sourcepub fn from_vec(data: Vec<T>, rows: usize, cols: usize) -> Self
pub fn from_vec(data: Vec<T>, rows: usize, cols: usize) -> Self
Build from a flat Vec, assuming column-major order.
Sourcepub fn from_rows_vec(data: Vec<T>, rows: usize, cols: usize) -> Self
pub fn from_rows_vec(data: Vec<T>, rows: usize, cols: usize) -> Self
Build from a flat Vec, assuming row-major order.
pub fn data(&self) -> &[T]
pub fn data_mut(&mut self) -> &mut [T]
pub fn rows(&self) -> usize
pub fn cols(&self) -> usize
pub fn shape(&self) -> (usize, usize)
Sourcepub fn get(&self, r: usize, c: usize) -> &T
pub fn get(&self, r: usize, c: usize) -> &T
Get element reference (immutable). Panics on out-of-bounds.
Sourcepub fn get_mut(&mut self, r: usize, c: usize) -> &mut T
pub fn get_mut(&mut self, r: usize, c: usize) -> &mut T
Get element reference (mutable). Panics on out-of-bounds.
pub fn column(&self, c: usize) -> &[T]
pub fn column_mut(&mut self, c: usize) -> &mut [T]
pub fn iter_columns(&self) -> impl Iterator<Item = &[T]>
pub fn iter_rows(&self) -> impl Iterator<Item = MatrixRow<'_, T>>
Sourcepub fn swap_columns(&mut self, c1: usize, c2: usize)
pub fn swap_columns(&mut self, c1: usize, c2: usize)
Swaps two columns in the matrix. Panics on out-of-bounds.
Sourcepub fn delete_column(&mut self, col: usize)
pub fn delete_column(&mut self, col: usize)
Deletes a column from the matrix. Panics on out-of-bounds. This is O(N) where N is the number of elements.
pub fn row(&self, r: usize) -> Vec<T>
pub fn row_copy_from_slice(&mut self, r: usize, values: &[T])
Sourcepub fn delete_row(&mut self, row: usize)
pub fn delete_row(&mut self, row: usize)
Deletes a row from the matrix. Panics on out-of-bounds. This is O(N) where N is the number of elements, as it rebuilds the data vec.
pub fn transpose(&self) -> Matrix<T>
Source§impl<T: Clone> Matrix<T>
impl<T: Clone> Matrix<T>
Sourcepub fn add_column(&mut self, index: usize, column: Vec<T>)
pub fn add_column(&mut self, index: usize, column: Vec<T>)
Adds a column to the matrix at the specified index. Panics if index > cols or length mismatch. This is O(N) where N is the number of elements.
Sourcepub fn add_row(&mut self, index: usize, row: Vec<T>)
pub fn add_row(&mut self, index: usize, row: Vec<T>)
Adds a row to the matrix at the specified index. Panics if index > rows or length mismatch. This is O(N) where N is the number of elements, as it rebuilds the data vec.
Sourcepub fn repeat_rows(&self, n: usize) -> Matrix<T>where
T: Clone,
pub fn repeat_rows(&self, n: usize) -> Matrix<T>where
T: Clone,
Return a new matrix where row 0 of self
is repeated n
times.
Sourcepub fn filled(rows: usize, cols: usize, value: T) -> Self
pub fn filled(rows: usize, cols: usize, value: T) -> Self
Creates a new matrix filled with a specific value of the specified size.
Sourcepub fn broadcast_row_to_target_shape(
&self,
target_rows: usize,
target_cols: usize,
) -> Matrix<T>
pub fn broadcast_row_to_target_shape( &self, target_rows: usize, target_cols: usize, ) -> Matrix<T>
Creates a new matrix by broadcasting a 1-row matrix to a target shape.
Panics if self
is not a 1-row matrix or if self.cols()
does not match target_cols
.
Source§impl Matrix<f64>
impl Matrix<f64>
Source§impl<T: PartialOrd + Clone> Matrix<T>
impl<T: PartialOrd + Clone> Matrix<T>
Sourcepub fn eq_elem<Rhs>(&self, rhs: Rhs) -> BoolMatrixwhere
Rhs: Broadcastable<T>,
pub fn eq_elem<Rhs>(&self, rhs: Rhs) -> BoolMatrixwhere
Rhs: Broadcastable<T>,
Element-wise comparison self == rhs
,
where rhs
may be a Matrix<T>
or a scalar T.
Returns a BoolMatrix
.
Sourcepub fn ne_elem<Rhs>(&self, rhs: Rhs) -> BoolMatrixwhere
Rhs: Broadcastable<T>,
pub fn ne_elem<Rhs>(&self, rhs: Rhs) -> BoolMatrixwhere
Rhs: Broadcastable<T>,
Element-wise comparison self != rhs
,
where rhs
may be a Matrix<T>
or a scalar T.
Returns a BoolMatrix
.
Sourcepub fn lt_elem<Rhs>(&self, rhs: Rhs) -> BoolMatrixwhere
Rhs: Broadcastable<T>,
pub fn lt_elem<Rhs>(&self, rhs: Rhs) -> BoolMatrixwhere
Rhs: Broadcastable<T>,
Element-wise comparison self < rhs
,
where rhs
may be a Matrix<T>
or a scalar T.
Returns a BoolMatrix
.
Sourcepub fn le_elem<Rhs>(&self, rhs: Rhs) -> BoolMatrixwhere
Rhs: Broadcastable<T>,
pub fn le_elem<Rhs>(&self, rhs: Rhs) -> BoolMatrixwhere
Rhs: Broadcastable<T>,
Element-wise comparison self <= rhs
,
where rhs
may be a Matrix<T>
or a scalar T.
Returns a BoolMatrix
.
Sourcepub fn gt_elem<Rhs>(&self, rhs: Rhs) -> BoolMatrixwhere
Rhs: Broadcastable<T>,
pub fn gt_elem<Rhs>(&self, rhs: Rhs) -> BoolMatrixwhere
Rhs: Broadcastable<T>,
Element-wise comparison self > rhs
,
where rhs
may be a Matrix<T>
or a scalar T.
Returns a BoolMatrix
.
Sourcepub fn ge_elem<Rhs>(&self, rhs: Rhs) -> BoolMatrixwhere
Rhs: Broadcastable<T>,
pub fn ge_elem<Rhs>(&self, rhs: Rhs) -> BoolMatrixwhere
Rhs: Broadcastable<T>,
Element-wise comparison self >= rhs
,
where rhs
may be a Matrix<T>
or a scalar T.
Returns a BoolMatrix
.