Struct little_matrix::Matrix[][src]

pub struct Matrix { /* fields omitted */ }

Implementations

impl Matrix[src]

A Matrix is represented here by 3 fields named: nrows: i16, ncols: i16, data: Vec<Vec>

pub fn nrows(&self) -> i16[src]

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());

pub fn ncols(&self) -> i16[src]

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());

pub fn set(&mut self, x: i16, y: i16, v: f64)[src]

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();

pub fn get(&self, x: i16, y: i16) -> f64[src]

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));

pub fn add(a: &Matrix, b: &Matrix) -> Matrix[src]

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);

pub fn sub(a: &Matrix, b: &Matrix) -> Matrix[src]

Returns two matrices subtracted 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_sub: Matrix = Matrix::sub(&matrixa, &matrixb);

pub fn mul(a: &Matrix, b: &Matrix) -> Matrix[src]

Returns two matrices multiplied 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_mul: Matrix = Matrix::mul(&matrixa, &matrixb);

pub fn div(a: &Matrix, b: &Matrix) -> Matrix[src]

Returns two matrices divided 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_div: Matrix = Matrix::div(&matrixa, &matrixb);

pub fn dot(a: &Matrix, b: &Matrix) -> Matrix[src]

Returns the dot product of two matrices as a Matrix.

Arguments

  • a - A &Matrix.
  • b - 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 = Matrix::dot(&matrixa, &matrixb);

pub fn transpose(a: &Matrix) -> Matrix[src]

Returns the transposed Matrix as a Matrix.

Arguments

  • a - A &Matrix.

Examples

use nn::Matrix;

let matrixa: Matrix = Matrix::create_random_matrix(6, 6);

let matrix_t: Matrix = Matrix::transpose(&matrixa);

pub fn map(&self, f: fn(_: f64) -> f64) -> Matrix[src]

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);

pub fn scalar_add(a: &Matrix, v: f64) -> Matrix[src]

Adds a single f64 float to every value in a given Matrix and returns it as a Matrix.

Arguments

  • a - A &Matrix.
  • v - A f64.

Examples

use nn::Matrix;

let matrixa: Matrix = Matrix::create_random_matrix(6, 6);

let scalar_add: Matrix = Matrix::scalar_add(&matrixa, 10.0);

pub fn scalar_sub(a: &Matrix, v: f64) -> Matrix[src]

Subtracts a single f64 float from every value in a given Matrix and returns it as a Matrix.

Arguments

  • a - A &Matrix.
  • v - A f64.

Examples

use nn::Matrix;

let matrixa: Matrix = Matrix::create_random_matrix(6, 6);

let scalar_sub: Matrix = Matrix::scalar_sub(&matrixa, 10.0);

pub fn scalar_sub_first(a: &Matrix, v: f64) -> Matrix[src]

Subtracts every value of the Matrix from a given float f64 and returns it as a Matrix.

Arguments

  • a - A &Matrix.
  • v - A f64.

Examples

use nn::Matrix;

let matrixa: Matrix = Matrix::create_random_matrix(6, 6);

let scalar_sub: Matrix = Matrix::scalar_sub_first(&matrixa, 10.0);

pub fn scalar_mult(a: &Matrix, v: f64) -> Matrix[src]

Multiplies every value of the Matrix by a given float f64 and returns it as a Matrix.

Arguments

  • a - A &Matrix.
  • v - A f64.

Examples

use nn::Matrix;

let matrixa: Matrix = Matrix::create_random_matrix(6, 6);

let scalar_sub: Matrix = Matrix::scalar_mult(&matrixa, 10.0);

pub fn scalar_div(a: &Matrix, v: f64) -> Matrix[src]

Divides every value of the Matrix by a given float f64 and returns it as a Matrix.

Arguments

  • a - A &Matrix.
  • v - A f64.

Examples

use nn::Matrix;

let matrixa: Matrix = Matrix::create_random_matrix(6, 6);

let scalar_sub: Matrix = Matrix::scalar_div(&matrixa, 10.0);

pub fn inverse(a: &Matrix) -> Matrix[src]

Returns a Matrix where every value has the opposite sign as a Matrix.

Arguments

  • a - A &Matrix.

Examples

use nn::Matrix;

let matrixa: Matrix = Matrix::create_random_matrix(6, 6);

let matrixa_inverse: Matrix = Matrix::inverse(&matrixa);

pub fn sum_rows(a: &Matrix) -> Matrix[src]

Sums every row together and returns a Matrix with the same number of rows and 1 column.

Arguments

  • a - A &Matrix.

Examples

use nn::Matrix;

let matrixa: Matrix = Matrix::create_random_matrix(6, 6);

let matrixa_rows_sum: = Matrix::sum_rows(&matrixa);

pub fn pow(a: &Matrix, v: f64) -> Matrix[src]

Every value in the Matrix is raised to a given power and returned as a Matrix.

Arguments

  • a - A &Matrix.
  • v - A f64.

Examples

use nn::Matrix;

let matrixa: Matrix = Matrix::create_random_matrix(6, 6);

let matrixa_pow_2 = Matrix::pow(&matrixa, 2.0);

pub fn filter_by_function(a: &Matrix, f: fn(_: f64) -> bool, v: f64) -> Matrix[src]

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);

pub fn get_shape_string(&self) -> String[src]

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());

pub fn print(&self)[src]

Pretty prints the Matrix to the console using print!().

Examples

use nn::Matrix;

let matrixa: Matrix = Matrix::create_random_matrix(6, 6);

matrixa.print();

pub fn create_matrix(nrows: i16, ncols: i16) -> Matrix[src]

Creates a Matrix by a given number of rows as i16 and cols as i16 where every value is zero and returns it as a Matrix.

Arguments

  • nrows - A i16.
  • ncols - A i16.

Examples

use nn::Matrix;

let matrixa: Matrix = Matrix::create_matrix(6, 6);

pub fn create_random_matrix(nrows: i16, ncols: i16) -> Matrix[src]

Creates a Matrix by a given number of rows as i16 and cols as i16 where every value is random between 0 and 1 and returns it as a Matrix.

Arguments

  • nrows - A i16.
  • ncols - A i16.

Examples

use nn::Matrix;

let matrixa: Matrix = Matrix::create_matrix(6, 6);

pub fn create_matrix_by_float(nrows: i16, ncols: i16, v: f64) -> Matrix[src]

Creates a Matrix by a given number of rows as i16 and cols as i16 where every value is a given float and returns it as a Matrix.

Arguments

  • nrows - A i16.
  • ncols - A i16.
  • v - A f64.

Examples

use nn::Matrix;

let matrixa: Matrix = Matrix::create_matrix_by_float(6, 6, 10.0);

pub fn create_matrix_from_nested_float_array(v: &[&[f64]]) -> Matrix[src]

Creates a Matrix by nested float array &[&f64] and returns it as a Matrix.

Arguments

  • v - A &[&f64].

Examples

use nn::Matrix;

let matrixa: Matrix = Matrix::create_matrix_from_nested_float_array(&[ &[10.0, 1.0, 1.2, 3.4], &[2.3, 4.3, 2.1, 5.4] ]);

matrixa.print();

Trait Implementations

impl Add<Matrix> for Matrix[src]

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();

type Output = Matrix

The resulting type after applying the + operator.

impl AddAssign<Matrix> for Matrix[src]

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;

impl BitOr<Matrix> for Matrix[src]

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();

type Output = Matrix

The resulting type after applying the | operator.

impl Clone for Matrix[src]

impl Div<Matrix> for Matrix[src]

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();

type Output = Matrix

The resulting type after applying the / operator.

impl DivAssign<Matrix> for Matrix[src]

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;

impl Index<Range<usize>> for Matrix[src]

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]);

type Output = f64

The returned type after indexing.

impl Mul<Matrix> for Matrix[src]

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();

type Output = Matrix

The resulting type after applying the * operator.

impl MulAssign<Matrix> for Matrix[src]

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;

impl Not for Matrix[src]

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);

type Output = Matrix

The resulting type after applying the ! operator.

impl Sub<Matrix> for Matrix[src]

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();

type Output = Matrix

The resulting type after applying the - operator.

impl SubAssign<Matrix> for Matrix[src]

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;

Auto Trait Implementations

impl RefUnwindSafe for Matrix

impl Send for Matrix

impl Sync for Matrix

impl Unpin for Matrix

impl UnwindSafe for Matrix

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

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