Struct nml_matrix::matrix::NmlMatrix
source · 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: boolImplementations§
source§impl NmlMatrix
impl NmlMatrix
sourcepub fn new(num_rows: u32, num_cols: u32) -> Self
pub fn new(num_rows: u32, num_cols: u32) -> Self
creates a matrix without data and reserves the capacity for the Data Vector
sourcepub fn new_with_2d_vec(
num_rows: u32,
num_cols: u32,
data_2d: &mut Vec<Vec<f64>>
) -> Result<Self, NmlError>
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
sourcepub fn new_with_data(
num_rows: u32,
num_cols: u32,
data: Vec<f64>
) -> Result<Self, NmlError>
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
sourcepub fn nml_mat_rnd(
num_rows: u32,
num_cols: u32,
minimum: f64,
maximum: f64
) -> Self
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
sourcepub fn nml_mat_sqr(size: u32) -> Self
pub fn nml_mat_sqr(size: u32) -> Self
Creates a square matrix of a given size, where all cells are filled with 0.0
sourcepub fn nml_mat_eye(size: u32) -> Self
pub fn nml_mat_eye(size: u32) -> Self
creates a identity matrix with the given size
sourcepub fn nml_mat_cp(matrix: &NmlMatrix) -> Self
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
sourcepub fn nml_mat_from_file() -> Self
pub fn nml_mat_from_file() -> Self
Unimplemented method that should read in a matrix from a file
sourcepub fn equality(&self, matrix: &NmlMatrix) -> bool
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
sourcepub fn equality_in_tolerance(&self, matrix: NmlMatrix, tolerance: f64) -> bool
pub fn equality_in_tolerance(&self, matrix: NmlMatrix, tolerance: f64) -> bool
Checks if two matrices are equal with a given tolerance
sourcepub fn at(&self, row: u32, col: u32) -> Result<f64, NmlError>
pub fn at(&self, row: u32, col: u32) -> Result<f64, NmlError>
Returns the value a specified at A[i,j]
sourcepub fn get_column(&self, column: u32) -> Result<Self, NmlError>
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
sourcepub fn get_row(&self, row: u32) -> Result<Self, NmlError>
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
sourcepub fn set_value(
&mut self,
row: u32,
col: u32,
data: f64
) -> Result<(), NmlError>
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
sourcepub fn set_all_values(&mut self, value: f64)
pub fn set_all_values(&mut self, value: f64)
Method sets the values of all cells ro a given value
sourcepub fn set_dig_values(&mut self, value: f64) -> Result<(), NmlError>
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
sourcepub fn multiply_row_scalar(
&mut self,
row: u32,
scalar: f64
) -> Result<(), NmlError>
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
sourcepub fn multiply_col_scalar(
&mut self,
col: u32,
scalar: f64
) -> Result<(), NmlError>
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
sourcepub fn multiply_matrix_scalar(&mut self, scalar: f64)
pub fn multiply_matrix_scalar(&mut self, scalar: f64)
multiplies the matrix in place with a given scalar
sourcepub fn add_rows(
&mut self,
row_1: u32,
scalar_1: f64,
row_2: u32,
scalar_2: f64
) -> Result<(), NmlError>
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)
sourcepub fn swap_rows(&mut self, row_1: u32, row_2: u32) -> Result<(), NmlError>
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
sourcepub fn swap_columns(&mut self, col_1: u32, col_2: u32) -> Result<(), NmlError>
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
sourcepub fn remove_column(&self, col: u32) -> Result<Self, NmlError>
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
sourcepub fn remove_row(&self, row: u32) -> Result<Self, NmlError>
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
pub fn get_sub_mtr( &self, row_start: u32, row_end: u32, col_start: u32, col_end: u32 ) -> Result<Self, NmlError>
sourcepub fn transpose(&self) -> Self
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.
sourcepub fn mul_transpose(&self, other: &Self) -> Result<Self, NmlError>
pub fn mul_transpose(&self, other: &Self) -> Result<Self, NmlError>
The naive matrix multiplication algorihm applied with the transponse of the one matrix