Giter Site home page Giter Site logo

rust-expm's Introduction

Matrix exponentiation in Rust

This crate contains expm, an implementation of Algorithm 6.1 by Al-Mohy, Higham in the Rust programming language. It calculates the exponential of a matrix. See the linked paper for more information.

It uses the excellent rust-ndarray crate for matrix storage.

Example usage

The example below calculates the exponential of the unit matrix.

Important: You need to explicitly link to a BLAS + LAPACK provider such as openblas_src. See the explanations given at the blas-lapack-rs organization.

extern crate openblas_src;
use approx::assert_ulps_eq;
#[test]
fn exp_of_unit() {
    let n = 5;
    let a = ndarray::Array2::eye(n);
    let mut b = unsafe { ndarray::Array2::<f64>::uninitialized((n, n)) };

    crate::expm(&a, &mut b);

    for &elem in &b.diag() {
        assert_ulps_eq!(elem, 1f64.exp(), max_ulps=1);
    }
}

TODO

Care was taken to implement the algorithm with performance in mind. As such, no extra allocations after the initial setup of the Expm struct are done, and Expm can be reused to repeatedly calculate the exponential of matrices with the same dimension.

However, profiling the code might reveal ways to improve it.

  • Profile code and optimize;
  • Write more tests to verify the goodness of the algorithm for difficult matrices;
  • Tune the parameters t and itmax when calculating the 1-norms (right now, t=2, itmax=5, which is what Scipy and Matlab are doing);
  • Ensure that the compiler performs const propagation when calculating the Padé coefficients;
  • Test the Padé coefficient against their hard-coded results;
  • Evaluate, whether the unsafe blocks are really necessary in all instances or could be removed.

rust-expm's People

Contributors

mattburn avatar superfluffy avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.