Crate mathru

Source
Expand description

This Rust library provides a wide range of mathematical routines such as linear algebra, differential equations, integration, interpolation, statistics and numerical optimization.

§Getting Started

Add a new dependency to your Cargo.toml file.

[dependencies]
mathru = "0.15"

You can check, if it works with a simple program like this:

 use mathru::vector;
 use mathru::algebra::linear::{vector::Vector, matrix::General};
 use mathru::algebra::linear::matrix::{Solve};

 fn main() {
     // set inputs:
     //
     // a = [1.0  -3.0]    b = [1.0]
     //     [2.0  -7.0]        [3.0]
     let a: General<f64> = General::new(2, 2, vec![1.0, 2.0, -3.0, -7.0]);
     let b: Vector<f64> = vector![1.0; 3.0];

     // Solve a * x = b
     let x: Vector<f64> = a.solve(&b).unwrap();
     assert_eq!(&a * &x, b);

     // Print result
     println!("x = [{} {}]", x[0], x[1]);
 }

§BLAS/LAPACK Support

Mathru has a native Rust implementation of all its functions. However, linear algebra functions are also implemented with a BLAS/LAPACK backend. The interface is identical, but the BLAS/LAPACK backend may be somewhat more efficient. BLAS/LAPACK support can be enable in the Cargo.toml file like so:

[dependencies.mathru]
version = "^0.15"
default-features = false
features = "openblas"

One of the following implementations for linear algebra can be activated as a feature:

  • native: Native Rust implementation(activated by default)
  • openblas: Optimized BLAS library
  • netlib: Collection of mathematical software, papers, and databases
  • intel-mkl: Intel Math Kernel Library
  • accelerate Make large-scale mathematical computations and image calculations, optimized for high performance and low-energy consumption. (macOS only)

Modules§

algebra
Abstract and linear algebra.
analysis
Interpolations, integration, differential equations, etc.
elementary
Elementary functions (the ones you learn in high school)
optimization
Algorithms for minimizing objective functions.
special
Special functions
statistics
Probability distributions and statistical functions

Macros§

abs_diff_eq
Approximate equality using the absolute difference.
abs_diff_ne
Approximate inequality using the absolute difference.
assert_abs_diff_eq
An assertion that delegates to abs_diff_eq!, and panics with a helpful error on failure.
assert_abs_diff_ne
An assertion that delegates to abs_diff_ne!, and panics with a helpful error on failure.
assert_relative_eq
An assertion that delegates to relative_eq!, and panics with a helpful error on failure.
assert_relative_ne
An assertion that delegates to relative_ne!, and panics with a helpful error on failure.
matrix
Macro to construct matrices
relative_eq
Approximate equality using both the absolute difference and relative based comparisons.
relative_ne
Approximate inequality using both the absolute difference and relative based comparisons.
vector
Macro to construct vectors