Struct NmlMatrix

Source
pub struct NmlMatrix<T> {
    pub num_rows: u32,
    pub num_cols: u32,
    pub data: Box<[T]>,
    pub is_square: bool,
}
Expand description

Nml_Matrix represents a matrix with a given number of rows and columns, the Data is stored in a one dimensional array using row-major-ordering (data[i][j] = data_new[i * m +j], where m is the number of columns) The Library contains a few methods to create matrices with or without data.

Fields§

§num_rows: u32§num_cols: u32§data: Box<[T]>§is_square: bool

Implementations§

Source§

impl<T> NmlMatrix<T>

Source

pub fn new(num_rows: u32, num_cols: u32) -> NmlMatrix<T>

creates a matrix without data and reserves the capacity for the Data Vector

Source

pub fn new_with_2d_vec( num_rows: u32, num_cols: u32, data_2d: &mut Vec<Vec<T>>, ) -> Result<Self, NmlError>

use a 2d Vector to initialize the matrix. Each Vector in the 2d Vector is a row and the length of these vectors are the columns

Source

pub fn new_with_data( num_rows: u32, num_cols: u32, data: Box<[T]>, ) -> Result<Self, NmlError>

Constructor that uses a vector to initialize the matrix. checks if the entered rows and columns fit the vector size

Source

pub fn nml_mat_rnd(num_rows: u32, num_cols: u32, minimum: T, maximum: T) -> Self

Returns a matrix with defined size and random data between minimum and maximum values

Source

pub fn nml_mat_sqr(size: u32) -> Self

Creates a square matrix of a given size, where all cells are filled with 0.0

Source

pub fn nml_mat_eye(size: u32) -> Self

creates a identity matrix with the given size

Source

pub fn nml_mat_cp(matrix: &NmlMatrix<T>) -> Self

Creates a new matrix which is a copy of a given matrix. Uses only the reference to the matrix, so that the original matrix is not moved

Source

pub fn equality(&self, matrix: &NmlMatrix<T>) -> bool

Checks if two matrices are equal by checking their dimensions and after that every cell. Method is also used for implementation of trait PatialEq

Source

pub fn equality_in_tolerance(&self, matrix: NmlMatrix<T>, tolerance: T) -> bool

Checks if two matrices are equal with a given tolerance

Source

pub fn at(&self, row: u32, col: u32) -> Result<T, NmlError>

Returns the value a specified at A[i,j]

Source

pub fn get_column(&self, column: u32) -> Result<Self, NmlError>

Returns a result with a specified Column of a matrix, which in itself also is a matrix. If the specified matrix is not in the matrix the result will contain an error

Source

pub fn get_row(&self, row: u32) -> Result<Self, NmlError>

Returns a result which either contains a row of a matrix (which is also a matrix) or a error

Source

pub fn set_value(&mut self, row: u32, col: u32, data: T) -> Result<(), NmlError>

Method sets the value of a given cell in the matrix through a mutable reference

Source

pub fn set_all_values(&mut self, value: T)

Method sets the values of all cells ro a given value

Source

pub fn set_dig_values(&mut self, value: T) -> Result<(), NmlError>

checks if the matrix is square and sets the diagonal values to a given value

Source

pub fn multiply_row_scalar( &mut self, row: u32, scalar: T, ) -> Result<(), NmlError>

multiplies a given row with a given scalar in place. If the row-index is not in the matrix the returned Result will contain an error

Source

pub fn multiply_col_scalar( &mut self, col: u32, scalar: T, ) -> Result<(), NmlError>

multiplies a given column with a given scalar in place. If the row-index is not in the matrix the returned Result will contain an error

Source

pub fn multiply_matrix_scalar(&mut self, scalar: T)

multiplies the matrix in place with a given scalar

Source

pub fn add_rows( &mut self, row_1: u32, scalar_1: T, row_2: u32, scalar_2: T, ) -> Result<(), NmlError>

row_1 is multiplied with scalar_1, this is analog for 2. row_1 will be modified with the solution (row_1 = row_1 * scalar + row_2 * scalar_2)

Source

pub fn swap_rows(&mut self, row_1: u32, row_2: u32) -> Result<(), NmlError>

Method that swaps two given rows of a matrix object in place. Returns either nothing or an NmlError if the specified rows are not in the matrix

Source

pub fn swap_columns(&mut self, col_1: u32, col_2: u32) -> Result<(), NmlError>

Method that swaps two given rows of a matrix object in place. Returns either nothing or an NmlError if the specified rows are not in the matrix

Source

pub fn remove_column(&self, col: u32) -> Result<Self, NmlError>

Tries to remove a column of a matrix and returns the rest of the matrix as a now on. Does not move the original matrix. If the column is not in the original matrix the result will return an error

Source

pub fn remove_row(&self, row: u32) -> Result<Self, NmlError>

Tries to remove a column of a matrix and returns the rest of the matrix as a now on. Does not move the original matrix. If the column is not in the original matrix the result will return an error

Source

pub fn get_sub_mtr( &self, row_start: u32, row_end: u32, col_start: u32, col_end: u32, ) -> Result<Self, NmlError>

Source

pub fn transpose(&self) -> Self

Computes the transpose matrix b’ of a matrix b. This is achieved by going from row-major-ordering to a more efficient storage. The input matrix will not be modified or moved.

Source

pub fn mul_transpose(&self, other: &Self) -> Result<Self, NmlError>

The naive matrix multiplication algorihm applied with the transponse of the one matrix

Source

pub fn mul_naive(&self, other: &Self) -> Result<Self, NmlError>

The naive matrix multiplication algorithm. It iterates trough all values of both matrices. These matrices are not moved or modified

Source

pub fn evcxr_display(&self)

Trait Implementations§

Source§

impl<T> Add for &NmlMatrix<T>

Source§

type Output = Result<NmlMatrix<T>, NmlError>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Self) -> Self::Output

Performs the + operation. Read more
Source§

impl<T> Add for NmlMatrix<T>

Source§

type Output = Result<NmlMatrix<T>, NmlError>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Self) -> Self::Output

Performs the + operation. Read more
Source§

impl<T: Debug> Debug for NmlMatrix<T>

Source§

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

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

impl<T> Display for NmlMatrix<T>

Source§

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

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

impl<T> Mul for NmlMatrix<T>

Source§

type Output = Result<NmlMatrix<T>, NmlError>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Self) -> Self::Output

Performs the * operation. Read more
Source§

impl<T> PartialEq for NmlMatrix<T>

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T> Sub for &NmlMatrix<T>

Source§

type Output = Result<NmlMatrix<T>, NmlError>

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Self) -> Self::Output

Performs the - operation. Read more
Source§

impl<T> Sub for NmlMatrix<T>

Source§

type Output = Result<NmlMatrix<T>, NmlError>

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Self) -> Self::Output

Performs the - operation. Read more
Source§

impl<T> Eq for NmlMatrix<T>

Auto Trait Implementations§

§

impl<T> Freeze for NmlMatrix<T>

§

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

§

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

§

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

§

impl<T> Unpin for NmlMatrix<T>

§

impl<T> UnwindSafe for NmlMatrix<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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V