pub struct Matrix { /* private fields */ }
Implementations§
Source§impl Matrix
A Matrix is represented here by 3 fields named: nrows: i16, ncols: i16, data: Vec<Vec>
impl Matrix
A Matrix is represented here by 3 fields named: nrows: i16, ncols: i16, data: Vec<Vec
Sourcepub fn nrows(&self) -> i16
pub fn nrows(&self) -> i16
Returns the number of rows as i16.
§Examples
use nn::Matrix;
let matrix: Matrix = Matrix::create_random_matrix(6, 6);
println!(“The matrix has {} rows and {} cols”, matrix.nrows(), matrix.ncols());
Sourcepub fn ncols(&self) -> i16
pub fn ncols(&self) -> i16
Returns the number of cols as i16.
§Examples
use nn::Matrix;
let matrix: Matrix = Matrix::create_random_matrix(6, 6);
println!(“The matrix has {} rows and {} cols”, matrix.nrows(), matrix.ncols());
Sourcepub fn set(&mut self, x: i16, y: i16, v: f64)
pub fn set(&mut self, x: i16, y: i16, v: f64)
Sets one value in the Vector.
§Arguments
x
- A i16 Integer that holds the row, in which the variable is set.y
- A i16 Integer that holds the col, in which the variable is set.v
- A f64 Float that holds the new variable value.
§Examples
use nn::Matrix;
let matrix: Matrix = Matrix::create_random_matrix(6, 6);
matrix.print();
matrix.set(0, 0, 5.3);
matrix.print();
Sourcepub fn get(&self, x: i16, y: i16) -> f64
pub fn get(&self, x: i16, y: i16) -> f64
Returns one value in the Vector by a given row and col as f64.
§Arguments
x
- A i16 Integer that holds the row, in which the variable is set.y
- A i16 Integer that holds the col, in which the variable is set.
§Examples
use nn::Matrix;
let matrix: Matrix = Matrix::create_random_matrix(6, 6);
println!(“Value at row 0 and col 0 has the value {}”, matrix.get(0, 0));
Sourcepub fn add(a: &Matrix, b: &Matrix) -> Matrix
pub fn add(a: &Matrix, b: &Matrix) -> Matrix
Returns two matrices added together one by one as a Matrix.
§Arguments
a
- A &Matrix.b
- A &Matrix.
§Examples
use nn::Matrix;
let matrixa: Matrix = Matrix::create_random_matrix(6, 6);
let matrixb: Matrix = Matrix::create_random_matrix(6, 6);
let matrix_sum: Matrix = Matrix::add(&matrixa, &matrixb);
Sourcepub fn map(&self, f: fn(f64) -> f64) -> Matrix
pub fn map(&self, f: fn(f64) -> f64) -> Matrix
Applies a given function fn(f64) -> f64 to every value in the Matrix and returns the new Matrix as a Matrix.
§Arguments
a
- A &Matrix.f
- A fn(f64) -> f64.
§Examples
use nn::Matrix;
let matrixa: Matrix = Matrix::create_random_matrix(6, 6); let closure = |i: f64| -> f64 { i+10.0 }; let matrixb = matrixa.map(closure);
Sourcepub fn scalar_add(a: &Matrix, v: f64) -> Matrix
pub fn scalar_add(a: &Matrix, v: f64) -> Matrix
Sourcepub fn scalar_sub(a: &Matrix, v: f64) -> Matrix
pub fn scalar_sub(a: &Matrix, v: f64) -> Matrix
Sourcepub fn scalar_sub_first(a: &Matrix, v: f64) -> Matrix
pub fn scalar_sub_first(a: &Matrix, v: f64) -> Matrix
Sourcepub fn scalar_mult(a: &Matrix, v: f64) -> Matrix
pub fn scalar_mult(a: &Matrix, v: f64) -> Matrix
Sourcepub fn scalar_div(a: &Matrix, v: f64) -> Matrix
pub fn scalar_div(a: &Matrix, v: f64) -> Matrix
Sourcepub fn filter_by_function(a: &Matrix, f: fn(f64) -> bool, v: f64) -> Matrix
pub fn filter_by_function(a: &Matrix, f: fn(f64) -> bool, v: f64) -> Matrix
Filters every value in the Matrix by a given function fn(f64) -> bool. If the output of the function is true, the value stays the same. If the output of the function is false, the value is replaced by a given float f64. It returns a Matrix.
§Arguments
a
- A &Matrix.f
- A fn(f64) -> bool.v
- A f64.
§Examples
use nn::Matrix;
let matrixa: Matrix = Matrix::create_random_matrix(6, 6);
let closure = |v: f64| -> bool { v < 10.0 };
let matrixb = Matrix::filter_by_function(&matrixa, closure, 0.0);
Sourcepub fn get_shape_string(&self) -> String
pub fn get_shape_string(&self) -> String
Returns the shape of a Matrix as a string formatted with Shape:({}, {}) as a String.
§Examples
use nn::Matrix;
let matrixa: Matrix = Matrix::create_random_matrix(6, 6);
println!(“Matrix has {}”, matrixa.get_shape_string());
Sourcepub fn print(&self)
pub fn print(&self)
Pretty prints the Matrix to the console using print!().
§Examples
use nn::Matrix;
let matrixa: Matrix = Matrix::create_random_matrix(6, 6);
matrixa.print();
Sourcepub fn create_matrix(nrows: i16, ncols: i16) -> Matrix
pub fn create_matrix(nrows: i16, ncols: i16) -> Matrix
Sourcepub fn create_random_matrix(nrows: i16, ncols: i16) -> Matrix
pub fn create_random_matrix(nrows: i16, ncols: i16) -> Matrix
Sourcepub fn create_matrix_from_nested_float_array(v: &[&[f64]]) -> Matrix
pub fn create_matrix_from_nested_float_array(v: &[&[f64]]) -> Matrix
Trait Implementations§
Source§impl Add for Matrix
Returns two matrices added together one by one as a Matrix.
impl Add for Matrix
Returns two matrices added together one by one as a Matrix.
§Examples
use nn::Matrix;
let matrixa: Matrix = Matrix::create_random_matrix(6, 6);
let matrixb: Matrix = Matrix::create_random_matrix(6, 6);
let matrix_sum: Matrix = matrixa.clone() + matrixb.clone();
Source§impl AddAssign for Matrix
Adds a Matrix to a given Matrix one by one.
impl AddAssign for Matrix
Adds a Matrix to a given Matrix one by one.
§Examples
use nn::Matrix;
let mut matrixa: Matrix = Matrix::create_random_matrix(6, 6);
let matrixb: Matrix = Matrix::create_random_matrix(6, 6);
matrixa += matrixb;
Source§fn add_assign(&mut self, _rhs: Matrix)
fn add_assign(&mut self, _rhs: Matrix)
+=
operation. Read moreSource§impl BitOr for Matrix
Returns the dot product of two matrices as a Matrix.
impl BitOr for Matrix
Returns the dot product of two matrices as a Matrix.
§Examples
use nn::Matrix;
let matrixa: Matrix = Matrix::create_random_matrix(1, 2);
let matrixb: Matrix = Matrix::create_random_matrix(2, 1);
let matrix_dot: Matrix = matrixa.clone() | matrixb.clone();
Source§impl Div for Matrix
Returns two matrices divided one by one as a Matrix.
impl Div for Matrix
Returns two matrices divided one by one as a Matrix.
§Examples
use nn::Matrix;
let matrixa: Matrix = Matrix::create_random_matrix(6, 6);
let matrixb: Matrix = Matrix::create_random_matrix(6, 6);
let matrix_div: Matrix = matrixa.clone() / matrixb.clone();
Source§impl DivAssign for Matrix
Divides a Matrix by a given Matrix one by one.
impl DivAssign for Matrix
Divides a Matrix by a given Matrix one by one.
§Examples
use nn::Matrix;
let mut matrixa: Matrix = Matrix::create_random_matrix(6, 6);
let matrixb: Matrix = Matrix::create_random_matrix(6, 6);
matrixa /= matrixb;
Source§fn div_assign(&mut self, _rhs: Matrix)
fn div_assign(&mut self, _rhs: Matrix)
/=
operation. Read moreSource§impl Index<Range<usize>> for Matrix
Creates a Matrix by nested float array &[&f64] and returns it as a Matrix.
impl Index<Range<usize>> for Matrix
Creates a Matrix by nested float array &[&f64] and returns it as a Matrix.
§Examples
use nn::Matrix;
let matrixa: Matrix = Matrix::create_random_matrix(2, 2);
println!(“The value at Row 0 and Col 0 has the value {}”, matrixa[0..0]);
Source§impl Mul for Matrix
Returns two matrices multiplied one by one as a Matrix.
impl Mul for Matrix
Returns two matrices multiplied one by one as a Matrix.
§Examples
use nn::Matrix;
let matrixa: Matrix = Matrix::create_random_matrix(6, 6);
let matrixb: Matrix = Matrix::create_random_matrix(6, 6);
let matrix_mul: Matrix = matrixa.clone() * matrixb.clone();
Source§impl MulAssign for Matrix
Multiplies a Matrix with a given Matrix one by one.
impl MulAssign for Matrix
Multiplies a Matrix with a given Matrix one by one.
§Examples
use nn::Matrix;
let mut matrixa: Matrix = Matrix::create_random_matrix(6, 6);
let matrixb: Matrix = Matrix::create_random_matrix(6, 6);
matrixa *= matrixb;
Source§fn mul_assign(&mut self, _rhs: Matrix)
fn mul_assign(&mut self, _rhs: Matrix)
*=
operation. Read moreSource§impl Not for Matrix
Returns a Matrix where every value has the opposite sign as a Matrix.
impl Not for Matrix
Returns a Matrix where every value has the opposite sign as a Matrix.
§Examples
use nn::Matrix;
let matrixa: Matrix = Matrix::create_random_matrix(6, 6);
let matrixa_inverse: Matrix = Matrix::inverse(&matrixa);
Source§impl Sub for Matrix
Returns two matrices subtracted one by one as a Matrix.
impl Sub for Matrix
Returns two matrices subtracted one by one as a Matrix.
§Examples
use nn::Matrix;
let matrixa: Matrix = Matrix::create_random_matrix(6, 6);
let matrixb: Matrix = Matrix::create_random_matrix(6, 6);
let matrix_sub: Matrix = matrixa.clone() - matrixb.clone();
Source§impl SubAssign for Matrix
Subtracts a Matrix with a given Matrix one by one.
impl SubAssign for Matrix
Subtracts a Matrix with a given Matrix one by one.
§Examples
use nn::Matrix;
let mut matrixa: Matrix = Matrix::create_random_matrix(6, 6);
let matrixb: Matrix = Matrix::create_random_matrix(6, 6);
matrixa -= matrixb;
Source§fn sub_assign(&mut self, _rhs: Matrix)
fn sub_assign(&mut self, _rhs: Matrix)
-=
operation. Read more