Peroxide
Rust numeric library with R Syntax.
Latest README version
Corresponds with 0.4.1
.
Usage
Initial Import
extern crate peroxide;
use *;
Vec<f64> Declaration
# R
a =
b = # (=c(1,3,5))
// Peroxide
let a = c!;
let b = seq! // (=c!(1,3,5))
Matrix Declaration
# R
a =
// Peroxide (All belows are same)
// matrix function
let a = matrix;
let b = matrix;
let c = matrix;
// matrix macro (More convenient)
let c = matrix!;
# R
a =
# [,1] [,2]
# [1,] 1 2
# [2,] 3 4
// Peroxide
let a = matrix!;
println!;
// c[0] c[1]
// r[0] 1 2
// r[1] 3 4
Matrix operation
- If you want to do multiple operations on same matrix, then you should use
clone
because Ruststd::ops
consume value.
# R
a =
b =
// Peroxide
let a = matrix!;
let b = matrix!;
println!;
println!;
println!; // Element-wise multiplication
println!; // Matrix multiplication
// Consume -> You can't use a,b anymore.
LU Decomposition
- Peroxide uses complete pivoting LU decomposition. - Very stable.
- Also there are lots of error handling for LU, so, you should use
Option
let a = matrix;
let pqlu = a.lu.unwrap; // for singular matrix, returns None
let = ;
assert_eq!; // swap 0 & 1 (Row)
assert_eq!; // swap 0 & 1 (Col)
assert_eq!;
assert_eq!;
Determinant
- Determinant is implemented using by LU decomposition (O(n^3))
let a = matrix;
assert_eq!;
Inverse
- Inverse is also implemented using by LU decomposition
- To handle singularity, output type is
Option<Matrix>
- To obtain inverse, you should use
unwrap
or pattern matching
- To obtain inverse, you should use
// Non-singular
let a = matrix!;
assert_eq!;
// Singular
let b = matrix!;
assert_eq!;
Extract Column or Row
a =
//Peroxide
let a = matrix!;
println!;
println!;
println!;
println!;
Functional Programming
// Peroxide
let a = matrix!;
println!;
println!;
println!;
// Results
//
// c[0] c[1]
// r[0] 2 3
// r[1] 4 5
//
// c[0] c[1]
// r[0] 0 1
// r[1] 2 3
//
// c[0] c[1]
// r[0] 2 4
// r[1] 6 8
Version Info
To see Release.md