peroxide
Rust numeric library with high performance and friendly syntax
Science Score: 77.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
✓CITATION.cff file
Found CITATION.cff file -
✓codemeta.json file
Found codemeta.json file -
✓.zenodo.json file
Found .zenodo.json file -
✓DOI references
Found 2 DOI reference(s) in README -
✓Academic publication links
Links to: zenodo.org -
✓Committers with academic emails
2 of 23 committers (8.7%) from academic institutions -
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (14.6%) to scientific vocabulary
Keywords
Repository
Rust numeric library with high performance and friendly syntax
Basic Info
- Host: GitHub
- Owner: Axect
- License: apache-2.0
- Language: Rust
- Default Branch: master
- Homepage: https://crates.io/crates/peroxide
- Size: 13.6 MB
Statistics
- Stars: 649
- Watchers: 16
- Forks: 32
- Open Issues: 12
- Releases: 25
Topics
Metadata Files
README.md
Peroxide
Rust numeric library contains linear algebra, numerical analysis, statistics and machine learning tools with R, MATLAB, Python like macros.
Table of Contents
- Peroxide
- Table of Contents
- Why Peroxide?
- 1. Customize features
- 2. Easy to optimize
- 3. Friendly syntax
- 4. Can choose two different coding styles.
- 5. Batteries included
- 6. Compatible with Mathematics
- 7. Written in Rust
- Latest README version
- Pre-requisite
- Install
- Basic Installation
- Featured Installation
- Available Features
- Install Examples
- Useful tips for features
- Module Structure
- Documentation
- Examples
- Release Info
- Contributes Guide
- LICENSE
- TODO
- Cite Peroxide
Why Peroxide?
1. Customize features
Peroxide provides various features.
default- Pure Rust (No dependencies of architecture - Perfect cross compilation)O3- BLAS & LAPACK (Perfect performance but little bit hard to set-up - Strongly recommend to look Peroxide with BLAS)plot- With matplotlib of python, we can draw any plots.complex- With complex numbers (vector, matrix and integral)parallel- With some parallel functionsnc- To handle netcdf file format with DataFramecsv- To handle csv file format with Matrix or DataFrameparquet- To handle parquet file format with DataFrameserde- serialization with Serde.rkyv- serialization with rkyv.
If you want to do high performance computation and more linear algebra, then choose O3 feature.
If you don't want to depend C/C++ or Fortran libraries, then choose default feature.
If you want to draw plot with some great templates, then choose plot feature.
You can choose any features simultaneously.
2. Easy to optimize
Peroxide uses a 1D data structure to represent matrices, making it straightforward to integrate with BLAS (Basic Linear Algebra Subprograms). This means that Peroxide can guarantee excellent performance for linear algebraic computations by leveraging the optimized routines provided by BLAS.
3. Friendly syntax
For users familiar with numerical computing libraries like NumPy, MATLAB, or R, Rust's syntax might seem unfamiliar at first. This can make it more challenging to learn and use Rust libraries that heavily rely on Rust's unique features and syntax.
However, Peroxide aims to bridge this gap by providing a syntax that resembles the style of popular numerical computing environments. With Peroxide, you can perform complex computations using a syntax similar to that of R, NumPy, or MATLAB, making it easier for users from these backgrounds to adapt to Rust and take advantage of its performance benefits.
For example,
```rust
[macro_use]
extern crate peroxide; use peroxide::prelude::*;
fn main() { // MATLAB like matrix constructor let a = ml_matrix("1 2;3 4");
// R like matrix constructor (default)
let b = matrix(c!(1,2,3,4), 2, 2, Row);
// Or use zeros
let mut z = zeros(2, 2);
z[(0,0)] = 1.0;
z[(0,1)] = 2.0;
z[(1,0)] = 3.0;
z[(1,1)] = 4.0;
// Simple but effective operations
let c = a * b; // Matrix multiplication (BLAS integrated)
// Easy to pretty print
c.print();
// c[0] c[1]
// r[0] 1 3
// r[1] 2 4
// Easy to do linear algebra
c.det().print();
c.inv().print();
// and etc.
} ```
4. Can choose two different coding styles.
In peroxide, there are two different options.
prelude: To simple use.fuga: To choose numerical algorithms explicitly.
For examples, let's see norm.
In prelude, use norm is simple: a.norm(). But it only uses L2 norm for Vec<f64>. (For Matrix, Frobenius norm.)
```rust
[macro_use]
extern crate peroxide; use peroxide::prelude::*;
fn main() { let a = c!(1, 2, 3); let l2 = a.norm(); // L2 is default vector norm
assert_eq!(l2, 14f64.sqrt());
} ```
In fuga, use various norms. But you should write a little bit longer than prelude.
```rust
[macro_use]
extern crate peroxide; use peroxide::fuga::*;
fn main() { let a = c!(1, 2, 3); let l1 = a.norm(Norm::L1); let l2 = a.norm(Norm::L2); let linf = a.norm(Norm::LInf); asserteq!(l1, 6f64); asserteq!(l2, 14f64.sqrt()); asserteq!(l_inf, 3f64); } ```
5. Batteries included
Peroxide can do many things.
- Linear Algebra
- Effective Matrix structure
- Transpose, Determinant, Diagonal
- LU Decomposition, Inverse matrix, Block partitioning
- QR Decomposition (
O3feature) - Singular Value Decomposition (SVD) (
O3feature) - Cholesky Decomposition (
O3feature) - Reduced Row Echelon form
- Column, Row operations
- Eigenvalue, Eigenvector
- Functional Programming
- Easier functional programming with
Vec<f64> - For matrix, there are three maps
fmap: map for all elementscol_map: map for column vectorsrow_map: map for row vectors
- Easier functional programming with
- Automatic Differentiation
- Taylor mode Forward AD - for nth order AD
- Exact jacobian
Realtrait to constrain forf64andAD(for ODE)
- Numerical Analysis
- Lagrange interpolation
- Splines
- Cubic Spline
- Cubic Hermite Spline
- Estimate slope via Akima
- Estimate slope via Quadratic interpolation
- B-Spline
- Non-linear regression
- Gradient Descent
- Levenberg Marquardt
- Ordinary Differential Equation
- Trait based ODE solver (after
v0.36.0) - Explicit integrator
- Ralston's 3rd order
- Runge-Kutta 4th order
- Ralston's 4th order
- Runge-Kutta 5th order
- Embedded integrator
- Bogacki-Shampine 3(2)
- Runge-Kutta-Fehlberg 5(4)
- Dormand-Prince 5(4)
- Tsitouras 5(4)
- Runge-Kutta-Fehlberg 8(7)
- Implicit integrator
- Gauss-Legendre 4th order
- Numerical Integration
- Newton-Cotes Quadrature
- Gauss-Legendre Quadrature (up to 30 order)
- Gauss-Kronrod Quadrature (Adaptive)
- G7K15, G10K21, G15K31, G20K41, G25K51, G30K61
- Gauss-Kronrod Quadrature (Relative tolerance)
- G7K15R, G10K21R, G15K31R, G20K41R, G25K51R, G30K61R
- Root Finding
- Trait based root finding (after
v0.37.0) - Bisection
- False Position
- Secant
- Newton
- Broyden
- Statistics
- More easy random with
randcrate - Ordered Statistics
- Median
- Quantile (Matched with R quantile)
- Probability Distributions
- Bernoulli
- Uniform
- Binomial
- Normal
- Gamma
- Beta
- Student's-t
- Weighted Uniform
- LogNormal
- RNG algorithms
- Acceptance Rejection
- Marsaglia Polar
- Ziggurat
- Wrapper for
rand-distcrate - Piecewise Rejection Sampling
- Confusion Matrix & Metrics
- More easy random with
- Special functions
- Wrapper for
puruspecrate (pure rust)
- Wrapper for
- Utils
- R-like macro & functions
- Matlab-like macro & functions
- Numpy-like macro & functions
- Julia-like macro & functions
- Plotting
- With
pyo3&matplotlib
- With
- DataFrame
- Support various types simultaneously
- Read & Write
csvfiles (csvfeature) - Read & Write
netcdffiles (ncfeature) - Read & Write
parquetfiles (parquetfeature)
6. Compatible with Mathematics
After 0.23.0, peroxide is compatible with mathematical structures.
Matrix, Vec<f64>, f64 are considered as inner product vector spaces.
And Matrix, Vec<f64> are linear operators - Vec<f64> to Vec<f64> and Vec<f64> to f64.
For future, peroxide will include more & more mathematical concepts. (But still practical.)
7. Written in Rust
Rust provides a strong type system, ownership concepts, borrowing rules, and other features that enable developers to write safe and efficient code. It also offers modern programming techniques like trait-based abstraction and convenient error handling. Peroxide is developed to take full advantage of these strengths of Rust.
The example code demonstrates how Peroxide can be used to simulate the Lorenz attractor and visualize the results. It showcases some of the powerful features provided by Rust, such as the ? operator for streamlined error handling and the ODEProblem trait for abstracting ODE problems.
```rust use peroxide::fuga::*;
fn main() -> Result<(), Box? - can check constraint violation and etc.
let ymat = pymatrix(yvec);
let y0 = ymat.col(0);
let y2 = y_mat.col(2);
// Simple but effective plotting
let mut plt = Plot2D::new();
plt
.set_domain(y0)
.insert_image(y2)
.set_xlabel(r"$y_0$")
.set_ylabel(r"$y_2$")
.set_style(PlotStyle::Nature)
.tight_layout()
.set_dpi(600)
.set_path("example_data/lorenz_rkf45.png")
.savefig()?;
Ok(())
}
struct Lorenz;
impl ODEProblem for Lorenz { fn rhs(&self, t: f64, y: &[f64], dy: &mut [f64]) -> anyhow::Result<()> { dy[0] = 10f64 * (y[1] - y[0]); dy[1] = 28f64 * y[0] - y[1] - y[0] * y[2]; dy[2] = -8f64 / 3f64 * y[2] + y[0] * y[1]; Ok(()) } } ```
Running the code produces the following visualization of the Lorenz attractor:

Peroxide strives to leverage the benefits of the Rust language while providing a user-friendly interface for numerical computing and scientific simulations.
How's that? Let me know if there's anything else you'd like me to improve!
Latest README version
Corresponding to 0.38.0
Pre-requisite
- For
O3feature - NeedOpenBLAS - For
plotfeature - Needmatplotliband optionalscienceplots(for publication quality) - For
ncfeature - Neednetcdf
Install
Basic Installation
bash
cargo add peroxide
Featured Installation
bash
cargo add peroxide --features "<FEATURES>"
Available Features
O3: Adds OpenBLAS supportplot: Enables plotting functionalitycomplex: Supports complex number operationsparallel: Enables parallel processing capabilitiesnc: Adds NetCDF support for DataFramecsv: Adds CSV support for DataFrameparquet: Adds Parquet support for DataFrameserde: Enables serialization/deserialization for Matrix and polynomial
Install Examples
Single feature installation:
bash
cargo add peroxide --features "plot"
Multiple features installation:
bash
cargo add peroxide --features "O3 plot nc csv parquet serde"
Useful tips for features
If you want to use QR, SVD, or Cholesky Decomposition, you should use the
O3feature. These decompositions are not implemented in thedefaultfeature.If you want to save your numerical results, consider using the
parquetorncfeatures, which correspond to theparquetandnetcdffile formats, respectively. These formats are much more efficient thancsvandjson.For plotting, it is recommended to use the
plotfeature. However, if you require more customization, you can use theparquetorncfeature to export your data in the parquet or netcdf format and then use Python to create the plots.- To read parquet files in Python, you can use the
pandasandpyarrowlibraries. - A template for Python code that works with netcdf files can be found in the Socialst repository.
- To read parquet files in Python, you can use the
Module Structure
- src
- lib.rs :
modandre-export - complex: For complex vector, matrix & integrals.
- mod.rs
- integrate.rs : Complex integral
- matrix.rs : Complex matrix
- vector.rs : Complex vector
- fuga : Fuga for controlling numerical algorithms.
- mod.rs
- macros : Macro files
- julia_macro.rs : Julia like macro
- matlab_macro.rs : MATLAB like macro
- mod.rs
- r_macro.rs : R like macro
- ml : For machine learning (Beta)
- mod.rs
- reg.rs : Regression tools
- numerical : To do numerical things
- mod.rs
- eigen.rs : Eigenvalue, Eigenvector algorithm
- integral.rs : Numerical integration
- interp.rs : Interpolation
- newton.rs : Newton's Method
- ode.rs : Main ODE solver with various algorithms
- optimize.rs : Non-linear regression
- root.rs : Root finding
- spline.rs : Cubic spline, Cubic Hermite spline & B-Spline
- utils.rs : Utils to do numerical things (e.g. jacobian)
- prelude : Prelude for using simple
- mod.rs
- simpler.rs : Provides more simple api
- special : Special functions written in pure Rust (Wrapper of
puruspe) - mod.rs
- function.rs : Special functions
- statistics : Statistical Tools
- mod.rs
- dist.rs : Probability distributions
- ops.rs : Some probabilistic operations
- rand.rs : Wrapper for
randcrate & Piecewise Rejection Sampling - stat.rs : Statistical tools
- structure : Fundamental data structures
- mod.rs
- ad.rs : Automatic Differentation
- dataframe.rs : Dataframe
- matrix.rs : Matrix
- polynomial.rs : Polynomial
- sparse.rs : For sparse structure (Beta)
- vector.rs : Extra tools for
Vec<f64> - traits
- mod.rs
- fp.rs : Functional programming toolbox
- general.rs : General algorithms
- math.rs : Mathematics
- matrix.rs : Matrix traits
- mutable.rs : Mutable toolbox
- num.rs : Number, Real and more operations
- pointer.rs : Matrix pointer and Vector pointer for convenience
- stable.rs : Implement nightly-only features in stable
- sugar.rs : Syntactic sugar for Vector
- util
- mod.rs
- api.rs : Matrix constructor for various language style
- low_level.rs : Low-level tools
- non_macro.rs : Primordial version of macros
- plot.rs : To draw plot (using
pyo3) - print.rs : To print conveniently
- useful.rs : Useful utils to implement library
- wrapper.rs : Wrapper for other crates (e.g. rand)
- writer.rs : More convenient write system
- lib.rs :
Documentation
Examples
In examples directory, there are some examples.
In tests directory, there are some useful tests.
More examples are in Peroxide Gallery.
Release Info
To see RELEASES.md
Contributes Guide
See CONTRIBUTES.md
LICENSE
Peroxide is licensed under dual licenses - Apache License 2.0 and MIT License.
TODO
To see TODO.md
Cite Peroxide
Hey there! If you're using Peroxide in your research or project, you're not required to cite us. But if you do, we'd be really grateful! 😊
To make citing Peroxide easy, we've created a DOI through Zenodo. Just click on this badge:
This will take you to the Zenodo page for Peroxide. At the bottom, you'll find the citation information in various formats like BibTeX, RIS, and APA.
So, if you want to acknowledge the work we've put into Peroxide, citing us would be a great way to do it! Thanks for considering it, we appreciate your support! 👍
Owner
- Name: Tae-Geun Kim
- Login: Axect
- Kind: user
- Location: Seoul, South Korea
- Company: Yonsei Univ.
- Website: https://axect.github.io
- Repositories: 21
- Profile: https://github.com/Axect
Ph.D student of particle physics & Rustacean
Citation (CITATION.cff)
# This CITATION.cff file was generated with cffinit.
# Visit https://bit.ly/cffinit to generate yours today!
cff-version: 1.2.0
title: Peroxide
message: >-
If you use this software, please cite it using the
metadata from this file.
type: software
authors:
- given-names: Tae-Geun
family-names: Kim
email: axect.tg@proton.me
affiliation: Yonsei University
orcid: 'https://orcid.org/0009-0000-4229-2935'
- name: Peroxide contributors
identifiers:
- type: doi
value: 10.5281/zenodo.10815823
repository-code: 'https://github.com/Axect/Peroxide'
url: 'https://crates.io/crates/peroxide'
abstract: >-
Peroxide is a comprehensive numeric library written in
Rust, designed to cater to the needs of scientists,
engineers, mathematicians, and anyone who desires high
performance numerical computation. The library provides
robust and efficient functionality for linear algebra,
numerical analysis, statistics, and more. Peroxide
leverages the Rust language's safety, concurrency, and
performance capabilities to provide an interface that is
both user-friendly and highly performant. It is designed
with simplicity in mind, aiming to offer the ease-of-use
found in high-level languages without sacrificing the
speed and precision demanded by complex numerical tasks.
Peroxide stands as an indispensable tool for those who
seek a performant, safe and robust numeric computation
solution.
keywords:
- Rust
- Numeric
- Integration
- Linear algebra
- Differential equation
license: MIT
GitHub Events
Total
- Create event: 10
- Release event: 7
- Issues event: 8
- Watch event: 138
- Issue comment event: 15
- Push event: 39
- Pull request review event: 4
- Pull request event: 11
- Fork event: 4
Last Year
- Create event: 10
- Release event: 7
- Issues event: 8
- Watch event: 138
- Issue comment event: 15
- Push event: 39
- Pull request review event: 4
- Pull request event: 11
- Fork event: 4
Committers
Last synced: 7 months ago
Top Committers
| Name | Commits | |
|---|---|---|
| Axect | a****t@o****r | 764 |
| axect | e****g@g****m | 271 |
| Soumya | s****9@g****m | 46 |
| russellb23 | b****3@y****n | 13 |
| Johanna Sörngård | j****d@g****m | 8 |
| Marc Schreiber | i****o@s****e | 6 |
| axect | a****t@o****r | 5 |
| Giorgio Comitini | g****i@d****t | 4 |
| Lorenzo Bertini | 1****7 | 2 |
| Magnus Ulimoen | f****s@g****m | 2 |
| Samuel Naughton Baldwin | s****0@g****m | 2 |
| nathan.eckert | n****t@p****u | 2 |
| Adam Nemecek | a****k@g****m | 1 |
| Frithjof Winkelmann | f****7@w****e | 1 |
| Hiroki Konishi | r****e@g****m | 1 |
| Jonas Grage | g****e@p****e | 1 |
| Koute | k****e | 1 |
| T. Chamelot | c****s@g****m | 1 |
| Unknown | u****n@e****m | 1 |
| rdavis120 | 1****0 | 1 |
| Lorenzo Bertini | l****7@g****m | 1 |
| tarolling | b****s@g****m | 1 |
| thettasch | t****h@g****m | 1 |
Committer Domains (Top 20 + Academic)
Issues and Pull Requests
Last synced: 4 months ago
All Time
- Total issues: 61
- Total pull requests: 54
- Average time to close issues: 8 months
- Average time to close pull requests: 1 day
- Total issue authors: 25
- Total pull request authors: 20
- Average comments per issue: 2.82
- Average comments per pull request: 1.81
- Merged pull requests: 49
- Bot issues: 0
- Bot pull requests: 0
Past Year
- Issues: 9
- Pull requests: 18
- Average time to close issues: 8 days
- Average time to close pull requests: 2 days
- Issue authors: 6
- Pull request authors: 7
- Average comments per issue: 2.78
- Average comments per pull request: 2.06
- Merged pull requests: 14
- Bot issues: 0
- Bot pull requests: 0
Top Authors
Issue Authors
- Axect (9)
- JSorngard (3)
- tolvanea (2)
- haasal (2)
- schrieveslaach (2)
- NoeMurr (1)
- pavhofman (1)
- asmyers (1)
- davidssmith (1)
- amartyabose (1)
- hombit (1)
- jonasvanderschaaf (1)
- saona-raimundo (1)
- spar7453 (1)
- tchamelot (1)
Pull Request Authors
- JSorngard (14)
- GComitini (8)
- schrieveslaach (6)
- soumyasen1809 (6)
- bertini97 (2)
- Hoff97 (2)
- russellb23 (2)
- Axect (2)
- tarolling (2)
- Nateckert (2)
- jgrage (2)
- rdavis120 (1)
- tchamelot (1)
- samnaughtonb (1)
- koute (1)
Top Labels
Issue Labels
Pull Request Labels
Packages
- Total packages: 5
-
Total downloads:
- cargo 1,488,677 total
-
Total dependent packages: 10
(may contain duplicates) -
Total dependent repositories: 25
(may contain duplicates) - Total versions: 432
- Total maintainers: 1
proxy.golang.org: github.com/axect/peroxide
- Documentation: https://pkg.go.dev/github.com/axect/peroxide#section-documentation
- License: apache-2.0
-
Latest release: v0.40.0
published 5 months ago
Rankings
proxy.golang.org: github.com/Axect/Peroxide
- Documentation: https://pkg.go.dev/github.com/Axect/Peroxide#section-documentation
- License: apache-2.0
-
Latest release: v0.40.0
published 5 months ago
Rankings
crates.io: peroxide
Rust comprehensive scientific computation library contains linear algebra, numerical analysis, statistics and machine learning tools with farmiliar syntax
- Documentation: https://docs.rs/peroxide/
- License: MIT OR Apache-2.0
-
Latest release: 0.40.0
published 5 months ago
Rankings
Maintainers (1)
crates.io: peroxide-ad
Proc macro for automatic differenitation of Peroxide
- Documentation: https://docs.rs/peroxide-ad/
- License: MIT OR Apache-2.0
-
Latest release: 0.3.0
published almost 5 years ago
Rankings
Maintainers (1)
crates.io: peroxide-num
Numerical traits for Peroxide
- Documentation: https://docs.rs/peroxide-num/
- License: MIT OR Apache-2.0
-
Latest release: 0.1.4
published about 2 years ago
Rankings
Maintainers (1)
Dependencies
- blas 0.22
- csv 1.1
- json 0.12
- lapack 0.19
- matrixmultiply 0.3
- netcdf 0.7
- order-stat 0.1
- peroxide-ad 0.3
- puruspe 0.2
- pyo3 0.16
- rand 0.8
- rand_distr 0.4
- serde 1.0
- quote 1
- syn 1
- actions/checkout v1 composite