Struct SMatrix

pub struct SMatrix<T, const M: usize, const N: usize> { /* private fields */ }
Expand description

Statically sized matrix.

SMatrix is used almost just like Matrix, but its size is known at compile-time, so operations can be done without the & operator. The size of this matrix cannot be changed.

§Example

let mut mat_a: SMatrix<i32, 3, 3> = SMatrix::one();
mat_a = mat_a * 2;
mat_a[1] = [1,2,3];
assert_eq!(mat_a, smatrix!{{2,0,0},{1,2,3},{0,0,2}});

Implementations§

§

impl<T, const M: usize, const N: usize> SMatrix<T, M, N>
where T: Copy,

Methods for matrices with general dimensions.

pub fn new(init: T) -> SMatrix<T, M, N>

Creates new Matrix

§Example
let mut mat_a: SMatrix<i32, 3, 3> = SMatrix::new(1_i32);
mat_a[1] = [1, 2, 3];
assert_eq!(mat_a[1], [1, 2, 3]);
assert_eq!(mat_a[1][1], 2);
let mat_b = smatrix!{1, 1, 1; 1, 1, 1; 1, 1, 1;};
let mat_c: SMatrix<u32, 3, 3> = SMatrix::new(1);
assert_eq!(mat_b, mat_c);

pub fn row_count(&self) -> usize

Get the number of rows

pub fn col_count(&self) -> usize

Get the number of columns

pub fn is_square(&self) -> bool

Returns true if the matrix is a square matrix, false otherwise.

pub fn transpose(&self) -> SMatrix<T, N, M>
where T: Zero,

Transpose a matrix.

This functions returns a new SMatrix with a different type.

§Example
let mat_a: SMatrix<i32, 4, 3> = smatrix!{1, 2, 3;
                                         3, 2, 1;
                                         2, 3, 1;
                                         3, 1, 2};
assert_eq!(mat_a.transpose(), smatrix!{1,3,2,3;2,2,3,1;3,1,1,2});
§

impl<T, const N: usize> SMatrix<T, N, N>
where T: Sub<Output = T> + Add<Output = T> + Mul<Output = T> + ToPrimitive,

pub fn lupdecompose(&self) -> Option<(SMatrix<f64, N, N>, Vec<usize>)>
where T: Signed,

pub fn det(&self) -> f64
where T: Copy + Signed,

pub fn diag(init: T) -> SMatrix<T, N, N>
where T: Copy + One + Zero,

Creates a diagonal matrix with every diagonal entry havong the value of init.

pub fn diag_with(entries: &[T]) -> SMatrix<T, N, N>
where T: One + Copy + Zero,

Creates a diagonal matrix with initial entries specified in entries.

Trait Implementations§

§

impl<T, const M: usize, const N: usize> Add for SMatrix<T, M, N>
where T: Add<Output = T> + Zero + Copy,

§

type Output = SMatrix<T, M, N>

The resulting type after applying the + operator.
§

fn add(self, rhs: SMatrix<T, M, N>) -> Self::Output

Performs the + operation. Read more
§

impl<T, const M: usize, const N: usize> AddAssign for SMatrix<T, M, N>
where T: Add<Output = T> + Zero + Copy,

§

fn add_assign(&mut self, rhs: SMatrix<T, M, N>)

Performs the += operation. Read more
§

impl<T: Clone, const M: usize, const N: usize> Clone for SMatrix<T, M, N>

§

fn clone(&self) -> SMatrix<T, M, N>

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
§

impl<T: Debug, const M: usize, const N: usize> Debug for SMatrix<T, M, N>

§

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

Formats the value using the given formatter. Read more
§

impl<T, const M: usize, const N: usize> Deref for SMatrix<T, M, N>

§

type Target = [[T; N]; M]

The resulting type after dereferencing.
§

fn deref(&self) -> &Self::Target

Dereferences the value.
§

impl<T, const M: usize, const N: usize> DerefMut for SMatrix<T, M, N>

§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
§

impl<T, const M: usize, const N: usize> Display for SMatrix<T, M, N>
where T: Display,

§

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

Formats the value using the given formatter. Read more
§

impl<T, const M: usize, const N: usize> Div<T> for SMatrix<T, M, N>
where T: Mul<Output = T> + Div<Output = T> + One + Copy,

§

type Output = SMatrix<T, M, N>

The resulting type after applying the / operator.
§

fn div(self, rhs: T) -> Self::Output

Performs the / operation. Read more
§

impl<T, const M: usize, const N: usize> DivAssign<T> for SMatrix<T, M, N>
where T: Mul<Output = T> + Div<Output = T> + One + Copy,

§

fn div_assign(&mut self, rhs: T)

Performs the /= operation. Read more
§

impl<T, const M: usize, const N: usize> From<[[T; N]; M]> for SMatrix<T, M, N>

§

fn from(arr: [[T; N]; M]) -> Self

Converts to this type from the input type.
§

impl<T, const N: usize> Inv for SMatrix<T, N, N>
where T: Sub<Output = T> + Add<Output = T> + Mul<Output = T> + ToPrimitive + Signed,

§

type Output = Option<SMatrix<f64, N, N>>

The result after applying the operator.
§

fn inv(self) -> Self::Output

Returns the multiplicative inverse of self. Read more
§

impl<T, const L: usize, const M: usize, const N: usize> Mul<SMatrix<T, M, N>> for SMatrix<T, L, M>
where T: Add<Output = T> + Mul<Output = T> + One + Copy,

§

type Output = SMatrix<T, L, N>

The resulting type after applying the * operator.
§

fn mul(self, rhs: SMatrix<T, M, N>) -> Self::Output

Performs the * operation. Read more
§

impl<T, const M: usize, const N: usize> Mul<T> for SMatrix<T, M, N>
where T: Mul<Output = T> + One + Copy,

§

type Output = SMatrix<T, M, N>

The resulting type after applying the * operator.
§

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

Performs the * operation. Read more
§

impl<T, const M: usize, const N: usize> MulAssign<T> for SMatrix<T, M, N>
where T: Mul<Output = T> + One + Copy,

§

fn mul_assign(&mut self, rhs: T)

Performs the *= operation. Read more
§

impl<T, const M: usize, const N: usize> Neg for SMatrix<T, M, N>
where T: Neg<Output = T> + Zero + Copy,

§

type Output = SMatrix<T, M, N>

The resulting type after applying the - operator.
§

fn neg(self) -> Self::Output

Performs the unary - operation. Read more
§

impl<T, const N: usize> One for SMatrix<T, N, N>
where T: Add<Output = T> + Copy + Zero + One,

§

fn one() -> Self

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

fn set_one(&mut self)

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

fn is_one(&self) -> bool
where Self: PartialEq,

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

impl<T: PartialEq, const M: usize, const N: usize> PartialEq for SMatrix<T, M, N>

§

fn eq(&self, other: &SMatrix<T, M, N>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
§

impl<T, const M: usize, const N: usize> Sub for SMatrix<T, M, N>
where T: Add<Output = T> + Sub<Output = T> + Neg<Output = T> + Zero + Copy,

§

type Output = SMatrix<T, M, N>

The resulting type after applying the - operator.
§

fn sub(self, rhs: SMatrix<T, M, N>) -> Self::Output

Performs the - operation. Read more
§

impl<T, const M: usize, const N: usize> SubAssign for SMatrix<T, M, N>
where T: Add<Output = T> + Sub<Output = T> + Neg<Output = T> + Zero + Copy,

§

fn sub_assign(&mut self, rhs: SMatrix<T, M, N>)

Performs the -= operation. Read more
§

impl<T, const M: usize, const N: usize> Zero for SMatrix<T, M, N>
where T: PartialEq + Copy + Zero,

§

fn zero() -> Self

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

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

impl<T: Copy, const M: usize, const N: usize> Copy for SMatrix<T, M, N>

§

impl<T, const M: usize, const N: usize> StructuralPartialEq for SMatrix<T, M, N>

Auto Trait Implementations§

§

impl<T, const M: usize, const N: usize> Freeze for SMatrix<T, M, N>
where T: Freeze,

§

impl<T, const M: usize, const N: usize> RefUnwindSafe for SMatrix<T, M, N>
where T: RefUnwindSafe,

§

impl<T, const M: usize, const N: usize> Send for SMatrix<T, M, N>
where T: Send,

§

impl<T, const M: usize, const N: usize> Sync for SMatrix<T, M, N>
where T: Sync,

§

impl<T, const M: usize, const N: usize> Unpin for SMatrix<T, M, N>
where T: Unpin,

§

impl<T, const M: usize, const N: usize> UnwindSafe for SMatrix<T, M, N>
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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
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.