[−][src]Struct mtrs::Matrix
The main Matrix struct. Can be created in a variety of different ways.
#[macro_use] extern crate mtrs; use mtrs::Matrix; // All of these create a 2 x 2 matrix. // From a 2D vector let matrix = Matrix::from_vec(2, 2, vec![1, 2, 3, 4]); // Identity matrix of i32 let matrix: Matrix<i32> = Matrix::identity(2); // Matrix of ones let matrix: Matrix<i32> = Matrix::ones(2, 2); // Matrix of zeros let matrix: Matrix<i32> = Matrix::zeros(2, 2); // Matrix of `i32`s let matrix = matrix![(2, 2); 1, 2, 3, 4]; // Matrix of `f64`s let matrix = matrix![f64; (2, 2); 1, 2; 3, 4];
Implementations
impl<T: Num + Clone + Copy> Matrix<T>
[src]
pub fn transpose(&mut self)
[src]
Transposes the matrix, via mutating the original data. Does not return a new struct, instead modifies the old one.
#[macro_use] extern crate mtrs; let mut matrix = matrix![(2, 2); 1, 2; 3, 4]; matrix.transpose(); assert_eq!(matrix, matrix![(2, 2); 1, 3; 2, 4]);
pub fn scalar_add(&self, value: T) -> Self
[src]
Add a scalar constant to the matrix
pub fn scalar_sub(&self, value: T) -> Self
[src]
Subtract a scalar constant from the matrix
pub fn scalar_mul(&self, value: T) -> Self
[src]
Multiply a scalar constant with the matrix
pub fn scalar_div(&self, value: T) -> Self
[src]
Divide each entry in the matrix by a scalar constant
pub fn determinant(&self) -> Option<T>
[src]
Calculate the determinant of the Matrix
(if the Matrix
is square)
pub fn inverse(&self) -> Option<Self>
[src]
Calculate the inverse of Matrix<T>
, via multiplying the reciprocal of the determinant
impl<T: Num + Clone + Copy> Matrix<T>
[src]
pub fn identity(size: usize) -> Self
[src]
Creates a new identity matrix of size N * N
use mtrs::Matrix; let matrix: Matrix<i32> = Matrix::identity(2); assert_eq!(matrix.as_slice(), &[1, 0, 0, 1]); assert_eq!(matrix.size(), (2, 2));
pub fn from_vec(height: usize, width: usize, body: Vec<T>) -> Self
[src]
Creates a new matrix from a pre-given size, passing a 2d Vec<T>
use mtrs::Matrix; let matrix = Matrix::from_vec(2, 2, vec![1, 2, 7, 6]); assert_eq!(matrix.as_slice(), &[1, 2, 7, 6]);
pub fn zeros(height: usize, width: usize) -> Self
[src]
Create a Matrix<i32>
of size M * N
filled with 0
s
use mtrs::Matrix; let matrix = Matrix::zeros(2, 2); assert_eq!(matrix.as_slice(), &[0, 0, 0, 0]); assert_eq!(matrix, Matrix::from_vec(2, 2, vec![0, 0, 0, 0]));
pub fn ones(height: usize, width: usize) -> Self
[src]
Create a Matrix<i32>
of size M * N
filled with 1
s
use mtrs::Matrix; let matrix = Matrix::ones(2, 2); assert_eq!(matrix.as_slice(), &[1, 1, 1, 1]); assert_eq!(matrix, Matrix::from_vec(2, 2, vec![1, 1, 1, 1]));
pub fn size(&self) -> (usize, usize)
[src]
Returns a tuple representing the dimensions ((height, width)
)
use mtrs::Matrix; let matrix: Matrix<i32> = Matrix::ones(2, 3); assert_eq!(matrix.size(), (2, 3));
pub fn as_slice(&self) -> &[T]
[src]
Wrapper function for self.data.as_slice()
pub fn as_mut_slice(&mut self) -> &mut [T]
[src]
Wrapper function for self.data.as_mut_slice()
pub fn as_ptr(&self) -> *const T
[src]
Wrapper function for self.data.as_ptr()
pub fn as_mut_ptr(&mut self) -> *const T
[src]
Wrapper function for self.data.as_mut_ptr()
pub fn as_vec(&self) -> Vec<Vec<T>>
[src]
Return a Vec
representation of the Matrix
use mtrs::Matrix; let matrix = Matrix::from_vec(2, 2, vec![2, 1, 4, 3]); assert_eq!(matrix.as_vec(), vec![vec![2, 1], vec![4, 3]]);
pub fn cols(&self) -> Vec<Vec<T>>
[src]
Returns a Vec
of all the columns
Trait Implementations
impl<T: Num + Clone + Copy> Add<Matrix<T>> for Matrix<T>
[src]
Perform addition using the +
operator
type Output = Self
The resulting type after applying the +
operator.
fn add(self, other: Self) -> Self
[src]
impl<T: Clone + Num> Clone for Matrix<T>
[src]
impl<T: Debug + Num> Debug for Matrix<T>
[src]
impl<T> Display for Matrix<T> where
T: Num + Clone + Copy + Display,
[src]
T: Num + Clone + Copy + Display,
Pretty print of the Matrix
via this impl
extern crate mtrs; use mtrs::Matrix; let matrix: Matrix<i32> = Matrix::identity(3); println!("{}", matrix);
impl<T: Num> Index<(usize, usize)> for Matrix<T>
[src]
Allows for the indexing of Matrix
extern crate mtrs; use mtrs::Matrix; let matrix: Matrix<u8> = Matrix::identity(3); assert_eq!(matrix[(1, 1)], 1);
type Output = T
The returned type after indexing.
fn index(&self, pos: (usize, usize)) -> &Self::Output
[src]
impl<T: Num + Clone + Copy> Mul<Matrix<T>> for Matrix<T>
[src]
Perform multiplication using the *
operator
type Output = Self
The resulting type after applying the *
operator.
fn mul(self, other: Self) -> Self
[src]
impl<T: PartialEq + Num> PartialEq<Matrix<T>> for Matrix<T>
[src]
impl<T: Num> StructuralPartialEq for Matrix<T>
[src]
impl<T: Num + Clone + Copy> Sub<Matrix<T>> for Matrix<T>
[src]
Perform subtraction using the -
operator
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> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
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>,