Skip to main content

Mat

Struct Mat 

Source
pub struct Mat<E> {
    pub rows: usize,
    pub cols: usize,
    pub data: Vec<E>,
}
Expand description

A rows × cols matrix stored row-major.

Fields§

§rows: usize

Number of rows.

§cols: usize

Number of columns.

§data: Vec<E>

Entries, row by row.

Implementations§

Source§

impl<E: Copy> Mat<E>

Source

pub fn from_vec(rows: usize, cols: usize, data: Vec<E>) -> Result<Self>

A matrix from row-major data. Fails if the length does not match the shape.

Source

pub fn from_fn( rows: usize, cols: usize, f: impl FnMut(usize, usize) -> E, ) -> Self

A matrix whose entry (r, c) is f(r, c).

Source

pub fn column(data: Vec<E>) -> Self

A column vector.

Source

pub fn get(&self, r: usize, c: usize) -> E

Entry (r, c).

Source

pub fn set(&mut self, r: usize, c: usize, v: E)

Set entry (r, c).

Source

pub fn row(&self, r: usize) -> &[E]

Row r as a slice.

Source

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

(rows, cols).

Source

pub fn is_square(&self) -> bool

Whether the matrix is square.

Source

pub fn map<F2>(&self, f: impl Fn(E) -> F2) -> Mat<F2>

Apply f to every entry.

Source

pub fn col(&self, c: usize) -> Vec<E>

Column c as a vector.

Source

pub fn transpose(&self) -> Self

The transpose.

Source§

impl<T: Scalar> Mat<T>

Source

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

A real matrix of zeros.

Source

pub fn matmul(&self, o: &Self) -> Result<Self>

Real matrix product.

Source

pub fn lift(m: &RMat<f64>) -> Self

Lift an f64 real matrix to this scalar type.

Source§

impl<T: Scalar> Mat<Complex<T>>

Source

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

A complex matrix of zeros.

Source

pub fn identity(n: usize) -> Self

The n × n identity.

Source

pub fn lift(m: &CMat<f64>) -> Self

Lift an f64 complex matrix to this scalar type.

Source

pub fn from_real(m: &RMat<T>) -> Self

A complex matrix from a real one.

Source

pub fn matmul(&self, o: &Self) -> Result<Self>

Complex matrix product.

Source

pub fn adjoint(&self) -> Self

The conjugate transpose.

Source

pub fn conj(&self) -> Self

The entrywise conjugate.

Source

pub fn scale(&self, s: C<T>) -> Self

Every entry times s.

Source

pub fn scale_re(&self, s: T) -> Self

Every entry times the real s.

Source

pub fn add(&self, o: &Self) -> Result<Self>

self + o.

Source

pub fn sub(&self, o: &Self) -> Result<Self>

self - o.

Source

pub fn axpy(&mut self, s: C<T>, o: &Self)

self += s·o, shapes assumed equal.

Source

pub fn axpy_re(&mut self, s: T, o: &Self)

self += s·o for a real s, shapes assumed equal.

Source

pub fn kron(&self, o: &Self) -> Self

The Kronecker product self ⊗ o.

Source

pub fn trace(&self) -> C<T>

The trace.

Source

pub fn inner(&self, o: &Self) -> C<T>

Σ conj(self_ij)·o_ij, the Frobenius inner product.

Source

pub fn norm1(&self) -> f64

The 1-norm (largest column sum of magnitudes) of the value parts.

Source§

impl Mat<Complex<f64>>

Source

pub fn max_abs_diff(&self, o: &Self) -> f64

Largest entrywise magnitude of self - o.

Source

pub fn is_hermitian(&self, tol: f64) -> bool

Whether the matrix equals its conjugate transpose to within tol.

Trait Implementations§

Source§

impl<E: Clone> Clone for Mat<E>

Source§

fn clone(&self) -> Self

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<E: Debug> Debug for Mat<E>

Source§

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

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

impl<E: Default> Default for Mat<E>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<E: PartialEq> PartialEq for Mat<E>

Source§

fn eq(&self, other: &Self) -> bool

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

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

Inequality operator !=. Read more
Source§

impl<E: PartialEq> StructuralPartialEq for Mat<E>

Auto Trait Implementations§

§

impl<E> Forget for Mat<E>

§

impl<E> Freeze for Mat<E>
where Vec<E>: Freeze,

§

impl<E> Move for Mat<E>

§

impl<E> RefUnwindSafe for Mat<E>
where Vec<E>: RefUnwindSafe,

§

impl<E> Send for Mat<E>
where Vec<E>: Send,

§

impl<E> Sync for Mat<E>
where Vec<E>: Sync,

§

impl<E> Unpin for Mat<E>
where Vec<E>: Unpin,

§

impl<E> UnsafeUnpin for Mat<E>
where Vec<E>: UnsafeUnpin,

§

impl<E> UnwindSafe for Mat<E>
where Vec<E>: 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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> Scalar for T
where T: 'static + Clone + PartialEq + Debug,

Source§

impl<T> SendAlias for T

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> SyncAlias 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, !>

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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V