[−][src]Struct sized_matrix::Matrix
An M
by N
matrix of T
s.
Examples
Multiplying two matrices of different sizes:
use sized_matrix::Matrix; let a: Matrix<i32, 3, 4> = Matrix::rows([ [ 1, 2, 3, 4], [ 5, 6, 7, 8], [ 9, 10, 11, 12], ]); let b: Matrix<i32, 4, 2> = Matrix::rows([ [ 0, 1], [ 1, 2], [ 3, 5], [ 8, 13], ]); let c: Matrix<i32, 3, 2> = a * b; assert_eq!(c, Matrix::rows([ [ 43, 72], [ 91, 156], [139, 240], ]));
Implementations
impl<T, const M: usize, const N: usize> Matrix<T, M, N>
[src]
pub fn cols(cols: [[T; M]; N]) -> Self
[src]
Construct a matrix from an array of columns of values.
Examples
Constructing a matrix from columns:
use sized_matrix::Matrix; let matrix = Matrix::cols([ [1, 3], [2, 4], ]); assert_eq!(matrix[[0, 0]], 1); assert_eq!(matrix[[0, 1]], 2); assert_eq!(matrix[[1, 0]], 3); assert_eq!(matrix[[1, 1]], 4);
pub fn rows(rows: [[T; N]; M]) -> Self
[src]
Construct a matrix from an array of rows of values.
Examples
Constructing a matrix from rows:
use sized_matrix::Matrix; let matrix = Matrix::rows([ [1, 2], [3, 4], ]); assert_eq!(matrix[[0, 0]], 1); assert_eq!(matrix[[0, 1]], 2); assert_eq!(matrix[[1, 0]], 3); assert_eq!(matrix[[1, 1]], 4);
pub fn from_vectors(vectors: [Vector<T, M>; N]) -> Self
[src]
Construct a matrix from an array of column vectors.
Examples
Applying a transformation to the points of a square:
use sized_matrix::Matrix; let points = [ Matrix::vector([0.0, 0.0]), Matrix::vector([0.0, 1.0]), Matrix::vector([1.0, 1.0]), Matrix::vector([1.0, 0.0]), ]; let shear = Matrix::rows([ [1.0, 0.3], [0.0, 1.0], ]); let transformed = (shear * Matrix::from_vectors(points)).to_vectors(); assert_eq!(transformed, [ Matrix::vector([0.0, 0.0]), Matrix::vector([0.3, 1.0]), Matrix::vector([1.3, 1.0]), Matrix::vector([1.0, 0.0]), ]);
pub fn to_vectors(self) -> [Vector<T, M>; N]
[src]
Retrieve an array of column vectors from a matrix.
Examples
Applying a transformation to the points of a square:
use sized_matrix::Matrix; let points = [ Matrix::vector([0.0, 0.0]), Matrix::vector([0.0, 1.0]), Matrix::vector([1.0, 1.0]), Matrix::vector([1.0, 0.0]), ]; let shear = Matrix::rows([ [1.0, 0.3], [0.0, 1.0], ]); let transformed = (shear * Matrix::from_vectors(points)).to_vectors(); assert_eq!(transformed, [ Matrix::vector([0.0, 0.0]), Matrix::vector([0.3, 1.0]), Matrix::vector([1.3, 1.0]), Matrix::vector([1.0, 0.0]), ]);
pub fn swap_row(&mut self, i: usize, j: usize)
[src]
Swap two rows of a matrix.
pub fn swap_col(&mut self, i: usize, j: usize)
[src]
Swap two columns of a matrix.
impl<T, const M: usize> Matrix<T, M, 1_usize>
[src]
pub fn vector(contents: [T; M]) -> Self
[src]
Construct a column vector from an array.
Examples
Constructing a Vector
:
use sized_matrix::{Vector, Matrix}; let vector: Vector<i32, 3> = Vector::vector([1, 2, 3]); assert_eq!(vector, Matrix::cols([[1, 2, 3]]));
Trait Implementations
impl<TLhs: Copy, TRhs: Copy, TOutput, const M: usize, const N: usize> Add<Matrix<TRhs, M, N>> for Matrix<TLhs, M, N> where
TLhs: Add<TRhs, Output = TOutput>,
[src]
TLhs: Add<TRhs, Output = TOutput>,
type Output = Matrix<TOutput, M, N>
The resulting type after applying the +
operator.
fn add(self, rhs: Matrix<TRhs, M, N>) -> Self::Output
[src]
impl<TLhs: Copy, TRhs: Copy, const M: usize, const N: usize> AddAssign<Matrix<TRhs, M, N>> for Matrix<TLhs, M, N> where
Self: Add<Matrix<TRhs, M, N>, Output = Self>,
[src]
Self: Add<Matrix<TRhs, M, N>, Output = Self>,
fn add_assign(&mut self, rhs: Matrix<TRhs, M, N>)
[src]
impl<T: Clone, const M: usize, const N: usize> Clone for Matrix<T, M, N>
[src]
impl<T: Copy, const M: usize, const N: usize> Copy for Matrix<T, M, N>
[src]
impl<T, const M: usize, const N: usize> Debug for Matrix<T, M, N> where
T: Debug,
[src]
T: Debug,
impl<T, const M: usize, const N: usize> Default for Matrix<T, M, N> where
T: Default,
[src]
T: Default,
impl<TLhs: Copy, TRhs: Copy, const M: usize, const N: usize> Div<Matrix<TRhs, N, N>> for Matrix<TLhs, M, N> where
TLhs: MulAdd<TRhs, TLhs, Output = TLhs> + DivAssign<TRhs>,
TRhs: Zero + MulAdd<TRhs, TRhs, Output = TRhs> + DivAssign<TRhs> + Neg<Output = TRhs>,
[src]
TLhs: MulAdd<TRhs, TLhs, Output = TLhs> + DivAssign<TRhs>,
TRhs: Zero + MulAdd<TRhs, TRhs, Output = TRhs> + DivAssign<TRhs> + Neg<Output = TRhs>,
Matrix
-Matrix
division.
This performs a generalised Gauss-Jordan elimination to calculate self * rhs^-1
.
This is slightly more efficient than calculating the inverse then multiplying, as the
Gauss-Jordan method of finding an inverse involves multiplying the identity matrix by the
inverse of the matrix, so you can replace this identity matrix with another matrix to get an
extra multiplication 'for free'. Inversion is then defined as A^-1 = 1 / A
.
type Output = Self
The resulting type after applying the /
operator.
fn div(self, rhs: Matrix<TRhs, N, N>) -> Self::Output
[src]
impl<TLhs: Copy, TRhs: Copy, TOutput, const M: usize, const N: usize> Div<TRhs> for Matrix<TLhs, M, N> where
TLhs: Div<TRhs, Output = TOutput>,
TRhs: Scalar,
[src]
TLhs: Div<TRhs, Output = TOutput>,
TRhs: Scalar,
Matrix
-Scalar
division.
type Output = Matrix<TOutput, M, N>
The resulting type after applying the /
operator.
fn div(self, rhs: TRhs) -> Self::Output
[src]
impl<T: Copy, const M: usize, const N: usize> DivAssign<Matrix<T, N, N>> for Matrix<T, M, N> where
Self: Div<Matrix<T, N, N>, Output = Self>,
[src]
Self: Div<Matrix<T, N, N>, Output = Self>,
Matrix
-Matrix
division.
fn div_assign(&mut self, rhs: Matrix<T, N, N>)
[src]
impl<TLhs: Copy, TRhs: Copy, const M: usize, const N: usize> DivAssign<TRhs> for Matrix<TLhs, M, N> where
Self: Div<TRhs, Output = Matrix<TLhs, M, N>>,
TRhs: Scalar,
[src]
Self: Div<TRhs, Output = Matrix<TLhs, M, N>>,
TRhs: Scalar,
Matrix
-Scalar
division.
fn div_assign(&mut self, rhs: TRhs)
[src]
impl<TLhs: Copy, TRhs: Copy, TOutput, const M: usize> Dot<Matrix<TRhs, M, 1_usize>> for Vector<TLhs, M> where
TLhs: Mul<TRhs, Output = TOutput> + MulAdd<TRhs, TOutput, Output = TOutput>,
TOutput: Zero,
[src]
TLhs: Mul<TRhs, Output = TOutput> + MulAdd<TRhs, TOutput, Output = TOutput>,
TOutput: Zero,
impl<T, const M: usize, const N: usize> Eq for Matrix<T, M, N> where
T: Eq,
[src]
T: Eq,
impl<T, const M: usize, const N: usize> Hash for Matrix<T, M, N> where
T: Hash,
[src]
T: Hash,
fn hash<H: Hasher>(&self, state: &mut H)
[src]
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl<T, const M: usize, const N: usize> Index<[usize; 2]> for Matrix<T, M, N>
[src]
impl<T, const M: usize, const N: usize> IndexMut<[usize; 2]> for Matrix<T, M, N>
[src]
impl<T, const M: usize, const N: usize> Init<T, [usize; 2], ()> for Matrix<T, M, N>
[src]
fn init_with<F: FnMut([usize; 2]) -> T>(_: (), elem: F) -> Self
[src]
fn init<F>(elem: F) -> Self where
F: FnMut(I) -> T,
V: TypeEquals<()>,
[src]
F: FnMut(I) -> T,
V: TypeEquals<()>,
impl<T: Copy, const N: usize> Inv for Matrix<T, N, N> where
Self: One + Div<Self, Output = Self>,
[src]
Self: One + Div<Self, Output = Self>,
impl<T, const M: usize, const N: usize> Map for Matrix<T, M, N>
[src]
type TFrom = T
The type of values being mapped over.
type TOut = Matrix<TTo, M, N>
The generic type of the result after mapping.
fn map<TTo, F: FnMut(Self::TFrom) -> TTo>(self, f: F) -> Self::TOut
[src]
impl<TLhs: Copy, TRhs: Copy, TOutput, const M: usize, const K: usize, const N: usize> Mul<Matrix<TRhs, K, N>> for Matrix<TLhs, M, K> where
TLhs: Mul<TRhs, Output = TOutput> + MulAdd<TRhs, TOutput, Output = TOutput>,
TOutput: Zero,
[src]
TLhs: Mul<TRhs, Output = TOutput> + MulAdd<TRhs, TOutput, Output = TOutput>,
TOutput: Zero,
Matrix
-Matrix
multiplication.
type Output = Matrix<TOutput, M, N>
The resulting type after applying the *
operator.
fn mul(self, rhs: Matrix<TRhs, K, N>) -> Self::Output
[src]
impl<TLhs: Copy, TRhs: Copy, TOutput, const M: usize, const N: usize> Mul<TRhs> for Matrix<TLhs, M, N> where
TLhs: Mul<TRhs, Output = TOutput>,
TRhs: Scalar,
[src]
TLhs: Mul<TRhs, Output = TOutput>,
TRhs: Scalar,
Matrix
-Scalar
multiplication.
type Output = Matrix<TOutput, M, N>
The resulting type after applying the *
operator.
fn mul(self, rhs: TRhs) -> Self::Output
[src]
impl<TLhs: Copy, TA: Copy, TB: Copy, const M: usize, const K: usize, const N: usize> MulAdd<Matrix<TA, K, N>, Matrix<TB, M, N>> for Matrix<TLhs, M, K> where
TLhs: MulAdd<TA, TB, Output = TB>,
[src]
TLhs: MulAdd<TA, TB, Output = TB>,
type Output = Matrix<TB, M, N>
The resulting type after applying the fused multiply-add.
fn mul_add(self, a: Matrix<TA, K, N>, b: Matrix<TB, M, N>) -> Self::Output
[src]
impl<TLhs: Copy, TA: Copy, TB: Copy, const M: usize, const N: usize> MulAddAssign<Matrix<TA, N, N>, Matrix<TB, M, N>> for Matrix<TLhs, M, N> where
Self: MulAdd<Matrix<TA, N, N>, Matrix<TB, M, N>, Output = Self>,
[src]
Self: MulAdd<Matrix<TA, N, N>, Matrix<TB, M, N>, Output = Self>,
fn mul_add_assign(&mut self, a: Matrix<TA, N, N>, b: Matrix<TB, M, N>)
[src]
impl<TLhs: Copy, TRhs: Copy, const M: usize, const N: usize> MulAssign<Matrix<TRhs, N, N>> for Matrix<TLhs, M, N> where
Self: Mul<Matrix<TRhs, N, N>, Output = Self>,
[src]
Self: Mul<Matrix<TRhs, N, N>, Output = Self>,
Matrix
-Matrix
multiplication.
fn mul_assign(&mut self, rhs: Matrix<TRhs, N, N>)
[src]
impl<TLhs: Copy, TRhs: Copy, const M: usize, const N: usize> MulAssign<TRhs> for Matrix<TLhs, M, N> where
Self: Mul<TRhs, Output = Matrix<TLhs, M, N>>,
TRhs: Scalar,
[src]
Self: Mul<TRhs, Output = Matrix<TLhs, M, N>>,
TRhs: Scalar,
Matrix
-Scalar
multiplication.
fn mul_assign(&mut self, rhs: TRhs)
[src]
impl<T: Copy, TOutput, const M: usize, const N: usize> Neg for Matrix<T, M, N> where
T: Neg<Output = TOutput>,
[src]
T: Neg<Output = TOutput>,
type Output = Matrix<TOutput, M, N>
The resulting type after applying the -
operator.
fn neg(self) -> Self::Output
[src]
impl<T: Copy, const N: usize> One for Matrix<T, N, N> where
T: Zero + One + MulAdd<Output = T>,
[src]
T: Zero + One + MulAdd<Output = T>,
fn one() -> Self
[src]
fn set_one(&mut self)
[src]
fn is_one(&self) -> bool where
Self: PartialEq<Self>,
[src]
Self: PartialEq<Self>,
impl<T, const M: usize, const N: usize> PartialEq<Matrix<T, M, N>> for Matrix<T, M, N> where
T: PartialEq,
[src]
T: PartialEq,
fn eq(&self, rhs: &Matrix<T, M, N>) -> bool
[src]
#[must_use]fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
impl<T: Copy, TRhs, const N: usize> Pow<TRhs> for Matrix<T, N, N> where
Self: Inv<Output = Self> + One + MulAssign<Self>,
TRhs: PrimInt,
[src]
Self: Inv<Output = Self> + One + MulAssign<Self>,
TRhs: PrimInt,
type Output = Self
The result after applying the operator.
fn pow(self, rhs: TRhs) -> Self::Output
[src]
impl<T, const M: usize, const N: usize> !Scalar for Matrix<T, M, N>
[src]
impl<TLhs: Copy, TRhs: Copy, TOutput, const M: usize, const N: usize> Sub<Matrix<TRhs, M, N>> for Matrix<TLhs, M, N> where
TLhs: Sub<TRhs, Output = TOutput>,
[src]
TLhs: Sub<TRhs, Output = TOutput>,
type Output = Matrix<TOutput, M, N>
The resulting type after applying the -
operator.
fn sub(self, rhs: Matrix<TRhs, M, N>) -> Self::Output
[src]
impl<TLhs: Copy, TRhs: Copy, const M: usize, const N: usize> SubAssign<Matrix<TRhs, M, N>> for Matrix<TLhs, M, N> where
Self: Sub<Matrix<TRhs, M, N>, Output = Self>,
[src]
Self: Sub<Matrix<TRhs, M, N>, Output = Self>,
fn sub_assign(&mut self, rhs: Matrix<TRhs, M, N>)
[src]
impl<T, const M: usize, const N: usize> Transpose for Matrix<T, M, N>
[src]
impl<T: Copy, const M: usize, const N: usize> Zero for Matrix<T, M, N> where
T: Zero,
[src]
T: Zero,
Auto Trait Implementations
impl<T, const M: usize, const N: usize> RefUnwindSafe for Matrix<T, M, N> where
T: RefUnwindSafe,
T: RefUnwindSafe,
impl<T, const M: usize, const N: usize> Send for Matrix<T, M, N> where
T: Send,
T: Send,
impl<T, const M: usize, const N: usize> Sync for Matrix<T, M, N> where
T: Sync,
T: Sync,
impl<T, const M: usize, const N: usize> Unpin for Matrix<T, M, N> where
T: Unpin,
T: Unpin,
impl<T, const M: usize, const N: usize> UnwindSafe for Matrix<T, M, N> where
T: UnwindSafe,
T: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,