[−][src]Struct peroxide::structure::matrix::Matrix
R-like matrix structure
Examples
extern crate peroxide; use peroxide::*; 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
Methods
impl Matrix
[src]
impl Matrix
Main matrix structure
pub fn change_shape(&self) -> Matrix | [src] |
Change Bindings
Row
-> Col
or Col
-> Row
Examples
extern crate peroxide; use peroxide::*; 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);
pub fn spread(&self) -> String | [src] |
Spread data(1D vector) to 2D formatted String
Examples
extern crate peroxide; use peroxide::*; 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
pub fn col(&self, index: usize) -> Vector | [src] |
Extract Column
Examples
extern crate peroxide; use peroxide::*; let a = matrix(c!(1,2,3,4), 2, 2, Row); assert_eq!(a.col(0), c!(1,3));
pub fn row(&self, index: usize) -> Vector | [src] |
Extract Row
Examples
extern crate peroxide; use peroxide::*; let a = matrix(c!(1,2,3,4), 2, 2, Row); assert_eq!(a.row(0), c!(1,2));
pub fn diag(&self) -> Vector | [src] |
Extract diagonal components
Examples
extern crate peroxide; use peroxide::*; let a = matrix!(1;4;1, 2, 2, Row); assert_eq!(a.diag(), c!(1,4));
pub fn swap(&self, idx1: usize, idx2: usize, shape: Shape) -> Matrix | [src] |
Swap row or col
Examples
extern crate peroxide; use peroxide::*; let a = matrix!(1;4;1, 2, 2, Row); assert_eq!(a.swap(0,1,Row), matrix(c!(3,4,1,2),2,2,Row)); assert_eq!(a.swap(0,1,Col), matrix(c!(2,4,1,3),2,2,Col));
pub fn write(&self, file_path: &str) -> Result<(), Box<dyn Error>> | [src] |
Write to CSV
Examples
extern crate peroxide; use peroxide::*; let a = matrix(c!(1,2,3,3,2,1), 3, 2, Col); a.write("test.csv");
pub fn write_with_header( | [src] |
pub fn read( | [src] |
Read from CSV
Examples
extern crate peroxide; use peroxide::*; use std::process; let a = matrix(c!(1,2,3,3,2,1), 3, 2, Col); a.write("test.csv"); let b = Matrix::read("test.csv", false, ','); // header = false, delimiter = ',' match b { Ok(mat) => println!("{}", mat), Err(err) => { println!("{}", err); process::exit(1); } }
pub fn subs_col(&mut self, idx: usize, v: Vec<f64>) | [src] |
Substitute Col
pub fn subs_row(&mut self, idx: usize, v: Vec<f64>) | [src] |
Substitute Row
Trait Implementations
impl LinearOps for Matrix
[src]
impl LinearOps for Matrix
fn to_matrix(&self) -> Matrix | [src] |
Just clone
fn transpose(&self) -> Matrix | [src] |
Transpose
Examples
extern crate peroxide; use peroxide::*; let a = matrix(vec![1,2,3,4], 2, 2, Row); println!("{}", a); // [[1,3],[2,4]]
fn t(&self) -> Matrix | [src] |
R-like transpose function
Examples
extern crate peroxide; use peroxide::*; let a = matrix!(1;4;1, 2, 2, Row); assert_eq!(a.transpose(), a.t());
impl FP for Matrix
[src]
impl FP for Matrix
fn take(&self, n: usize, shape: Shape) -> Matrix | [src] |
fn skip(&self, n: usize, shape: Shape) -> Matrix | [src] |
fn fmap<F>(&self, f: F) -> Matrix where | [src] |
fn reduce<F, T>(&self, init: T, f: F) -> f64 where | [src] |
fn zip_with<F>(&self, f: F, other: &Matrix) -> Matrix where | [src] |
impl LinearAlgebra for Matrix
[src]
impl LinearAlgebra for Matrix
fn lu(&self) -> Option<PQLU> | [src] |
LU Decomposition Implements
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
extern crate peroxide; use peroxide::*; let a = matrix(vec![1,2,3,4], 2, 2, Row); let pqlu = a.lu().unwrap(); let (p,q,l,u) = (pqlu.p, pqlu.q, pqlu.l, pqlu.u); assert_eq!(p, vec![(0,1)]); // swap 0 & 1 (Row) assert_eq!(q, vec![(0,1)]); // swap 0 & 1 (Col) assert_eq!(l, matrix(c!(1,0,0.5,1),2,2,Row)); assert_eq!(u, matrix(c!(4,3,0,-0.5),2,2,Row));
fn det(&self) -> f64 | [src] |
Determinant
Examples
extern crate peroxide; use peroxide::*; let a = matrix!(1;4;1, 2, 2, Row); assert_eq!(a.det(), -2f64);
fn block(&self) -> (Matrix, Matrix, Matrix, Matrix) | [src] |
Block Partition
Examples
extern crate peroxide; use peroxide::*; 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));
fn inv(&self) -> Option<Matrix> | [src] |
Inverse of Matrix
Caution
inv
function returns Option<Matrix>
Thus, you should use pattern matching or unwrap
to obtain inverse.
Examples
extern crate peroxide; use peroxide::*; // Non-singular let a = matrix!(1;4;1, 2, 2, Row); assert_eq!(a.inv().unwrap(), matrix(c!(-2,1,1.5,-0.5),2,2,Row)); // Singular let b = matrix!(1;9;1, 3, 3, Row); assert_eq!(b.inv(), None);
fn pseudo_inv(&self) -> Option<Matrix> | [src] |
Moore-Penrose Pseudo inverse
Description
(X^T X)^{-1} X
Examples
extern crate peroxide; use peroxide::*; let a = matrix!(1;4;1, 2, 2, Row); let inv_a = a.inv().unwrap(); let pse_a = a.pseudo_inv().unwrap(); assert_eq!(inv_a, pse_a); // Nearly equal
impl Statistics for Matrix
[src]
impl Statistics for Matrix
type Array = Matrix
type Value = Vector
fn mean(&self) -> Vector | [src] |
Column Mean
Examples
extern crate peroxide; use peroxide::*; let m = matrix(c!(1,3,3,1), 2, 2, Col); assert_eq!(m.mean(), c!(2,2));
fn var(&self) -> Vector | [src] |
Column variance
Examples
extern crate peroxide; use peroxide::*; let m = matrix(c!(1,2,3,3,2,1), 3, 2, Col); assert!(nearly_eq(m.var()[0], 1));
fn sd(&self) -> Vector | [src] |
Column Standard Deviation
Examples
extern crate peroxide; use peroxide::*; let m = matrix(c!(1,2,3,3,2,1), 3, 2, Col); assert!(nearly_eq(m.sd()[0], 1));
fn cov(&self) -> Matrix | [src] |
Covariance Matrix (Column based)
Examples
extern crate peroxide; use peroxide::*; 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
fn cor(&self) -> Matrix | [src] |
impl Printable for Matrix
[src]
impl Printable for Matrix
impl MATLAB for Matrix
[src]
impl MATLAB for Matrix
impl PYTHON for Matrix
[src]
impl PYTHON for Matrix
impl R for Matrix
[src]
impl R for Matrix
impl PartialEq<Matrix> for Matrix
[src]
impl PartialEq<Matrix> for Matrix
PartialEq implements
fn eq(&self, other: &Matrix) -> bool | [src] |
| 1.0.0 [src] |
This method tests for !=
.
impl Clone for Matrix
[src]
impl Clone for Matrix
fn clone(&self) -> Matrix | [src] |
fn clone_from(&mut self, source: &Self) | 1.0.0 [src] |
Performs copy-assignment from source
. Read more
impl Debug for Matrix
[src]
impl Debug for Matrix
impl Display for Matrix
[src]
impl Display for Matrix
Pretty Print
impl Add<Matrix> for Matrix
[src]
impl Add<Matrix> 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.
type Output = Matrix
The resulting type after applying the +
operator.
fn add(self, other: Matrix) -> Matrix | [src] |
impl<T> Add<T> for Matrix where
T: Into<f64> + Copy,
[src]
impl<T> Add<T> for Matrix where
T: Into<f64> + Copy,
Element-wise addition between Matrix & f64
Examples
extern crate peroxide; use peroxide::*; let a = matrix!(1;4;1, 2, 2, Row); assert_eq!(a + 1, matrix!(2;5;1, 2, 2, Row));
type Output = Matrix
The resulting type after applying the +
operator.
fn add(self, other: T) -> Matrix | [src] |
impl Add<Matrix> for f64
[src]
impl Add<Matrix> for f64
Element-wise addition between f64 & matrix
Examples
extern crate peroxide; use peroxide::*; let a = matrix!(1;4;1, 2, 2, Row); assert_eq!(1f64 + a, matrix!(2;5;1, 2, 2, Row));
type Output = Matrix
The resulting type after applying the +
operator.
fn add(self, other: Matrix) -> Matrix | [src] |
impl Add<Matrix> for i32
[src]
impl Add<Matrix> for i32
Element-wise addition between f64 & matrix
Examples
extern crate peroxide; use peroxide::*; let a = matrix!(1;4;1, 2, 2, Row); assert_eq!(1 + a, matrix!(2;5;1, 2, 2, Row));
type Output = Matrix
The resulting type after applying the +
operator.
fn add(self, other: Matrix) -> Matrix | [src] |
impl Add<Matrix> for usize
[src]
impl Add<Matrix> for usize
Element-wise addition between f64 & matrix
Examples
extern crate peroxide; use peroxide::*; let a = matrix!(1;4;1, 2, 2, Row); assert_eq!(1 as usize + a, matrix!(2;5;1, 2, 2, Row));
type Output = Matrix
The resulting type after applying the +
operator.
fn add(self, other: Matrix) -> Matrix | [src] |
impl Sub<Matrix> for Matrix
[src]
impl Sub<Matrix> for Matrix
Subtraction between Matrix
Examples
extern crate peroxide; use peroxide::*; 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]]
type Output = Matrix
The resulting type after applying the -
operator.
fn sub(self, other: Matrix) -> Matrix | [src] |
impl<T> Sub<T> for Matrix where
T: Into<f64> + Copy,
[src]
impl<T> Sub<T> for Matrix where
T: Into<f64> + Copy,
type Output = Matrix
The resulting type after applying the -
operator.
fn sub(self, other: T) -> Matrix | [src] |
impl Sub<Matrix> for f64
[src]
impl Sub<Matrix> for f64
Subtraction Matrix with f64
Examples
extern crate peroxide; use peroxide::*; let a = matrix(vec![1,2,3,4],2,2,Row); assert_eq!(a - 1f64, matrix!(0;3;1, 2, 2, Row));
type Output = Matrix
The resulting type after applying the -
operator.
fn sub(self, other: Matrix) -> Matrix | [src] |
impl Sub<Matrix> for i32
[src]
impl Sub<Matrix> for i32
type Output = Matrix
The resulting type after applying the -
operator.
fn sub(self, other: Matrix) -> Matrix | [src] |
impl Sub<Matrix> for usize
[src]
impl Sub<Matrix> for usize
type Output = Matrix
The resulting type after applying the -
operator.
fn sub(self, other: Matrix) -> Matrix | [src] |
impl Mul<Matrix> for Matrix
[src]
impl Mul<Matrix> for Matrix
Element-wise matrix multiplication
Examples
extern crate peroxide; use peroxide::*; 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); // [[1,6],[6,16]]
type Output = Matrix
The resulting type after applying the *
operator.
fn mul(self, other: Matrix) -> Matrix | [src] |
impl<T> Mul<T> for Matrix where
T: Into<f64> + Copy,
[src]
impl<T> Mul<T> for Matrix where
T: Into<f64> + Copy,
type Output = Matrix
The resulting type after applying the *
operator.
fn mul(self, other: T) -> Matrix | [src] |
impl Mul<Matrix> for f64
[src]
impl Mul<Matrix> for f64
type Output = Matrix
The resulting type after applying the *
operator.
fn mul(self, other: Matrix) -> Matrix | [src] |
impl Mul<Matrix> for i64
[src]
impl Mul<Matrix> for i64
type Output = Matrix
The resulting type after applying the *
operator.
fn mul(self, other: Matrix) -> Matrix | [src] |
impl Mul<Matrix> for i32
[src]
impl Mul<Matrix> for i32
type Output = Matrix
The resulting type after applying the *
operator.
fn mul(self, other: Matrix) -> Matrix | [src] |
impl Mul<Matrix> for usize
[src]
impl Mul<Matrix> for usize
type Output = Matrix
The resulting type after applying the *
operator.
fn mul(self, other: Matrix) -> Matrix | [src] |
impl<T> Rem<T> for Matrix where
T: LinearOps,
[src]
impl<T> Rem<T> for Matrix where
T: LinearOps,
Matrix Multiplication
Examples
extern crate peroxide; use peroxide::*; 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)); let m = matrix!(1;4;1, 2, 2, Row); let v = c!(1,2); assert_eq!(m % v, matrix(c!(5,11),2,1,Col));
type Output = Matrix
The resulting type after applying the %
operator.
fn rem(self, other: T) -> Matrix | [src] |
impl Rem<Matrix> for Vector
[src]
impl Rem<Matrix> for Vector
Matrix multiplication for Vector vs Matrix
Examples
extern crate peroxide; use peroxide::*; let a = matrix!(1;4;1, 2, 2, Row); let v = c!(1,2); assert_eq!(v % a, matrix(c!(7,10),1,2,Row));
type Output = Matrix
The resulting type after applying the %
operator.
fn rem(self, other: Matrix) -> Matrix | [src] |
impl Neg for Matrix
[src]
impl Neg for Matrix
Negation of Matrix
Examples
extern crate peroxide; use peroxide::*; let a = matrix(vec![1,2,3,4],2,2,Row); println!("{}", -a); // [[-1,-2],[-3,-4]]
impl Index<(usize, usize)> for Matrix
[src]
impl Index<(usize, usize)> for Matrix
Index for Matrix
(usize, usize) -> f64
Examples
extern crate peroxide; use peroxide::*; let a = matrix(vec![1,2,3,4],2,2,Row); assert_eq!(a[(0,1)], 2f64);
type Output = f64
The returned type after indexing.
fn index(&self, pair: (usize, usize)) -> &f64 | [src] |
impl IndexMut<(usize, usize)> for Matrix
[src]
impl IndexMut<(usize, usize)> for Matrix
IndexMut for Matrix (Assign)
(usize, usize) -> f64
Examples
extern crate peroxide; use peroxide::*; 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));
Auto Trait Implementations
Blanket Implementations
impl<T> From for T
[src]
impl<T> From for T
impl<T, U> Into for T where
U: From<T>,
[src]
impl<T, U> Into for T where
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
impl<T> ToOwned for T where
T: Clone,
impl<T> ToString for T where
T: Display + ?Sized,
[src]
impl<T> ToString for T where
T: Display + ?Sized,
impl<T, U> TryFrom for T where
T: From<U>,
[src]
impl<T, U> TryFrom for T where
T: From<U>,
type Error = !
try_from
)The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error> | [src] |
impl<T> Borrow for T where
T: ?Sized,
[src]
impl<T> Borrow for T where
T: ?Sized,
impl<T> BorrowMut for T where
T: ?Sized,
[src]
impl<T> BorrowMut for T where
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T | [src] |
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
impl<T, U> TryInto for T where
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
try_from
)The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error> | [src] |
impl<T> Any for T where
T: 'static + ?Sized,
[src]
impl<T> Any for T where
T: 'static + ?Sized,
fn get_type_id(&self) -> TypeId | [src] |