[][src]Struct sized_matrix::Matrix

pub struct Matrix<T, const M: usize, const N: usize> { /* fields omitted */ }

An M by N matrix of Ts.

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]

type Output = Matrix<TOutput, M, N>

The resulting type after applying the + operator.

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]

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]

impl<T, const M: usize, const N: usize> Default for Matrix<T, M, N> where
    T: Default
[src]

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]

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.

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]

Matrix-Scalar division.

type Output = Matrix<TOutput, M, N>

The resulting type after applying the / operator.

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]

Matrix-Matrix division.

See Div<Matrix<TRhs, N, N>>

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]

Matrix-Scalar division.

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]

type Output = TOutput

impl<T, const M: usize, const N: usize> Eq for Matrix<T, M, N> where
    T: Eq
[src]

impl<T, const M: usize, const N: usize> Hash for Matrix<T, M, N> where
    T: Hash
[src]

impl<T, const M: usize, const N: usize> Index<[usize; 2]> for Matrix<T, M, N>[src]

type Output = T

The returned type after indexing.

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]

impl<T: Copy, const N: usize> Inv for Matrix<T, N, N> where
    Self: One + Div<Self, Output = Self>, 
[src]

type Output = Self

The result after applying the operator.

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.

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]

Matrix-Matrix multiplication.

type Output = Matrix<TOutput, M, N>

The resulting type after applying the * operator.

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]

Matrix-Scalar multiplication.

type Output = Matrix<TOutput, M, N>

The resulting type after applying the * operator.

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]

type Output = Matrix<TB, M, N>

The resulting type after applying the fused multiply-add.

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]

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]

Matrix-Matrix multiplication.

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]

Matrix-Scalar multiplication.

impl<T: Copy, TOutput, const M: usize, const N: usize> Neg for Matrix<T, M, N> where
    T: Neg<Output = TOutput>, 
[src]

type Output = Matrix<TOutput, M, N>

The resulting type after applying the - operator.

impl<T: Copy, const N: usize> One for Matrix<T, N, N> where
    T: Zero + One + MulAdd<Output = T>, 
[src]

impl<T, const M: usize, const N: usize> PartialEq<Matrix<T, M, N>> for Matrix<T, M, N> where
    T: PartialEq
[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]

type Output = Self

The result after applying the operator.

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]

type Output = Matrix<TOutput, M, N>

The resulting type after applying the - operator.

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]

impl<T, const M: usize, const N: usize> Transpose for Matrix<T, M, N>[src]

type Output = Matrix<T, N, M>

impl<T: Copy, const M: usize, const N: usize> Zero for Matrix<T, M, N> where
    T: Zero
[src]

Auto Trait Implementations

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

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

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

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

impl<T, const M: usize, const N: usize> UnwindSafe for Matrix<T, M, N> where
    T: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.