[][src]Struct aljabar::Matrix

#[repr(transparent)]
pub struct Matrix<T, const N: usize, const M: usize>(_);

An N-by-M Column Major matrix.

Matrices can be created from arrays of Vectors of any size and scalar type. As with Vectors there are convenience constructor functions for square matrices of the most common sizes.

This example is not tested
let a = Matrix::<f32, 3, 3>::from( [ vec3( 1.0, 0.0, 0.0 ),
                                     vec3( 0.0, 1.0, 0.0 ),
                                     vec3( 0.0, 0.0, 1.0 ), ] );
let b: Matrix::<i32, 3, 3> =
            mat3x3( 0, -3, 5,
                    6, 1, -4,
                    2, 3, -2 );

All operations performed on matrices produce fixed-size outputs. For example, taking the transpose of a non-square matrix will produce a matrix with the width and height swapped:

This example is not tested
assert_eq!(
    Matrix::<i32, 1, 2>::from( [ vec1( 1 ), vec1( 2 ) ] )
        .transpose(),
    Matrix::<i32, 2, 1>::from( [ vec2( 1, 2 ) ] )
);

Indexing

Matrices can be indexed by either their native column major storage or by the more natural row major method. In order to use row-major indexing, call .index or .index_mut on the matrix with a pair of indices. Calling .index. with a single index will produce a Vector representing the appropriate column of the matrix.

This example is not tested
let m: Matrix::<i32, 2, 2> =
           mat2x2( 0, 2,
                   1, 3 );

// Column-major indexing:
assert_eq!(m[0][0], 0);
assert_eq!(m[0][1], 1);
assert_eq!(m[1][0], 2);
assert_eq!(m[1][1], 3);

// Row-major indexing:
assert_eq!(m[(0, 0)], 0);
assert_eq!(m[(1, 0)], 1);
assert_eq!(m[(0, 1)], 2);
assert_eq!(m[(1, 1)], 3);

Methods

impl<T, const N: usize, const M: usize> Matrix<T, { N }, { M }>[src]

pub fn transpose(self) -> Matrix<T, { M }, { N }>[src]

Returns the transpose of the matrix.

Trait Implementations

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

impl<T, const N: usize> One for Matrix<T, { N }, { N }> where
    T: Zero + One + Clone,
    Self: PartialEq<Self> + SquareMatrix<T, { N }>, 
[src]

Constructs a unit matrix.

impl<Scalar, const N: usize> SquareMatrix<Scalar, N> for Matrix<Scalar, { N }, { N }> where
    Scalar: Clone + One,
    Scalar: Add<Scalar, Output = Scalar> + Sub<Scalar, Output = Scalar>,
    Scalar: Mul<Scalar, Output = Scalar>,
    Self: Add<Self>,
    Self: Sub<Self>,
    Self: Mul<Self>,
    Self: Mul<Vector<Scalar, { N }>, Output = Vector<Scalar, { N }>>, 
[src]

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

fn clone_from(&mut self, source: &Self)1.0.0[src]

Performs copy-assignment from source. Read more

impl<T, const N: usize> From<Matrix<T, N, 1>> for Vector<T, { N }>[src]

impl<T, const N: usize, const M: usize> From<[Vector<T, N>; M]> for Matrix<T, { N }, { M }>[src]

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

impl<A, B, RHS, const N: usize, const M: usize> PartialEq<RHS> for Matrix<A, { N }, { M }> where
    RHS: Deref<Target = [Vector<B, { N }>; {M}]>,
    A: PartialEq<B>, 
[src]

#[must_use] fn ne(&self, other: &Rhs) -> bool1.0.0[src]

This method tests for !=.

impl<T, const N: usize, const M: usize> DerefMut for Matrix<T, { N }, { M }>[src]

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

fn hash_slice<H>(data: &[Self], state: &mut H) where
    H: Hasher
1.3.0[src]

Feeds a slice of this type into the given [Hasher]. Read more

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

I'm not quite sure how to format the debug output for a matrix.

impl<A, B, const N: usize, const M: usize> Add<Matrix<B, N, M>> for Matrix<A, { N }, { M }> where
    A: Add<B>, 
[src]

Element-wise addition of two equal sized matrices.

type Output = Matrix<<A as Add<B>>::Output, { N }, { M }>

The resulting type after applying the + operator.

impl<A, B, const N: usize, const M: usize> Sub<Matrix<B, N, M>> for Matrix<A, { N }, { M }> where
    A: Sub<B>, 
[src]

Element-wise subtraction of two equal sized matrices.

type Output = Matrix<<A as Sub<B>>::Output, { N }, { M }>

The resulting type after applying the - operator.

impl<T, const N: usize, const M: usize, const P: usize> Mul<Matrix<T, M, P>> for Matrix<T, { N }, { M }> where
    T: Add<T, Output = T> + Mul<T, Output = T> + Clone,
    Vector<T, { M }>: InnerSpace
[src]

type Output = Matrix<<Vector<T, { M }> as VectorSpace>::Scalar, { N }, { P }>

The resulting type after applying the * operator.

impl<T, const N: usize, const M: usize> Mul<Vector<T, M>> for Matrix<T, { N }, { M }> where
    T: Add<T, Output = T> + Mul<T, Output = T> + Clone,
    Vector<T, { M }>: InnerSpace
[src]

type Output = Vector<<Vector<T, { M }> as VectorSpace>::Scalar, { N }>

The resulting type after applying the * operator.

impl<T, const N: usize, const M: usize> Mul<T> for Matrix<T, { N }, { M }> where
    T: Mul<T, Output = T> + Clone
[src]

Scalar multiply

type Output = Matrix<T, { N }, { M }>

The resulting type after applying the * operator.

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

type Output = Matrix<<T as Neg>::Output, { N }, { M }>

The resulting type after applying the - operator.

impl<A, B, const N: usize, const M: usize> AddAssign<Matrix<B, N, M>> for Matrix<A, { N }, { M }> where
    A: AddAssign<B>, 
[src]

impl<A, B, const N: usize, const M: usize> SubAssign<Matrix<B, N, M>> for Matrix<A, { N }, { M }> where
    A: SubAssign<B>, 
[src]

impl<T, const N: usize, const M: usize> Deref for Matrix<T, { N }, { M }>[src]

type Target = [Vector<T, { N }>; {M}]

The resulting type after dereferencing.

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

type Output = Vector<T, { N }>

The returned type after indexing.

impl<T, const N: usize, const M: usize> Index<(usize, usize)> for Matrix<T, { N }, { M }>[src]

type Output = T

The returned type after indexing.

impl<T, const N: usize, const M: usize> IndexMut<usize> for Matrix<T, { N }, { M }>[src]

impl<T, const N: usize, const M: usize> IndexMut<(usize, usize)> for Matrix<T, { N }, { M }>[src]

Auto Trait Implementations

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

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

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

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

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

Blanket Implementations

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

impl<T> From<T> for 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.

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

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

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