Struct peroxide::structure::matrix::Matrix

source ·
pub struct Matrix {
    pub data: Vec<f64>,
    pub row: usize,
    pub col: usize,
    pub shape: Shape,
}
Expand description

R-like matrix structure

§Examples

use peroxide::fuga::*;

let a = Matrix {
    data: vec![1f64,2f64,3f64,4f64],
    row: 2,
    col: 2,
    shape: Row,
}; // [[1,2],[3,4]]

Fields§

§data: Vec<f64>§row: usize§col: usize§shape: Shape

Implementations§

source§

impl Matrix

source

pub fn write(&self, file_path: &str) -> Result<(), Box<dyn Error>>

Write to CSV

§Examples
#[macro_use]
extern crate peroxide;
use peroxide::fuga::*;

fn main() -> Result<(), Box<dyn Error>> {
    let a = matrix(c!(1,2,3,3,2,1), 3, 2, Col);
    a.write("example_data/test.csv")?;

    Ok(())
}
source

pub fn write_round( &self, file_path: &str, round: usize, ) -> Result<(), Box<dyn Error>>

Write to CSV (with round option)

§Examples
#[macro_use]
extern crate peroxide;
use peroxide::fuga::*;

fn main() -> Result<(), Box<dyn Error>> {
    let a = matrix(c!(1,2,3,3,2,1), 3, 2, Col);
    a.write_round("example_data/test.csv", 0)?;

    Ok(())
}
source

pub fn write_with_header( &self, file_path: &str, header: Vec<&str>, ) -> Result<(), Box<dyn Error>>

source

pub fn write_with_header_round( &self, file_path: &str, header: Vec<&str>, round: usize, ) -> Result<(), Box<dyn Error>>

source

pub fn read( file_path: &str, header: bool, delimiter: char, ) -> Result<Matrix, Box<dyn Error>>

Read from CSV

§Examples
#[macro_use]
extern crate peroxide;
use peroxide::fuga::*;
use std::process;

fn main() -> Result<(), Box<dyn Error>> {
    let a = matrix(c!(1,2,3,3,2,1), 3, 2, Col);
    a.write_round("example_data/test.csv", 0)?;

    let b = Matrix::read("example_data/test.csv", false, ','); // header = false, delimiter = ','
    match b {
        Ok(mat) => println!("{}", mat),
        Err(err) => {
            println!("{}", err);
            process::exit(1);
        }
    }

    Ok(())
}
source

pub fn from_series( series: &Series, row: usize, col: usize, shape: Shape, ) -> Self

Matrix from series

§Example
#[macro_use]
extern crate peroxide;
use peroxide::fuga::*;

fn main() {
    let a = Series::new(c!(1,2,3,4));
    let m = Matrix::from_series(&a, 2, 2, Row);
     
    assert_eq!(m, matrix(c!(1,2,3,4), 2, 2, Row));
}

Trait Implementations§

source§

impl<'a, 'b> Add<&'b Matrix> for &'a Matrix

source§

type Output = Matrix

The resulting type after applying the + operator.
source§

fn add(self, rhs: &'b Matrix) -> Self::Output

Performs the + operation. Read more
source§

impl<'a> Add<&'a Matrix> for f64

Element-wise addition between f64 & &Matrix

source§

type Output = Matrix

The resulting type after applying the + operator.
source§

fn add(self, other: &'a Matrix) -> Self::Output

Performs the + operation. Read more
source§

impl<'a> Add<&'a Matrix> for i32

Element-wise addition between i32 & &Matrix

source§

type Output = Matrix

The resulting type after applying the + operator.
source§

fn add(self, other: &'a Matrix) -> Self::Output

Performs the + operation. Read more
source§

impl<'a> Add<&'a Matrix> for usize

Element-wise addition between usize & &Matrix

source§

type Output = Matrix

The resulting type after applying the + operator.
source§

fn add(self, other: &'a Matrix) -> Self::Output

Performs the + operation. Read more
source§

impl Add<Matrix> for f64

Element-wise addition between f64 & matrix

§Examples

#[macro_use]
extern crate peroxide;
use peroxide::fuga::*;

fn main() {
    let a = matrix!(1;4;1, 2, 2, Row);
    assert_eq!(1f64 + a, matrix!(2;5;1, 2, 2, Row));
}
source§

type Output = Matrix

The resulting type after applying the + operator.
source§

fn add(self, other: Matrix) -> Matrix

Performs the + operation. Read more
source§

impl Add<Matrix> for i32

Element-wise addition between i32 & Matrix

§Examples

#[macro_use]
extern crate peroxide;
use peroxide::fuga::*;

fn main() {
    let a = matrix!(1;4;1, 2, 2, Row);
    assert_eq!(1 + a, matrix!(2;5;1, 2, 2, Row));
}
source§

type Output = Matrix

The resulting type after applying the + operator.
source§

fn add(self, other: Matrix) -> Matrix

Performs the + operation. Read more
source§

impl Add<Matrix> for usize

Element-wise addition between usize & matrix

§Examples

#[macro_use]
extern crate peroxide;
use peroxide::fuga::*;

fn main() {
    let a = matrix!(1;4;1, 2, 2, Row);
    assert_eq!(1usize + a, matrix!(2;5;1, 2, 2, Row));
}
source§

type Output = Matrix

The resulting type after applying the + operator.
source§

fn add(self, other: Matrix) -> Matrix

Performs the + operation. Read more
source§

impl<'a, T> Add<T> for &'a Matrix
where T: Into<f64> + Copy,

Element-wise addition between &Matrix & f64

source§

type Output = Matrix

The resulting type after applying the + operator.
source§

fn add(self, other: T) -> Self::Output

Performs the + operation. Read more
source§

impl<T> Add<T> for Matrix
where T: Into<f64> + Copy,

Element-wise addition between Matrix & f64

§Examples

#[macro_use]
extern crate peroxide;
use peroxide::fuga::*;

fn main() {
    let a = matrix!(1;4;1, 2, 2, Row);
    assert_eq!(a + 1, matrix!(2;5;1, 2, 2, Row));
}
source§

type Output = Matrix

The resulting type after applying the + operator.
source§

fn add(self, other: T) -> Self

Performs the + operation. Read more
source§

impl Add for Matrix

Element-wise addition of Matrix

§Caution

You should remember ownership. If you use Matrix a,b then you can’t use them after.

source§

type Output = Matrix

The resulting type after applying the + operator.
source§

fn add(self, other: Self) -> Self

Performs the + operation. Read more
source§

impl Clone for Matrix

source§

fn clone(&self) -> Matrix

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Matrix

source§

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

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

impl Default for Matrix

source§

fn default() -> Matrix

Returns the “default value” for a type. Read more
source§

impl<'de> Deserialize<'de> for Matrix

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl Display for Matrix

Pretty Print

source§

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

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

impl Div<Matrix> for f32

source§

type Output = Matrix

The resulting type after applying the / operator.
source§

fn div(self, m: Matrix) -> Matrix

Performs the / operation. Read more
source§

impl Div<Matrix> for f64

source§

type Output = Matrix

The resulting type after applying the / operator.
source§

fn div(self, m: Matrix) -> Matrix

Performs the / operation. Read more
source§

impl<'a> Div<f64> for &'a Matrix

source§

type Output = Matrix

The resulting type after applying the / operator.
source§

fn div(self, other: f64) -> Self::Output

Performs the / operation. Read more
source§

impl Div<f64> for Matrix

Element-wise division between Matrix vs f64

source§

type Output = Matrix

The resulting type after applying the / operator.
source§

fn div(self, other: f64) -> Self

Performs the / operation. Read more
source§

impl<'a> Div<i32> for &'a Matrix

source§

type Output = Matrix

The resulting type after applying the / operator.
source§

fn div(self, other: i32) -> Self::Output

Performs the / operation. Read more
source§

impl Div<i32> for Matrix

source§

type Output = Matrix

The resulting type after applying the / operator.
source§

fn div(self, other: i32) -> Self

Performs the / operation. Read more
source§

impl<'a> Div<i64> for &'a Matrix

source§

type Output = Matrix

The resulting type after applying the / operator.
source§

fn div(self, other: i64) -> Self::Output

Performs the / operation. Read more
source§

impl Div<i64> for Matrix

source§

type Output = Matrix

The resulting type after applying the / operator.
source§

fn div(self, other: i64) -> Self

Performs the / operation. Read more
source§

impl<'a> Div<usize> for &'a Matrix

source§

type Output = Matrix

The resulting type after applying the / operator.
source§

fn div(self, other: usize) -> Self::Output

Performs the / operation. Read more
source§

impl Div<usize> for Matrix

source§

type Output = Matrix

The resulting type after applying the / operator.
source§

fn div(self, other: usize) -> Self

Performs the / operation. Read more
source§

impl Div for Matrix

source§

type Output = Matrix

The resulting type after applying the / operator.
source§

fn div(self, m: Matrix) -> Matrix

Performs the / operation. Read more
source§

impl ExpLogOps for Matrix

source§

type Float = f64

source§

fn exp(&self) -> Self

source§

fn ln(&self) -> Self

source§

fn log(&self, base: Self::Float) -> Self

source§

fn log2(&self) -> Self

source§

fn log10(&self) -> Self

source§

impl FPMatrix for Matrix

source§

fn col_map<F>(&self, f: F) -> Matrix
where F: Fn(Vec<f64>) -> Vec<f64>,

Column map

§Example
use peroxide::fuga::*;

let x = ml_matrix("1 2;3 4;5 6");
let y = x.col_map(|c| c.fmap(|t| t - c.mean()));

assert_eq!(y, ml_matrix("-2 -2;0 0;2 2"));
source§

fn row_map<F>(&self, f: F) -> Matrix
where F: Fn(Vec<f64>) -> Vec<f64>,

Row map

§Example
use peroxide::fuga::*;

let x = ml_matrix("1 2 3;4 5 6");
let y = x.row_map(|r| r.fmap(|t| t - r.mean()));

assert_eq!(y, ml_matrix("-1 0 1;-1 0 1"));
source§

type Scalar = f64

source§

fn take_row(&self, n: usize) -> Self

source§

fn take_col(&self, n: usize) -> Self

source§

fn skip_row(&self, n: usize) -> Self

source§

fn skip_col(&self, n: usize) -> Self

source§

fn fmap<F>(&self, f: F) -> Matrix
where F: Fn(f64) -> f64,

source§

fn col_mut_map<F>(&mut self, f: F)
where F: Fn(Vec<f64>) -> Vec<f64>,

source§

fn row_mut_map<F>(&mut self, f: F)
where F: Fn(Vec<f64>) -> Vec<f64>,

source§

fn reduce<F, T>(&self, init: T, f: F) -> f64
where F: Fn(f64, f64) -> f64, T: Into<f64>,

source§

fn zip_with<F>(&self, f: F, other: &Matrix) -> Self
where F: Fn(f64, f64) -> f64,

source§

fn col_reduce<F>(&self, f: F) -> Vec<f64>
where F: Fn(Vec<f64>) -> f64,

source§

fn row_reduce<F>(&self, f: F) -> Vec<f64>
where F: Fn(Vec<f64>) -> f64,

source§

impl Index<(usize, usize)> for Matrix

Index for Matrix

(usize, usize) -> f64

§Examples

extern crate peroxide;
use peroxide::fuga::*;

let a = matrix(vec![1,2,3,4],2,2,Row);
assert_eq!(a[(0,1)], 2f64);
source§

type Output = f64

The returned type after indexing.
source§

fn index(&self, pair: (usize, usize)) -> &f64

Performs the indexing (container[index]) operation. Read more
source§

impl IndexMut<(usize, usize)> for Matrix

IndexMut for Matrix (Assign)

(usize, usize) -> f64

§Examples

#[macro_use]
extern crate peroxide;
use peroxide::fuga::*;

fn main() {
    let mut a = matrix!(1;4;1, 2, 2, Row);
    a[(1,1)] = 10.0;
    assert_eq!(a, matrix(c!(1,2,3,10), 2, 2, Row));
}
source§

fn index_mut(&mut self, pair: (usize, usize)) -> &mut f64

Performs the mutable indexing (container[index]) operation. Read more
source§

impl InnerProduct for Matrix

Frobenius inner product

source§

fn dot(&self, rhs: &Self) -> f64

source§

impl<'a> Into<&'a Vec<f64>> for &'a Matrix

&Matrix to &Vec<f64>

source§

fn into(self) -> &'a Vec<f64>

Converts this type into the (usually inferred) input type.
source§

impl Into<Matrix> for &Vec<f64>

source§

fn into(self) -> Matrix

Converts this type into the (usually inferred) input type.
source§

impl Into<Matrix> for SPMatrix

source§

fn into(self) -> Matrix

Converts this type into the (usually inferred) input type.
source§

impl Into<Matrix> for Vec<f64>

Vec<f64> to Matrix

source§

fn into(self) -> Matrix

Converts this type into the (usually inferred) input type.
source§

impl Into<SPMatrix> for Matrix

source§

fn into(self) -> SPMatrix

Converts this type into the (usually inferred) input type.
source§

impl Into<Vec<f64>> for Matrix

Matrix to Vec<f64>

source§

fn into(self) -> Vec<f64>

Converts this type into the (usually inferred) input type.
source§

impl LinearAlgebra<Matrix> for Matrix

source§

fn back_subs(&self, b: &[f64]) -> Vec<f64>

Backward Substitution for Upper Triangular

source§

fn forward_subs(&self, b: &[f64]) -> Vec<f64>

Forward substitution for Lower Triangular

source§

fn lu(&self) -> PQLU<Matrix>

LU Decomposition Implements (Complete Pivot)

§Description

It use complete pivoting LU decomposition. You can get two permutations, and LU matrices.

§Caution

It returns Option<PQLU> - You should unwrap to obtain real value.

  • PQLU has four field - p, q, l, u.
    • p, q are permutations.
    • l, u are matrices.
§Examples
use peroxide::fuga::*;

let a = matrix(vec![1,2,3,4], 2, 2, Row);
let pqlu = a.lu();
let (p,q,l,u) = (pqlu.p, pqlu.q, pqlu.l, pqlu.u);
assert_eq!(p, vec![1]); // swap 0 & 1 (Row)
assert_eq!(q, vec![1]); // swap 0 & 1 (Col)
assert_eq!(l, matrix(vec![1.0,0.0,0.5,1.0],2,2,Row));
assert_eq!(u, matrix(vec![4.0,3.0,0.0,-0.5],2,2,Row));
source§

fn qr(&self) -> QR<Matrix>

QR Decomposition

Translation of RosettaCode#Python

§Example
use peroxide::fuga::*;

let a = ml_matrix("12 -51 4;6 167 -68; -4 24 -41");
let qr = a.qr();
let r = ml_matrix("-14 -21 14; 0 -175 70; 0 0 -35");
#[cfg(feature="O3")]
{
    assert_eq!(r, qr.r);
}
qr.r.print();
source§

fn svd(&self) -> SVD<Matrix>

Singular Value Decomposition

§Examples
use peroxide::fuga::*;

let a = ml_matrix("3 2 2;2 3 -2");
#[cfg(feature="O3")]
{
    let svd = a.svd();
    assert!(eq_vec(&vec![5f64, 3f64], &svd.s, 1e-7));
}
a.print();
source§

fn cholesky(&self, uplo: UPLO) -> Matrix

Cholesky Decomposition

§Examples
use peroxide::fuga::*;

let a = ml_matrix("1 2;2 5");
#[cfg(feature = "O3")]
{
    let u = a.cholesky(Upper);
    let l = a.cholesky(Lower);

    assert_eq!(u, ml_matrix("1 2;0 1"));
    assert_eq!(l, ml_matrix("1 0;2 1"));
}
a.print();
source§

fn rref(&self) -> Matrix

Reduced Row Echelon Form

Implementation of RosettaCode

source§

fn det(&self) -> f64

Determinant

§Examples
#[macro_use]
extern crate peroxide;
use peroxide::fuga::*;

fn main() {
    let a = matrix!(1;4;1, 2, 2, Row);
    assert_eq!(a.det(), -2f64);
}
source§

fn block(&self) -> (Self, Self, Self, Self)

Block Partition

§Examples
#[macro_use]
extern crate peroxide;
use peroxide::fuga::*;

fn main() {
    let a = matrix!(1;16;1, 4, 4, Row);
    let (m1, m2, m3, m4) = a.block();
    assert_eq!(m1, matrix(c!(1,2,5,6), 2, 2, Row));
    assert_eq!(m2, matrix(c!(3,4,7,8), 2, 2, Row));
    assert_eq!(m3, matrix(c!(9,10,13,14), 2, 2, Row));
    assert_eq!(m4, matrix(c!(11,12,15,16), 2, 2, Row));

    let b = matrix!(1;16;1, 4, 4, Col);
    let (m1, m2, m3, m4) = b.block();
    assert_eq!(m1, matrix(c!(1,2,5,6), 2, 2, Col));
    assert_eq!(m3, matrix(c!(3,4,7,8), 2, 2, Col));
    assert_eq!(m2, matrix(c!(9,10,13,14), 2, 2, Col));
    assert_eq!(m4, matrix(c!(11,12,15,16), 2, 2, Col));
}
source§

fn inv(&self) -> Self

Inverse of Matrix

§Caution

inv function returns Option<Matrix> Thus, you should use pattern matching or unwrap to obtain inverse.

§Examples
#[macro_use]
extern crate peroxide;
use peroxide::fuga::*;

fn main() {
    // Non-singular
    let a = matrix!(1;4;1, 2, 2, Row);
    assert_eq!(a.inv(), matrix(c!(-2,1,1.5,-0.5),2,2,Row));

    // Singular
    //let b = matrix!(1;9;1, 3, 3, Row);
    //let c = b.inv(); // Can compile but..
    //let d = b.det();
    //assert_eq!(d, 0f64);
}
source§

fn pseudo_inv(&self) -> Self

Moore-Penrose Pseudo inverse

§Description

$X^\dagger = (X^T X)^{-1} X^T$

§Examples
#[macro_use]
extern crate peroxide;
use peroxide::fuga::*;

fn main() {
    let a = matrix!(1;4;1, 2, 2, Row);
    let inv_a = a.inv();
    let pse_a = a.pseudo_inv();

    assert_eq!(inv_a, pse_a); // Nearly equal
}
source§

fn solve(&self, b: &[f64], sk: SolveKind) -> Vec<f64>

Solve with Vector

§Solve options
  • LU: Gaussian elimination with Complete pivoting LU (GECP)
  • WAZ: Solve with WAZ decomposition
§Reference
  • Biswa Nath Datta, Numerical Linear Algebra and Applications, Second Edition
  • Ke Chen, Matrix Preconditioning Techniques and Applications, Cambridge Monographs on Applied and Computational Mathematics
source§

fn waz(&self, d_form: Form) -> Option<WAZD<Matrix>>

source§

fn solve_mat(&self, m: &Matrix, sk: SolveKind) -> Matrix

source§

fn is_symmetric(&self) -> bool

source§

impl LinearAlgebra<Matrix> for SPMatrix

Linear algebra for sparse matrix

Caution : In every ops in this trait, there is converting process to dense matrix

source§

fn back_subs(&self, _b: &[f64]) -> Vec<f64>

source§

fn forward_subs(&self, _b: &[f64]) -> Vec<f64>

source§

fn lu(&self) -> PQLU<Matrix>

source§

fn waz(&self, _d_form: Form) -> Option<WAZD<Matrix>>

source§

fn qr(&self) -> QR<Matrix>

source§

fn svd(&self) -> SVD<Matrix>

source§

fn cholesky(&self, _uplo: UPLO) -> Matrix

source§

fn rref(&self) -> Matrix

source§

fn det(&self) -> f64

source§

fn block(&self) -> (Matrix, Matrix, Matrix, Matrix)

source§

fn inv(&self) -> Matrix

source§

fn pseudo_inv(&self) -> Matrix

source§

fn solve(&self, _b: &[f64], _sk: SolveKind) -> Vec<f64>

source§

fn solve_mat(&self, _m: &Matrix, _sk: SolveKind) -> Matrix

source§

fn is_symmetric(&self) -> bool

source§

impl LinearOp<Vec<f64>, Vec<f64>> for Matrix

Matrix as Linear operator for Vector

source§

fn apply(&self, other: &Vec<f64>) -> Vec<f64>

source§

impl MATLAB for Matrix

source§

fn new(s: &str) -> Self

source§

impl MatrixProduct for Matrix

source§

fn kronecker(&self, other: &Self) -> Self

source§

fn hadamard(&self, other: &Self) -> Matrix

source§

impl MatrixPtr for Matrix

source§

unsafe fn row_ptr(&self, idx: usize) -> Vec<*const f64>

Row pointer

§Examples
#[macro_use]
extern crate peroxide;
use peroxide::fuga::*;

fn main() {
    let a = ml_matrix("1 2;3 4");
    unsafe {
        let b = a.row_ptr(1);
        let b_vec = ptr_to_vec(&b);
        assert_eq!(b_vec, vec![3f64, 4f64]);
    }
}
source§

unsafe fn col_ptr(&self, idx: usize) -> Vec<*const f64>

source§

impl MatrixTrait for Matrix

Main matrix structure

source§

fn ptr(&self) -> *const f64

Raw pointer for self.data

source§

fn mut_ptr(&mut self) -> *mut f64

Raw mutable pointer for self.data

source§

fn as_slice(&self) -> &[f64]

Slice of self.data

§Examples
use peroxide::fuga::*;

let a = matrix(vec![1,2,3,4], 2, 2, Col);
let b = a.as_slice();
assert_eq!(b, &[1f64,2f64,3f64,4f64]);
source§

fn as_mut_slice(&mut self) -> &mut [f64]

Mutable slice of self.data

§Examples
use peroxide::fuga::*;

let mut a = matrix(vec![1,2,3,4], 2, 2, Col);
let mut b = a.as_mut_slice();
b[0] = 5f64;
assert_eq!(b, &[5f64, 2f64, 3f64, 4f64]);
assert_eq!(a, matrix(vec![5,2,3,4], 2, 2, Col));
source§

fn change_shape(&self) -> Self

Change Bindings

Row -> Col or Col -> Row

§Examples
use peroxide::fuga::*;

let a = matrix(vec![1,2,3,4],2,2,Row);
assert_eq!(a.shape, Row);
let b = a.change_shape();
assert_eq!(b.shape, Col);
source§

fn change_shape_mut(&mut self)

Change Bindings Mutably

Row -> Col or Col -> Row

§Examples
use peroxide::fuga::*;

let a = matrix(vec![1,2,3,4],2,2,Row);
assert_eq!(a.shape, Row);
let b = a.change_shape();
assert_eq!(b.shape, Col);
source§

fn spread(&self) -> String

Spread data(1D vector) to 2D formatted String

§Examples
use peroxide::fuga::*;

let a = matrix(vec![1,2,3,4],2,2,Row);
println!("{}", a.spread()); // same as println!("{}", a);
// Result:
//       c[0] c[1]
// r[0]     1    3
// r[1]     2    4
source§

fn col(&self, index: usize) -> Vec<f64>

Extract Column

§Examples
#[macro_use]
extern crate peroxide;
use peroxide::fuga::*;

fn main() {
    let a = matrix(c!(1,2,3,4), 2, 2, Row);
    assert_eq!(a.col(0), c!(1,3));
}
source§

fn row(&self, index: usize) -> Vec<f64>

Extract Row

§Examples
#[macro_use]
extern crate peroxide;
use peroxide::fuga::*;

fn main() {
    let a = matrix(c!(1,2,3,4), 2, 2, Row);
    assert_eq!(a.row(0), c!(1,2));
}
source§

fn diag(&self) -> Vec<f64>

Extract diagonal components

§Examples
#[macro_use]
extern crate peroxide;
use peroxide::fuga::*;

fn main() {
    let a = matrix!(1;4;1, 2, 2, Row);
    assert_eq!(a.diag(), c!(1,4));
}
source§

fn transpose(&self) -> Self

Transpose

§Examples
use peroxide::fuga::*;

let a = matrix(vec![1,2,3,4], 2, 2, Row);
println!("{}", a); // [[1,3],[2,4]]
source§

fn t(&self) -> Self

R-like transpose function

§Examples
#[macro_use]
extern crate peroxide;
use peroxide::fuga::*;

fn main() {
    let a = matrix!(1;4;1, 2, 2, Row);
    assert_eq!(a.transpose(), a.t());
}
source§

fn subs_col(&mut self, idx: usize, v: &[f64])

Substitute Col

source§

fn subs_row(&mut self, idx: usize, v: &[f64])

Substitute Row

source§

fn from_index<F, G>(f: F, size: (usize, usize)) -> Matrix
where F: Fn(usize, usize) -> G + Copy, G: Into<f64>,

From index operations

source§

fn to_vec(&self) -> Vec<Vec<f64>>

Matrix to Vec<Vec<f64>>

To send Matrix to inline-python

source§

fn submat(&self, start: (usize, usize), end: (usize, usize)) -> Matrix

Submatrix

§Description

Return below elements of matrix to new matrix

$$ \begin{pmatrix} \ddots & & & & \\ & start & \cdots & end.1 & \\ & \vdots & \ddots & \vdots & \\ & end.0 & \cdots & end & \\ & & & & \ddots \end{pmatrix} $$

§Examples
extern crate peroxide;
use peroxide::fuga::*;

fn main() {
    let a = ml_matrix("1 2 3;4 5 6;7 8 9");
    let b = ml_matrix("5 6;8 9");
    let c = a.submat((1, 1), (2, 2));
    assert_eq!(b, c);   
}
source§

fn subs_mat(&mut self, start: (usize, usize), end: (usize, usize), m: &Matrix)

Substitute matrix to specific position

§Description

Substitute below elements of matrix

$$ \begin{pmatrix} \ddots & & & & \\ & start & \cdots & end.1 & \\ & \vdots & \ddots & \vdots & \\ & end.0 & \cdots & end & \\ & & & & \ddots \end{pmatrix} $$

§Examples
extern crate peroxide;
use peroxide::fuga::*;

fn main() {
    let mut a = ml_matrix("1 2 3;4 5 6;7 8 9");
    let b = ml_matrix("1 2;3 4");
    let c = ml_matrix("1 2 3;4 1 2;7 3 4");
    a.subs_mat((1,1), (2,2), &b);
    assert_eq!(a, c);       
}
source§

type Scalar = f64

source§

fn to_diag(&self) -> Matrix

source§

impl<'a, 'b> Mul<&'b Matrix> for &'a Matrix

source§

type Output = Matrix

The resulting type after applying the * operator.
source§

fn mul(self, other: &'b Matrix) -> Self::Output

Performs the * operation. Read more
source§

impl<'a, 'b> Mul<&'b Matrix> for &'a Vec<f64>

source§

type Output = Vec<f64>

The resulting type after applying the * operator.
source§

fn mul(self, other: &'b Matrix) -> Self::Output

Performs the * operation. Read more
source§

impl<'a> Mul<&'a Matrix> for f64

source§

type Output = Matrix

The resulting type after applying the * operator.
source§

fn mul(self, other: &'a Matrix) -> Matrix

Performs the * operation. Read more
source§

impl<'a> Mul<&'a Matrix> for i32

source§

type Output = Matrix

The resulting type after applying the * operator.
source§

fn mul(self, other: &'a Matrix) -> Matrix

Performs the * operation. Read more
source§

impl<'a> Mul<&'a Matrix> for i64

source§

type Output = Matrix

The resulting type after applying the * operator.
source§

fn mul(self, other: &'a Matrix) -> Matrix

Performs the * operation. Read more
source§

impl<'a> Mul<&'a Matrix> for usize

source§

type Output = Matrix

The resulting type after applying the * operator.
source§

fn mul(self, other: &'a Matrix) -> Matrix

Performs the * operation. Read more
source§

impl<'a, 'b> Mul<&'b Vec<f64>> for &'a Matrix

source§

type Output = Vec<f64>

The resulting type after applying the * operator.
source§

fn mul(self, other: &'b Vec<f64>) -> Self::Output

Performs the * operation. Read more
source§

impl Mul<Matrix> for Vec<f64>

Matrix multiplication for Vec<f64> vs Matrix

§Examples

#[macro_use]
extern crate peroxide;
use peroxide::fuga::*;

fn main() {
    let a = matrix!(1;4;1, 2, 2, Row);
    let v = c!(1,2);
    assert_eq!(v * a, c!(7, 10));
}
source§

type Output = Vec<f64>

The resulting type after applying the * operator.
source§

fn mul(self, other: Matrix) -> Self::Output

Performs the * operation. Read more
source§

impl Mul<Matrix> for f64

source§

type Output = Matrix

The resulting type after applying the * operator.
source§

fn mul(self, other: Matrix) -> Matrix

Performs the * operation. Read more
source§

impl Mul<Matrix> for i32

source§

type Output = Matrix

The resulting type after applying the * operator.
source§

fn mul(self, other: Matrix) -> Matrix

Performs the * operation. Read more
source§

impl Mul<Matrix> for i64

source§

type Output = Matrix

The resulting type after applying the * operator.
source§

fn mul(self, other: Matrix) -> Matrix

Performs the * operation. Read more
source§

impl Mul<Matrix> for usize

source§

type Output = Matrix

The resulting type after applying the * operator.
source§

fn mul(self, other: Matrix) -> Matrix

Performs the * operation. Read more
source§

impl Mul<Redox<Vec<f64>>> for &Matrix

source§

type Output = Redox<Vec<f64>>

The resulting type after applying the * operator.
source§

fn mul(self, rhs: Redox<Vec<f64>>) -> Self::Output

Performs the * operation. Read more
source§

impl Mul<Redox<Vec<f64>>> for Matrix

source§

type Output = Redox<Vec<f64>>

The resulting type after applying the * operator.
source§

fn mul(self, rhs: Redox<Vec<f64>>) -> Self::Output

Performs the * operation. Read more
source§

impl Mul<Vec<f64>> for Matrix

source§

type Output = Vec<f64>

The resulting type after applying the * operator.
source§

fn mul(self, other: Vec<f64>) -> Self::Output

Performs the * operation. Read more
source§

impl Mul<f64> for Matrix

Element-wise multiplication between Matrix vs f64

source§

type Output = Matrix

The resulting type after applying the * operator.
source§

fn mul(self, other: f64) -> Self

Performs the * operation. Read more
source§

impl Mul<i32> for Matrix

source§

type Output = Matrix

The resulting type after applying the * operator.
source§

fn mul(self, other: i32) -> Self

Performs the * operation. Read more
source§

impl Mul<i64> for Matrix

source§

type Output = Matrix

The resulting type after applying the * operator.
source§

fn mul(self, other: i64) -> Self

Performs the * operation. Read more
source§

impl Mul<usize> for Matrix

source§

type Output = Matrix

The resulting type after applying the * operator.
source§

fn mul(self, other: usize) -> Self

Performs the * operation. Read more
source§

impl Mul for Matrix

Matrix Multiplication

§Examples

#[macro_use]
extern crate peroxide;
use peroxide::fuga::*;

fn main() {
    let a = matrix!(1;4;1, 2, 2, Row);
    let b = matrix!(1;4;1, 2, 2, Col);
    assert_eq!(a * b, matrix(c!(5, 11, 11, 25), 2, 2, Row));
}
source§

type Output = Matrix

The resulting type after applying the * operator.
source§

fn mul(self, other: Self) -> Self

Performs the * operation. Read more
source§

impl MutMatrix for Matrix

source§

type Scalar = f64

source§

unsafe fn col_mut(&mut self, idx: usize) -> Vec<*mut f64>

source§

unsafe fn row_mut(&mut self, idx: usize) -> Vec<*mut f64>

source§

unsafe fn swap(&mut self, idx1: usize, idx2: usize, shape: Shape)

source§

unsafe fn swap_with_perm(&mut self, p: &Vec<(usize, usize)>, shape: Shape)

source§

impl<'a> Neg for &'a Matrix

Negation of &’a Matrix

source§

type Output = Matrix

The resulting type after applying the - operator.
source§

fn neg(self) -> Self::Output

Performs the unary - operation. Read more
source§

impl Neg for Matrix

Negation of Matrix

§Examples

extern crate peroxide;
use peroxide::fuga::*;

let a = matrix(vec![1,2,3,4],2,2,Row);
println!("{}", -a); // [[-1,-2],[-3,-4]]
source§

type Output = Matrix

The resulting type after applying the - operator.
source§

fn neg(self) -> Self

Performs the unary - operation. Read more
source§

impl Normed for Matrix

source§

fn norm(&self, kind: Norm) -> f64

Norm of Matrix

§Example
use peroxide::fuga::*;

let a = ml_matrix("1 2;3 4");
assert_eq!(a.norm(Norm::F), (1f64 + 4f64 + 9f64 + 16f64).sqrt());
source§

type UnsignedScalar = f64

source§

fn normalize(&self, _kind: Norm) -> Self
where Self: Sized,

source§

impl PYTHON for Matrix

source§

fn new<T>(v: Vec<Vec<T>>) -> Self
where T: Into<f64> + Copy,

source§

impl ParallelInnerProduct for Matrix

Frobenius inner product in parallel

source§

fn par_dot(&self, rhs: &Self) -> f64

source§

impl ParallelNormed for Matrix

source§

fn par_norm(&self, kind: Norm) -> f64

Parallel version of norm

§Example
use peroxide::fuga::*;

let a = ml_matrix("1 2;3 4");
assert_eq!(a.par_norm(Norm::F), (1f64 + 4f64 + 9f64 + 16f64).sqrt());
source§

type UnsignedScalar = f64

source§

impl PartialEq for Matrix

PartialEq implements

source§

fn eq(&self, other: &Matrix) -> 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 PowOps for Matrix

source§

type Float = f64

source§

fn powi(&self, n: i32) -> Self

source§

fn powf(&self, f: Self::Float) -> Self

source§

fn pow(&self, _f: Self) -> Self

source§

fn sqrt(&self) -> Self

source§

impl Printable for Matrix

source§

fn print(&self)

source§

impl R for Matrix

source§

fn new<T>(v: Vec<T>, x: usize, y: usize, shape: Shape) -> Self
where T: Into<f64>,

source§

impl Scalable for Matrix

Modify Matrix

source§

fn reshape(&self, (r, c): (usize, usize), shape: Shape) -> Matrix

Resize matrix

#[macro_use]
extern crate peroxide;
use peroxide::fuga::*;

fn main() {
    let a = ml_matrix("1 2 3;4 5 6"); // ml_matrix has shape `Col`
    let b1 = a.reshape((3, 2), Row);
    let b2 = a.reshape((3, 2), Col);
    assert_eq!(b1, ml_matrix("1 2;3 4;5 6"));
    assert_eq!(b2, ml_matrix("1 4;2 5;3 6"));
}
source§

fn add_col(&self, v: &Self::Vec) -> Matrix

Add column

#[macro_use]
extern crate peroxide;
use peroxide::fuga::*;

fn main() {
    let a = ml_matrix("1 2 3;4 5 6");
    let b = c!(7,8);
    let c = a.add_col(&b);
    assert_eq!(c, ml_matrix("1 2 3 7;4 5 6 8"));
}
source§

fn add_row(&self, v: &Self::Vec) -> Matrix

Add row

#[macro_use]
extern crate peroxide;
use peroxide::fuga::*;

fn main() {
    let a = ml_matrix("1 2 3;4 5 6");
    let b = c!(7,8,9);
    let c = a.add_row(&b);
    assert_eq!(c, ml_matrix("1 2 3;4 5 6;7 8 9"));
}
source§

type Vec = Vec<f64>

source§

impl ScalableMut for Matrix

source§

fn reshape_mut(&mut self, (r, c): (usize, usize), shape: Shape)

Resize matrix (Mutable)

#[macro_use]
extern crate peroxide;
use peroxide::fuga::*;

fn main() {
    let mut a = ml_matrix("1 2 3;4 5 6"); // ml_matrix has shape `Row`
    a.reshape_mut((3, 2), Row);
    assert_eq!(a, ml_matrix("1 2;3 4;5 6"));
    a.reshape_mut((3, 2), Col);
    assert_eq!(a, ml_matrix("1 4;2 5;3 6"));
}
source§

fn add_col_mut(&mut self, v: &Self::Vec)

Add column (Mutable)

#[macro_use]
extern crate peroxide;
use peroxide::fuga::*;

fn main() {
    let mut a = ml_matrix("1 2 3;4 5 6");
    let b = c!(7,8);
    a.add_col_mut(&b);
    assert_eq!(a, ml_matrix("1 2 3 7;4 5 6 8"));
}
source§

fn add_row_mut(&mut self, v: &Self::Vec)

Add row (Mutable)

#[macro_use]
extern crate peroxide;
use peroxide::fuga::*;

fn main() {
    let mut a = ml_matrix("1 2 3;4 5 6");
    let b = c!(7,8,9);
    a.add_row_mut(&b);
    assert_eq!(a, ml_matrix("1 2 3;4 5 6;7 8 9"));
}
source§

type Vec = Vec<f64>

source§

impl Serialize for Matrix

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl SimpleNorm for Matrix

Simple Frobenius norm

source§

fn norm(&self) -> Self::Scalar

source§

fn normalize(&self) -> Self

source§

impl SimplerLinearAlgebra<Matrix> for Matrix

source§

fn back_subs(&self, b: &[f64]) -> Vec<f64>

source§

fn forward_subs(&self, b: &[f64]) -> Vec<f64>

source§

fn lu(&self) -> PQLU<Matrix>

source§

fn waz_diag(&self) -> Option<WAZD<Matrix>>

source§

fn waz(&self) -> Option<WAZD<Matrix>>

source§

fn qr(&self) -> QR<Matrix>

source§

fn cholesky(&self) -> Matrix

source§

fn rref(&self) -> Matrix

source§

fn det(&self) -> f64

source§

fn block(&self) -> (Matrix, Matrix, Matrix, Matrix)

source§

fn inv(&self) -> Matrix

source§

fn pseudo_inv(&self) -> Matrix

source§

fn solve(&self, b: &[f64]) -> Vec<f64>

source§

fn solve_mat(&self, m: &Matrix) -> Matrix

source§

fn is_symmetric(&self) -> bool

source§

impl Statistics for Matrix

source§

fn mean(&self) -> Vec<f64>

Column Mean

§Examples
#[macro_use]
extern crate peroxide;
use peroxide::fuga::*;

fn main() {
    let m = matrix(c!(1,3,3,1), 2, 2, Col);
    assert_eq!(m.mean(), c!(2,2));
}
source§

fn var(&self) -> Vec<f64>

Column variance

§Examples
#[macro_use]
extern crate peroxide;
use peroxide::fuga::*;

fn main() {
    let m = matrix(c!(1,2,3,3,2,1), 3, 2, Col);
    assert!(nearly_eq(m.var()[0], 1));
}
source§

fn sd(&self) -> Vec<f64>

Column Standard Deviation

§Examples
#[macro_use]
extern crate peroxide;
use peroxide::fuga::*;

fn main() {
    let m = matrix(c!(1,2,3,3,2,1), 3, 2, Col);
    assert!(nearly_eq(m.sd()[0], 1));
}
source§

fn cov(&self) -> Self

Covariance Matrix (Column based)

§Examples
#[macro_use]
extern crate peroxide;
use peroxide::fuga::*;

fn main() {
    let m = matrix(c!(1,2,3,3,2,1), 3, 2, Col);
    println!("{}", m.cov());

    //         c[0]    c[1]
    // r[0]  1.0000 -1.0000
    // r[1] -1.0000  1.0000
}
source§

type Array = Matrix

source§

type Value = Vec<f64>

source§

fn cor(&self) -> Self

source§

impl<'a, 'b> Sub<&'b Matrix> for &'a Matrix

source§

type Output = Matrix

The resulting type after applying the - operator.
source§

fn sub(self, rhs: &'b Matrix) -> Matrix

Performs the - operation. Read more
source§

impl<'a> Sub<&'a Matrix> for f64

source§

type Output = Matrix

The resulting type after applying the - operator.
source§

fn sub(self, other: &'a Matrix) -> Self::Output

Performs the - operation. Read more
source§

impl<'a> Sub<&'a Matrix> for i32

source§

type Output = Matrix

The resulting type after applying the - operator.
source§

fn sub(self, other: &'a Matrix) -> Self::Output

Performs the - operation. Read more
source§

impl<'a> Sub<&'a Matrix> for usize

source§

type Output = Matrix

The resulting type after applying the - operator.
source§

fn sub(self, other: &'a Matrix) -> Self::Output

Performs the - operation. Read more
source§

impl Sub<Matrix> for f64

Subtraction Matrix with f64

§Examples

#[macro_use]
extern crate peroxide;
use peroxide::fuga::*;

fn main() {
    let a = matrix(vec![1,2,3,4],2,2,Row);
    assert_eq!(a - 1f64, matrix!(0;3;1, 2, 2, Row));
}
source§

type Output = Matrix

The resulting type after applying the - operator.
source§

fn sub(self, other: Matrix) -> Matrix

Performs the - operation. Read more
source§

impl Sub<Matrix> for i32

source§

type Output = Matrix

The resulting type after applying the - operator.
source§

fn sub(self, other: Matrix) -> Matrix

Performs the - operation. Read more
source§

impl Sub<Matrix> for usize

source§

type Output = Matrix

The resulting type after applying the - operator.
source§

fn sub(self, other: Matrix) -> Matrix

Performs the - operation. Read more
source§

impl<'a, T> Sub<T> for &'a Matrix
where T: Into<f64> + Copy,

Subtraction between &Matrix & f64

source§

type Output = Matrix

The resulting type after applying the - operator.
source§

fn sub(self, other: T) -> Self::Output

Performs the - operation. Read more
source§

impl<T> Sub<T> for Matrix
where T: Into<f64> + Copy,

Subtraction between Matrix & f64

source§

type Output = Matrix

The resulting type after applying the - operator.
source§

fn sub(self, other: T) -> Self

Performs the - operation. Read more
source§

impl Sub for Matrix

Subtraction between Matrix

§Examples

extern crate peroxide;
use peroxide::fuga::*;

let a = matrix(vec![1,2,3,4],2,2,Row);
let b = matrix(vec![1,2,3,4],2,2,Col);
println!("{}", a - b); // [[0, -1], [1, 0]]
source§

type Output = Matrix

The resulting type after applying the - operator.
source§

fn sub(self, other: Self) -> Self

Performs the - operation. Read more
source§

impl TrigOps for Matrix

source§

fn sin_cos(&self) -> (Self, Self)

source§

fn sin(&self) -> Self

source§

fn cos(&self) -> Self

source§

fn tan(&self) -> Self

source§

fn sinh(&self) -> Self

source§

fn cosh(&self) -> Self

source§

fn tanh(&self) -> Self

source§

fn asin(&self) -> Self

source§

fn acos(&self) -> Self

source§

fn atan(&self) -> Self

source§

fn asinh(&self) -> Self

source§

fn acosh(&self) -> Self

source§

fn atanh(&self) -> Self

§

fn asin_acos(&self) -> (Self, Self)

§

fn asinh_acosh(&self) -> (Self, Self)

source§

impl Vector for Matrix

source§

type Scalar = f64

source§

fn add_vec(&self, other: &Self) -> Self

source§

fn sub_vec(&self, other: &Self) -> Self

source§

fn mul_scalar(&self, other: Self::Scalar) -> Self

source§

impl Numeric<f64> for Matrix

Auto Trait Implementations§

§

impl Freeze for Matrix

§

impl RefUnwindSafe for Matrix

§

impl Send for Matrix

§

impl Sync for Matrix

§

impl Unpin for Matrix

§

impl UnwindSafe for Matrix

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> CloneToUninit for T
where T: Clone,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> DynClone for T
where T: Clone,

source§

fn __clone_box(&self, _: Private) -> *mut ()

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> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> ToOwned for T
where T: Clone,

source§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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>,

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

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

§

fn vzip(self) -> V

source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

§

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