[−][src]Struct math_concept::lalg::matrix::Matrix
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]
T: Copy + Add<Output = T> + Div<Output = T>,
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]
U: Copy + Add<Output = U> + Div<Output = U>,
F: Fn(&T) -> U,
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]
T: Copy + Add<Output = T> + Div<Output = T>,
type Output = Matrix<T>
The resulting type after applying the +
operator.
fn add(self, other: Self) -> Self::Output
[src]
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]
T: Copy + Add<Output = T> + AddAssign<T> + Mul<Output = T> + Div<Output = T> + Default,
Auto Trait Implementations
impl<T> RefUnwindSafe for Matrix<T> where
T: RefUnwindSafe,
T: RefUnwindSafe,
impl<T> Send for Matrix<T> where
T: Send,
T: Send,
impl<T> Sync for Matrix<T> where
T: Sync,
T: Sync,
impl<T> Unpin for Matrix<T> where
T: Unpin,
T: Unpin,
impl<T> UnwindSafe for Matrix<T> 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, 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>,