[][src]Struct math_concept::lalg::matrix::Matrix

pub struct Matrix<T> { /* fields omitted */ }

A representation of a standard Matrix of size r * c

Examples

let mut m = Matrix::new(2, 2, vec![0; 4]);

assert_eq!(m.at(0, 0), 0);

*m.at_mut(1, 1) = 5;
assert_eq!(m.at(1, 1), 5);
let m = Matrix::from_vec(1, 2, &vec![9, 8]);

assert_eq!(&vec![9, 8], m.data());

Methods

impl<T> Matrix<T> where
    T: Copy + Add<Output = T> + Div<Output = T>, 
[src]

pub fn new(r: usize, c: usize, v: Vec<T>) -> Matrix<T>[src]

Constructs a new Matrix<T>, taking ownership of v and using it as the buffer.

pub fn from_vec(r: usize, c: usize, v: &Vec<T>) -> Matrix<T>[src]

Constructs a new Matrix<T>, using v as the buffer without taking ownership of it.

pub fn rows(&self) -> usize[src]

Returns the number of rows of the matrix.

pub fn cols(&self) -> usize[src]

Returns the number of columns of the matrix.

pub fn at(&self, r: usize, c: usize) -> T[src]

Returns the element at the r-th row and c-th column, provided those are within bounds.

pub fn at_mut(&mut self, r: usize, c: usize) -> &mut T[src]

Returns a mutable reference to the element at the r-th row and c-th column, provided those are within bounds.

pub fn data(&self) -> &Vec<T>[src]

Returns a reference to the matrix data vector

pub fn map<U, F>(&self, f: F) -> Matrix<U> where
    U: Copy + Add<Output = U> + Div<Output = U>,
    F: Fn(&T) -> U, 
[src]

Maps over the elements of the matrix.

Example

let m = Matrix::new(2, 2, vec![5; 4]);

let mapped = m.map(|&x| x * 8);
assert_eq!(mapped.data(), &vec![40; 4]);

pub fn diagonal(&self) -> Vec<T>[src]

Produces the diagonal of an 'm x m' matrix. Panics otherwise.

Example

let m = Matrix::new(2, 2, vec![1, 2, 3, 4]);

let diag = m.diagonal();
assert_eq!(diag, vec![1, 4]);

Trait Implementations

impl<'a, T> Add<&'a Matrix<T>> for &'a Matrix<T> where
    T: Copy + Add<Output = T> + Div<Output = T>, 
[src]

type Output = Matrix<T>

The resulting type after applying the + operator.

impl<'a, T> Mul<&'a Matrix<T>> for &'a Matrix<T> where
    T: Copy + Add<Output = T> + AddAssign<T> + Mul<Output = T> + Div<Output = T> + Default
[src]

type Output = Matrix<T>

The resulting type after applying the * operator.

Auto Trait Implementations

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