Struct Matrix

Source
pub struct Matrix<T: Real> {
    pub nrows: usize,
    pub ncols: usize,
    pub data: Vec<T>,
    pub storage: MatrixStorage<T>,
}
Expand description

Generic matrix for linear algebra (typically square in current use).

Fields§

§nrows: usize§ncols: usize§data: Vec<T>§storage: MatrixStorage<T>

Implementations§

Source§

impl<T: Real> Matrix<T>

Source

pub fn component_add(self, rhs: T) -> Self

Return a new matrix where each stored entry has rhs added. Off-band for banded becomes dense if rhs != 0.

Source§

impl<T: Real> Matrix<T>

Source

pub fn identity(n: usize) -> Self

Identity matrix of size n x n.

Source

pub fn full(n: usize, data: Vec<T>) -> Self

Full matrix from a row-major vector of length n*n.

Source

pub fn zeros(n: usize) -> Self

Zero matrix of size n x n.

Source

pub fn banded(n: usize, ml: usize, mu: usize) -> Self

Zero banded matrix with the given bandwidths. For entry (i,j) within the band, index maps to data[i - j + mu, j].

Source

pub fn diagonal(diag: Vec<T>) -> Self

Diagonal matrix from the provided diagonal entries (ml=mu=0).

Source

pub fn lower_triangular(n: usize) -> Self

Zero lower-triangular matrix (ml = n-1, mu = 0).

Source

pub fn upper_triangular(n: usize) -> Self

Zero upper-triangular matrix (ml = 0, mu = n-1).

Source

pub fn dims(&self) -> (usize, usize)

Dimensions (nrows, ncols).

Source

pub fn n(&self) -> usize

Convenience: n for an n x n matrix.

Source§

impl<T: Real> Matrix<T>

Source

pub fn lin_solve<V>(&self, b: V) -> V
where V: State<T>,

Solve A x = b (returns same State<T> type as b). Densifies A as needed.

Source

pub fn lin_solve_mut(&self, b: &mut [T])

In-place solve: overwrites b with x.

Source§

impl<T: Real> Matrix<T>

Source

pub fn component_mul(self, rhs: T) -> Self

Return a new matrix where each stored entry is multiplied by rhs.

Source

pub fn component_mul_mut(&mut self, rhs: T)

In-place component-wise scalar multiplication: self[i,j] *= rhs for all stored entries. For Identity, converts to a diagonal banded matrix with rhs on the diagonal.

Source

pub fn mul_state<V: State<T>>(&self, vec: &V) -> V

Source§

impl<T: Real> Matrix<T>

Source

pub fn component_sub(self, rhs: T) -> Self

Return a new matrix where each stored entry has rhs subtracted. Off-band handling similar to add.

Trait Implementations§

Source§

impl<T: Real> Add for Matrix<T>

Source§

type Output = Matrix<T>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Matrix<T>) -> Self::Output

Performs the + operation. Read more
Source§

impl<T: Real> AddAssign for Matrix<T>

Source§

fn add_assign(&mut self, rhs: Matrix<T>)

Performs the += operation. Read more
Source§

impl<T: Clone + Real> Clone for Matrix<T>

Source§

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

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<T: Debug + Real> Debug for Matrix<T>

Source§

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

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

impl<T> Display for Matrix<T>
where T: Real + Display,

Source§

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

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

impl<T: Real> Index<(usize, usize)> for Matrix<T>

2D indexing by (i, j), read-only.

Source§

type Output = T

The returned type after indexing.
Source§

fn index(&self, index: (usize, usize)) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl<T: Real> IndexMut<(usize, usize)> for Matrix<T>

2D indexing by (i, j), mutable (where supported).

Source§

fn index_mut(&mut self, (i, j): (usize, usize)) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl<T: Real> Sub for Matrix<T>

Source§

type Output = Matrix<T>

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Matrix<T>) -> Self::Output

Performs the - operation. Read more
Source§

impl<T: Real> SubAssign<&Matrix<T>> for Matrix<T>

Source§

fn sub_assign(&mut self, rhs: &Matrix<T>)

Performs the -= operation. Read more
Source§

impl<T: Real> SubAssign for Matrix<T>

Source§

fn sub_assign(&mut self, rhs: Matrix<T>)

Performs the -= operation. Read more

Auto Trait Implementations§

§

impl<T> Freeze for Matrix<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for Matrix<T>
where T: RefUnwindSafe,

§

impl<T> Send for Matrix<T>

§

impl<T> Sync for Matrix<T>

§

impl<T> Unpin for Matrix<T>
where T: Unpin,

§

impl<T> UnwindSafe for Matrix<T>
where T: UnwindSafe,

Blanket Implementations§

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, 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<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

impl<T> CallBackData for T
where T: Clone + Debug,

Source§

impl<T, Right> ClosedAdd<Right> for T
where T: Add<Right, Output = T> + AddAssign<Right>,

Source§

impl<T, Right> ClosedAddAssign<Right> for T
where T: ClosedAdd<Right> + AddAssign<Right>,

Source§

impl<T, Right> ClosedSub<Right> for T
where T: Sub<Right, Output = T> + SubAssign<Right>,

Source§

impl<T, Right> ClosedSubAssign<Right> for T
where T: ClosedSub<Right> + SubAssign<Right>,