34 releases

0.8.0 Nov 22, 2020
0.7.3 Sep 29, 2020
0.6.10 Jun 30, 2020
0.6.5 Mar 29, 2020
0.0.3 Nov 19, 2018

#14 in Math

Download history 89/week @ 2020-08-13 69/week @ 2020-08-20 99/week @ 2020-08-27 104/week @ 2020-09-03 70/week @ 2020-09-10 23/week @ 2020-09-17 56/week @ 2020-09-24 89/week @ 2020-10-01 63/week @ 2020-10-08 63/week @ 2020-10-15 35/week @ 2020-10-22 31/week @ 2020-10-29 33/week @ 2020-11-05 40/week @ 2020-11-12 44/week @ 2020-11-19 58/week @ 2020-11-26

243 downloads per month
Used in tinguely

MIT license

530KB
12K SLoC

Mathru

crate documentation minimum rustc 1.46.0 maintenance pipeline status

Mathru is a numeric library containing algorithms for linear algebra, analysis and statistics written in pure Rust with BLAS/LAPACK support.

Features

The following features are implemented in this create:

Usage

Add this to your Cargo.toml for the native Rust implementation:

[dependencies.mathru]
version = "0.7"

Add the following lines to 'Cargo.toml' if the openblas library should be used:

[dependencies.mathru]
version = "0.7"
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)

Then import the modules and it is ready to be used.

use mathru as mr;

Solve linear system

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

/// Solves a system of linear equations
fn main()
{
    let a: Matrix<f64> = matrix![6.0, 2.0, -1.0; -3.0, 5.0, 3.0; -2.0, 1.0, 3.0];
    let b: Vector<f64> = vector![48.0; 49.0; 24.0];

    // Decompose a into a lower and upper matrix
    let lu_dec: LUDec<f64> = a.dec_lu().unwrap();

    // Solve the system of linear equations with the decomposed matrix
    let _x1: Vector<f64> = lu_dec.solve(&b).unwrap();

    // Solve it directly
    let _x2: Vector<f64> = a.solve(&b).unwrap();
}

Solve ordinary differential equation with the Dormand-Prince algorithm

use mathru::{
    algebra::linear::Vector,
    analysis::differential_equation::ordinary::{problem, DormandPrince54, ExplicitODE},
};

fn main()
{
    // Create an ODE instance
    let problem: problem::Euler<f64> = problem::Euler::default();

    let (x_start, x_end) = problem.time_span();

    // Create a ODE solver instance
    let h_0: f64 = 0.0001;
    let n_max: u32 = 800;
    let abs_tol: f64 = 10e-7;

    let solver: DormandPrince54<f64> = DormandPrince54::new(abs_tol, h_0, n_max);

    // Solve ODE
    let (x, y): (Vec<f64>, Vec<Vector<f64>>) = solver.solve(&problem).unwrap();
}

Further examples

For further examples, see project page

Documentation

See project page for more information and examples. The API is documented on docs.rs.

License

Licensed under

Contribution

Any contribution is welcome!

Dependencies

~0.8–20MB
~395K SLoC