Giter Site home page Giter Site logo

flaport / eigs Goto Github PK

View Code? Open in Web Editor NEW
3.0 1.0 0.0 42 KB

Find Eigenvalues and Eigenvectors with Rust using UMFPACK + ARPACK

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

License: GNU Lesser General Public License v2.1

Rust 89.82% Python 8.54% Dockerfile 1.64%
arpack eigenvalues eigenvectors modes numpy python rust scipy umfpack eigs

eigs's Introduction

eigs (Rust/Python Package)

Find Eigenvalues and Eigenvectors with Rust/Python using UMFPACK + ARPACK.

Packages

  • Rust Library: eigs @ crates.io: cargo add eigs
  • Python Library: eigs @ pypi.org: pip install eigs (Linux Only for now)

Examples

eigs (The Python Package)

import numpy as np
from scipy.sparse import csc_matrix
from eigs import eigs

data = np.array([ 0.+4.j,  2.+3.j,  4.+0.j,  0.-2.j, -3.+3.j,  0.-1.j,
                 -3.-3.j,  4.-4.j, -4.+0.j,  4.+1.j, -4.-1.j,  4.+2.j,
                  3.+2.j,  0.+2.j, -4.+0.j, -4.+1.j, -4.+2.j, -2.+2.j,
                 -1.-2.j,  0.+3.j, -3.+0.j,  4.+0.j, -1.+3.j])  # fmt: skip
indices = np.array([6, 1, 4, 5, 7, 2, 3, 4, 5, 6, 7, 1,
                    1, 3, 3, 4, 0, 2, 5, 6, 3, 6, 7])  # fmt: skip
indptr = np.array([0, 1, 5, 11, 12, 14, 16, 20, 23])
A = csc_matrix((data, indices, indptr))
vals, vecs = eigs(A=A, num_eigs=4, sigma=-2.0 + 7.0j)

for i, val in enumerate(vals):
    print(f"{i}: {val.real} + {val.imag}j")
0: -2.3310185657008846 + 7.624960781252993j
1: -4.525347075933688 + 1.8131068538310453j
2: 5.301183172745191 + 4.2055904210543575j
3: 0.1713950830265607 + 0.46316839127801934j

eigs (The Rust Package)

#[allow(non_snake_case)]
fn main() {
    use eigs::eigs::eigs;
    use num_complex::Complex64;
    let k = 4; // number of eigenvalues we want returned
    let n = 8; // nxn matrix A
    let Ap = vec![0, 1, 5, 11, 12, 14, 16, 20, 23];
    let Ai = vec![6, 1, 4, 5, 7, 2, 3, 4, 5, 6, 7, 1, 1, 3, 3, 4, 0, 2, 5, 6, 3, 6, 7];
    let Are = vec![0., 2., 4., 0., -3., 0., -3., 4., -4., 4., -4., 4., 3., 0., -4., -4., -4., -2., -1., 0., -3., 4., -1.];
    let Aim = vec![4., 3., 0., -2., 3., -1., -3., -4., 0., 1., -1., 2., 2., 2., 0., 1., 2., 2., -2., 3., 0., 0., 3.];
    let Ax: Vec<Complex64> = Are.iter().zip(Aim.iter())
        .map(|(re, im)| Complex64 { re: *re, im: *im })
        .collect();
    let sigma = Complex64 { re: -2.0, im: 7.0 };
    let (vals, _) = eigs(k, n, &Ap, &Ai, &Ax, sigma, None);
    for (i, val) in vals.iter().enumerate() {
        println!("{}: {} + {}j", i, val.re, val.im);
    }
}
0: -2.3310185657008846 + 7.624960781252993j
1: -4.525347075933688 + 1.8131068538310453j
2: 5.301183172745191 + 4.2055904210543575j
3: 0.1713950830265607 + 0.46316839127801934j

License & Credits

© Floris Laporte 2023, LGPL-2.1

eigs's People

Contributors

flaport avatar

Stargazers

 avatar  avatar  avatar

Watchers

 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.