Skip to main content

Matrix

Struct Matrix 

Source
pub struct Matrix<T> {
    pub rows: Vec<Vec<T>>,
    pub cols: Vec<Vec<T>>,
    pub dims: MatrixDimensions,
}
Expand description

Implementation for a finite-dimensional matrix over T.

Fields§

§rows: Vec<Vec<T>>

Rows of the Matrix

§cols: Vec<Vec<T>>

Columns of the Matrix

§dims: MatrixDimensions

Dimensions of the Matrix

Implementations§

Source§

impl<T> Matrix<T>
where T: Copy,

Source

pub fn new(rows: Vec<Vec<T>>) -> Matrix<T>

Constructs a new Matrix from a nested Vec.

§Panics

This constructor panics in two scenarios. If the provided Vec has no elements, as depicted below,

let _: Matrix<i32> = Matrix::new(vec![]); // panics!

then a Matrix cannot be constructed and a panic issues. If the provided Vec has rows of differing length, then it is similarly impossible to determine the appropriate dimension of the Matrix desired and there is a panic.

let _ = Matrix::new(vec![vec![1, 0], vec![0]]); // panics!
Source§

impl<T> Matrix<T>
where T: Copy + Default + Mul<Output = T> + Add<Output = T>,

Source

pub fn transform(&self, other: &Vector<T>) -> Vector<T>

Transforms a Vector through matrix-vector multiplication with self without transferring ownership.

let v = Vector::new(vec![0, 1]);
let m = Matrix::new(vec![
    vec![2, 0],
    vec![0, 2]
]);
let transformed_v = Vector::new(vec![0, 2]);
assert_eq!(transformed_v, m.transform(&v));

Trait Implementations§

Source§

impl<T> Add for Matrix<T>
where T: Copy + Add<Output = T>,

Source§

type Output = Matrix<T>

The resulting type after applying the + operator.
Source§

fn add(self, other: Self) -> Self

Performs the + operation. Read more
Source§

impl<T> Debug for Matrix<T>
where T: Display,

Source§

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

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

impl<T> Div<T> for Matrix<T>
where T: Copy + Div<Output = T>,

Source§

type Output = Matrix<T>

The resulting type after applying the / operator.
Source§

fn div(self, other: T) -> Self

Performs the / operation. Read more
Source§

impl<T> Index<usize> for Matrix<T>
where T: Clone,

Source§

type Output = Vec<T>

The returned type after indexing.
Source§

fn index(&self, index: usize) -> &Vec<T>

Performs the indexing (container[index]) operation. Read more
Source§

impl<T> Mul for Matrix<T>
where T: Copy + Default + Mul<Output = T> + Add<Output = T>,

Source§

type Output = Matrix<T>

The resulting type after applying the * operator.
Source§

fn mul(self, other: Self) -> Self

Performs the * operation. Read more
Source§

impl<T> Mul<T> for Matrix<T>
where T: Copy + Mul<Output = T>,

Source§

type Output = Matrix<T>

The resulting type after applying the * operator.
Source§

fn mul(self, other: T) -> Self

Performs the * operation. Read more
Source§

impl<T> Mul<Vector<T>> for Matrix<T>
where T: Copy + Default + Mul<Output = T> + Add<Output = T>,

Source§

type Output = Vector<T>

The resulting type after applying the * operator.
Source§

fn mul(self, other: Vector<T>) -> Vector<T>

Performs the * operation. Read more
Source§

impl<T> PartialEq for Matrix<T>
where T: PartialEq,

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<T> Sub for Matrix<T>
where T: Copy + Sub<Output = T>,

Source§

type Output = Matrix<T>

The resulting type after applying the - operator.
Source§

fn sub(self, other: Self) -> Self

Performs the - operation. Read more

Auto Trait Implementations§

§

impl<T> Freeze for Matrix<T>

§

impl<T> RefUnwindSafe for Matrix<T>
where T: RefUnwindSafe,

§

impl<T> Send for Matrix<T>
where T: Send,

§

impl<T> Sync for Matrix<T>
where T: Sync,

§

impl<T> Unpin for Matrix<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for Matrix<T>

§

impl<T> UnwindSafe for Matrix<T>
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> 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, 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.