Giter Site home page Giter Site logo

flaport / umfpack-rs Goto Github PK

View Code? Open in Web Editor NEW
2.0 1.0 1.0 787 KB

Some UMFPACK bindings for rust.

Home Page: https://crates.io/crates/umfpack-rs

License: GNU Lesser General Public License v2.1

Rust 100.00%
lu solve suitesparse umfpack linear rust sparse system

umfpack-rs's Introduction

UMFPACK-rs

Some UMFPACK bindings for rust.

The umfpack-rs library provides unsafe bindings and safe wrappers to some of the SuiteSparse UMFPACK routines. You can use the wrappers to solve a sparse linear system that is either real-values (f64) with umfpack_di_{symbolic,numeric,solve} or complex valued (Complex64) using umfpack_zi_{symbolic,numeric,solve}.

Example

Note that the rust wrappers attempt to be as close as possible to the SuiteSparse C-code while hiding unsafe operations. This means the exposed API might not be as clean as one might expect.

#[allow(non_snake_case)]
fn main() {
    use umfpack::prelude::*;

    let n = 5;
    let Ap = vec![0, 2, 5, 9, 10, 12]; // column pointers of CSC sparse nxn matrix
    let Ai = vec![0, 1, 0, 2, 4, 1, 2, 3, 4, 2, 1, 4]; // row indices of CSC sparse matrix
    let Ax = vec![2.0, 3.0, 3.0, -1.0, 4.0, 4.0, -3.0, 1.0, 2.0, 2.0, 6.0, 1.0]; // values of CSC sparse matrix
    let b = vec![8.0, 45.0, -3.0, 3.0, 19.0]; // dense target
    let mut x = vec![0.0, 0.0, 0.0, 0.0, 0.0]; // initial value for unknown x
    let control = Control::new(); // default control parameters
    let mut info = Info::new(); // empty info buffer

    // solving the system Ax=b happens in three steps:

    // 1. Symbolic Analyzation of the sparse system
    let mut symbolic = Symbolic::new();
    umfpack_di_symbolic(
        n, // m
        n, // n
        &Ap,
        &Ai,
        &Ax,
        &mut symbolic,
        Some(&control),
        Some(&mut info),
    );

    // 2. Numeric Analyzation of the sparse system
    let mut numeric = Numeric::new();
    umfpack_di_numeric(
        &Ap,
        &Ai,
        &Ax,
        &symbolic,
        &mut numeric,
        Some(&control),
        Some(&mut info),
    );

    // 3. Solving of the sparse system
    umfpack_di_solve(
        UMFPACK::A, // solve the system Ax=b
        &Ap,
        &Ai,
        &Ax,
        &mut x,
        &b,
        &numeric,
        Some(&control),
        Some(&mut info),
    );

    println!("symbolic walltime: {}", info.umfpack_symbolic_walltime());
    println!("numeric walltime: {}", info.umfpack_numeric_walltime());
    println!("solve walltime: {}", info.umfpack_solve_walltime());

    for i in 0..(n as usize) {
        println!("x [{}] = {:.1}", i, x[i]);
    }
}
symbolic walltime: 0.000018095000086759683
numeric walltime: 0.0004187900001397793
solve walltime: 0.000003099999958067201
x [0] = 1.0
x [1] = 2.0
x [2] = 3.0
x [3] = 4.0
x [4] = 5.0

You can find more examples in the examples folder (sometimes alongside with the C++ equivalent). To learn more on how to use UMFPACK, read the user guide or quick start pdf.

Installation

cargo add umfpack-rs

License & Credits

© Floris Laporte 2023, LGPL-2.1

This library vendors, wraps and statically links to SuiteSparse, LGPL-2.1.

umfpack-rs's People

Contributors

flaport avatar yshoji-hep avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Forkers

yshoji-hep

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.