Skip to main content

DenseMatrix

Struct DenseMatrix 

Source
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>

Source

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.

Source

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

The entries, row-major.

Source

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>

Source§

type Output = DenseMatrix<T>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Self) -> Self

Performs the + operation. Read more
Source§

impl<T> Annihilating for DenseMatrix<T>
where T: Annihilating + Clone,

Source§

impl<T> Associative<Additive> for DenseMatrix<T>

Source§

impl<T> Associative<Multiplicative> for DenseMatrix<T>

Source§

impl<T: Clone> Clone for DenseMatrix<T>

Source§

fn clone(&self) -> DenseMatrix<T>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T> Commutative<Additive> for DenseMatrix<T>

Source§

impl<T: Debug> Debug for DenseMatrix<T>

Source§

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

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

impl<T> Distributive for DenseMatrix<T>
where T: Distributive + Clone,

Source§

impl<T: Eq> Eq for DenseMatrix<T>

Source§

impl<T> MatrixBuild for DenseMatrix<T>
where T: Zero + Clone,

Source§

fn zeros(rows: usize, cols: usize) -> Self

A matrix of the given shape with every entry zero. Read more
Source§

fn set(&mut self, row: usize, col: usize, value: T) -> Result<(), LinearError>

Writes value at (row, col). Read more
Source§

fn identity(n: usize) -> Self
where Self: Sized, Self::Scalar: One,

The n x n identity. Read more
Source§

impl<T> MatrixView for DenseMatrix<T>
where T: Zero + Clone,

Source§

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§

type Scalar = T

The type of an entry. Read more
Source§

fn rows(&self) -> usize

The number of rows.
Source§

fn cols(&self) -> usize

The number of columns.
Source§

fn get(&self, row: usize, col: usize) -> Result<T, LinearError>

The entry at (row, col). Read more
Source§

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

The shape, as (rows, cols).
Source§

fn len(&self) -> usize

The number of entries the shape describes, which is not the number stored. Read more
Source§

fn is_empty(&self) -> bool

Whether the shape describes no entries at all. Read more
Source§

fn is_square(&self) -> bool

Whether the matrix is square. Read more
Source§

impl<T> Mul for DenseMatrix<T>

Matrix multiplication, which is what makes this a Ring and not a CommutativeRing.

Source§

fn mul(self, rhs: Self) -> Self

Matrix multiplication, which is what makes this a Ring and not a CommutativeRing.

Source§

type Output = DenseMatrix<T>

The resulting type after applying the * operator.
Source§

impl<T, S> Mul<S> for DenseMatrix<T>
where T: Clone + Mul<S, Output = T>, S: Ring + Copy,

Scaling by a ring element, which is what Module<S> reads.

Source§

type Output = DenseMatrix<T>

The resulting type after applying the * operator.
Source§

fn mul(self, scalar: S) -> Self

Performs the * operation. Read more
Source§

impl<T, S> MulAssign<S> for DenseMatrix<T>
where T: Clone + MulAssign<S>, S: Ring + Copy,

Source§

fn mul_assign(&mut self, scalar: S)

Performs the *= operation. Read more
Source§

impl<T> Neg for DenseMatrix<T>

Source§

type Output = DenseMatrix<T>

The resulting type after applying the - operator.
Source§

fn neg(self) -> Self

Performs the unary - operation. Read more
Source§

impl<T> One for DenseMatrix<T>

Source§

fn one() -> Self

Returns the multiplicative identity element of Self, 1. Read more
Source§

fn is_one(&self) -> bool

Returns true if self is equal to the multiplicative identity.
Source§

fn set_one(&mut self)

Sets self to the multiplicative identity element of Self, 1.
Source§

impl<T: PartialEq> PartialEq for DenseMatrix<T>

Source§

fn eq(&self, other: &DenseMatrix<T>) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl<T> RowOps for DenseMatrix<T>
where T: Field + Clone,

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.

Source§

fn swap_rows(&mut self, a: usize, b: usize) -> Result<(), LinearError>

Exchanges two rows. Read more
Source§

fn scale_row( &mut self, row: usize, factor: &T, from_col: usize, ) -> Result<(), LinearError>

Multiplies row by factor, from column from_col onward. Read more
Source§

fn axpy_rows( &mut self, dst: usize, src: usize, factor: &T, from_col: usize, ) -> Result<(), LinearError>

dst := dst + factor * src, from column from_col onward. Read more
Source§

fn pivot_in_column(&self, col: usize, from_row: usize) -> Option<usize>
where Self::Scalar: Field,

Chooses a pivot row in col, searching at or below from_row. Read more
Source§

impl<T: PartialEq> StructuralPartialEq for DenseMatrix<T>

Source§

impl<T> Sub for DenseMatrix<T>

Source§

type Output = DenseMatrix<T>

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Self) -> Self

Performs the - operation. Read more
Source§

impl<T> Zero for DenseMatrix<T>

Source§

fn zero() -> Self

Returns the additive identity element of Self, 0. Read more
Source§

fn is_zero(&self) -> bool

Returns true if self is equal to the additive identity.
Source§

fn set_zero(&mut self)

Sets self to the additive identity element of Self, 0.

Auto Trait Implementations§

§

impl<T> Freeze for DenseMatrix<T>
where Vec<T>: Freeze,

§

impl<T> RefUnwindSafe for DenseMatrix<T>
where Vec<T>: RefUnwindSafe,

§

impl<T> Send for DenseMatrix<T>
where Vec<T>: Send,

§

impl<T> Sync for DenseMatrix<T>
where Vec<T>: Sync,

§

impl<T> Unpin for DenseMatrix<T>
where Vec<T>: Unpin,

§

impl<T> UnsafeUnpin for DenseMatrix<T>
where Vec<T>: UnsafeUnpin,

§

impl<T> UnwindSafe for DenseMatrix<T>
where Vec<T>: UnwindSafe,

Blanket Implementations§

Source§

impl<T> AbelianGroup for T

Source§

impl<T> AddGroup for T
where T: Sub<Output = T> + Neg<Output = T> + AddMonoid,

Source§

impl<T> AddMagma for T
where T: Add<Output = T> + Clone,

Source§

impl<T> AddMonoid for T
where T: AddSemigroup + Zero,

Source§

impl<T> AddSemigroup for T

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> Group for T
where T: AddGroup,

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<V, R> Module<R> for V
where V: AbelianGroup + Mul<R, Output = V> + MulAssign<R>, R: Ring,

Source§

fn scale(&self, scalar: R) -> Self

Scales the module element by a scalar from the ring R. Read more
Source§

fn scale_mut(&mut self, scalar: R)

Scales the module element in-place by a scalar from the ring R. Read more
Source§

impl<T> MulMagma for T
where T: Mul<Output = T> + Clone,

Source§

impl<T> MulMonoid for T
where T: MulSemigroup + One,

Source§

impl<T> MulSemigroup for T

Source§

impl<T> Ring for T

Source§

impl<T> Semiring for T

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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.