pub struct DenseMatrix<T> { /* private fields */ }Expand description
A dense matrix stored row-major.
§Why this exists when CausalTensor has a rank-2 case
A rank-2 tensor is a matrix that has to be asked whether it is one. The construction census
across the seven consumer crates found 46 rank-2 constructions, and the crates holding them
maintain the invariant by hand: DensityMatrix stores dim: usize beside its tensor because
CausalTensor cannot express squareness, and topology’s AdjacencyMatrix, IncidenceMatrix and
LaplacianMatrix are bare aliases of it. Physics, quantum and topology together call 56
two-dimensional operations and zero N-dimensional ones.
Carrying the two dimensions in the type moves rank and squareness out of runtime checks. A determinant asked of this type needs no dimension argument from the caller and cannot be handed a rank-3 object.
§Row-major
Elimination works on rows. Row-major puts each row’s entries contiguous, so axpy_rows walks
one slice and swap_rows exchanges two, which is what makes the row-operation seam cheap.
§Fields are private
Shape and data must agree — data.len() == rows * cols — and that is an invariant the type
keeps rather than one every caller re-establishes.
Implementations§
Source§impl<T> DenseMatrix<T>
impl<T> DenseMatrix<T>
Sourcepub fn from_vec(
data: Vec<T>,
rows: usize,
cols: usize,
) -> Result<Self, LinearError>
pub fn from_vec( data: Vec<T>, rows: usize, cols: usize, ) -> Result<Self, LinearError>
Builds from a row-major buffer.
§Errors
LinearError::ShapeMismatch if data.len() is not rows * cols, which includes a shape
whose entry count does not fit a usize.
Sourcepub fn row(&self, row: usize) -> Result<&[T], LinearError>
pub fn row(&self, row: usize) -> Result<&[T], LinearError>
One row’s entries, which are contiguous.
§Errors
LinearError::IndexOutOfBounds if the row is outside the shape.
Trait Implementations§
Source§impl<T> Add for DenseMatrix<T>where
T: CommutativeSemiring + Clone,
impl<T> Add for DenseMatrix<T>where
T: CommutativeSemiring + Clone,
impl<T> Annihilating for DenseMatrix<T>where
T: Annihilating + Clone,
impl<T> Associative<Additive> for DenseMatrix<T>
impl<T> Associative<Multiplicative> for DenseMatrix<T>
Source§impl<T: Clone> Clone for DenseMatrix<T>
impl<T: Clone> Clone for DenseMatrix<T>
Source§fn clone(&self) -> DenseMatrix<T>
fn clone(&self) -> DenseMatrix<T>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl<T> Commutative<Additive> for DenseMatrix<T>
Source§impl<T: Debug> Debug for DenseMatrix<T>
impl<T: Debug> Debug for DenseMatrix<T>
impl<T> Distributive for DenseMatrix<T>where
T: Distributive + Clone,
impl<T: Eq> Eq for DenseMatrix<T>
Source§impl<T> MatrixBuild for DenseMatrix<T>
impl<T> MatrixBuild for DenseMatrix<T>
Source§impl<T> MatrixView for DenseMatrix<T>
impl<T> MatrixView for DenseMatrix<T>
Source§fn to_row_major(&self) -> Result<Vec<T>, LinearError>
fn to_row_major(&self) -> Result<Vec<T>, LinearError>
The dense layout is the row-major buffer, so this is the copy rather than a walk.
Source§fn get(&self, row: usize, col: usize) -> Result<T, LinearError>
fn get(&self, row: usize, col: usize) -> Result<T, LinearError>
(row, col). Read moreSource§impl<T> Mul for DenseMatrix<T>where
T: CommutativeSemiring + Clone,
Matrix multiplication, which is what makes this a Ring and not a CommutativeRing.
impl<T> Mul for DenseMatrix<T>where
T: CommutativeSemiring + Clone,
Matrix multiplication, which is what makes this a Ring and not a CommutativeRing.
Source§impl<T, S> Mul<S> for DenseMatrix<T>
Scaling by a ring element, which is what Module<S> reads.
impl<T, S> Mul<S> for DenseMatrix<T>
Scaling by a ring element, which is what Module<S> reads.
Source§impl<T, S> MulAssign<S> for DenseMatrix<T>
impl<T, S> MulAssign<S> for DenseMatrix<T>
Source§fn mul_assign(&mut self, scalar: S)
fn mul_assign(&mut self, scalar: S)
*= operation. Read moreSource§impl<T> Neg for DenseMatrix<T>where
T: CommutativeRing + Clone,
impl<T> Neg for DenseMatrix<T>where
T: CommutativeRing + Clone,
Source§impl<T> One for DenseMatrix<T>where
T: CommutativeSemiring + Clone,
impl<T> One for DenseMatrix<T>where
T: CommutativeSemiring + Clone,
Source§impl<T: PartialEq> PartialEq for DenseMatrix<T>
impl<T: PartialEq> PartialEq for DenseMatrix<T>
Source§impl<T> RowOps for DenseMatrix<T>
The dense layout is what makes the row operations cheap: each row’s entries are contiguous, so
axpy_rows walks one slice and swap_rows exchanges two.
impl<T> RowOps for DenseMatrix<T>
The dense layout is what makes the row operations cheap: each row’s entries are contiguous, so
axpy_rows walks one slice and swap_rows exchanges two.