pub struct NmlMatrix {
    pub num_rows: u32,
    pub num_cols: u32,
    pub data: Vec<f64>,
    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: Vec<f64>§is_square: bool

Implementations§

source§

impl NmlMatrix

source

pub fn new(num_rows: u32, num_cols: u32) -> Self

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<f64>> ) -> 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: Vec<f64> ) -> 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: f64, maximum: f64 ) -> 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) -> 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 nml_mat_from_file() -> Self

Unimplemented method that should read in a matrix from a file

source

pub fn equality(&self, matrix: &NmlMatrix) -> 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, tolerance: f64) -> bool

Checks if two matrices are equal with a given tolerance

source

pub fn at(&self, row: u32, col: u32) -> Result<f64, 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: f64 ) -> 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: f64)

Method sets the values of all cells ro a given value

source

pub fn set_dig_values(&mut self, value: f64) -> 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: f64 ) -> 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: f64 ) -> 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: f64)

multiplies the matrix in place with a given scalar

source

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

row_1 ist 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

Trait Implementations§

source§

impl Add for &NmlMatrix

§

type Output = Result<NmlMatrix, NmlError>

The resulting type after applying the + operator.
source§

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

Performs the + operation. Read more
source§

impl Add for NmlMatrix

§

type Output = Result<NmlMatrix, NmlError>

The resulting type after applying the + operator.
source§

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

Performs the + operation. Read more
source§

impl Debug for NmlMatrix

source§

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

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

impl Display for NmlMatrix

source§

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

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

impl Mul for NmlMatrix

§

type Output = Result<NmlMatrix, NmlError>

The resulting type after applying the * operator.
source§

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

Performs the * operation. Read more
source§

impl PartialEq for NmlMatrix

source§

fn eq(&self, other: &Self) -> 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 Sub for &NmlMatrix

§

type Output = Result<NmlMatrix, NmlError>

The resulting type after applying the - operator.
source§

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

Performs the - operation. Read more
source§

impl Sub for NmlMatrix

§

type Output = Result<NmlMatrix, NmlError>

The resulting type after applying the - operator.
source§

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

Performs the - operation. Read more
source§

impl Eq for NmlMatrix

Auto Trait Implementations§

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§

default 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>,

§

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>,

§

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.
§

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

§

fn vzip(self) -> V