Struct matrix_lib::Matrix

source ·
pub struct Matrix<T> { /* private fields */ }

Implementations§

source§

impl<T> Matrix<T>where T: Add<Output = T> + Sub<Output = T> + Mul<Output = T> + Div<Output = T> + Neg<Output = T> + AddAssign + SubAssign + MulAssign + DivAssign + Clone + One + Zero + PartialEq + Copy + ToPrimitive + Send + 'static,

source

pub async fn par_scalar_mul(self, scalar: T) -> Matrix<T>

source

pub async fn par_mul(self, other: Matrix<T>) -> Result<Matrix<T>, String>

source

pub async fn par_sum(self, other: Matrix<T>) -> Result<Matrix<T>, String>

source§

impl<T> Matrix<T>where T: Add<Output = T> + Sub<Output = T> + Mul<Output = T> + Div<Output = T> + Neg<Output = T> + AddAssign + SubAssign + MulAssign + DivAssign + Clone + One + Zero + PartialEq + Copy + ToPrimitive,

source

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

Creates a new Matrix<T>.

Panics

Panics if rows of matrix are different size. example: matrix![[1, 2, 3], [4,5]]

source

pub fn sum(&self, other: Matrix<T>) -> Result<Self, String>

Sums two matrices of same size.

Errors

This function will return an error if matrices are different sizes.

examples:

use matrix_lib::*;
let m1 = matrix![[1,2,3], [4,5,6]];
let m2 = matrix![[1,2], [3,4], [5,6]];
assert!(matches!(m1.sum(m2), Err(String)));

will not sum successfully

Examples of correct usage
use matrix_lib::*;
let m1 = matrix![[1,2,3], [4,5,6]];
let m2 = matrix![[1,2,3], [4,5,6]];
assert_eq!(matrix![[2,4,6], [8,10,12]], m1.sum(m2).unwrap());
source

pub fn mul(&self, other: Matrix<T>) -> Result<Self, String>

Multiplies two matrices.

Errors

ERRORS WIP IN THIS FUNCTION This function will return an error if …

source

pub fn scalar_mul(&self, scalar: T) -> Self

Multiplies two matrices.

source

pub fn transpose(&self) -> Matrix<T>

Returns the transpose of this Matrix<T>.

source

pub fn gaussian_elimination(&self) -> Matrix<f64>

Returns the gaussian elimination of this Matrix<T>.

Panics

Panics if type T is not convertable to f64 as f64 is needed to calculate this correctly.

source

pub fn determinant(&self) -> Result<f64, String>

Returns the determinant of this Matrix<T>.

Errors

This function will return an error if matrix is not square.

source

pub fn vectorize(&self) -> Vec<T>

Returns the vectorize of this Matrix<T>.

source

pub fn from_vectorized(v: Vec<T>, columns: usize) -> Matrix<T>

Generates Matrix<T> from provided vector.

Example
use matrix_lib::*;
let v = vec![1, 2, 3, 4, 5, 6, 7, 8, 9];
assert_eq!(matrix![1,4,7;2,5,8;3,6,9], Matrix::from_vectorized(v, 3));
source

pub fn inverse(&self) -> Result<Matrix<f64>, String>

Returns the inverse of this Matrix<T>.

Panics

Panics if type T is not convertable to f64 as f64 is needed to calculate this correctly.

Errors

This function will return an error if matrix is not suqare or determinant from given matrix is equal to 0.

source

pub fn get_size(&self) -> Size

Returns the get size of this Matrix<T>.

Example
use matrix_lib::*;
use matrix_lib::functions::Size;
let m = matrix![1,2,3;4,5,6;7,8,9;10,11,12];
assert_eq!(m.get_size(), Size{x: 3, y: 4});

Trait Implementations§

source§

impl<T: Clone> Clone for Matrix<T>

source§

fn clone(&self) -> Matrix<T>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<T: Debug> Debug for Matrix<T>

source§

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

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

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

source§

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

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

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

source§

fn eq(&self, other: &Matrix<T>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<T: Eq> Eq for Matrix<T>

source§

impl<T> StructuralEq for Matrix<T>

source§

impl<T> StructuralPartialEq for Matrix<T>

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§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for Twhere T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.