Skip to content

Commit

Permalink
Merge branch 'update-lapack'
Browse files Browse the repository at this point in the history
  • Loading branch information
termoshtt committed Dec 20, 2017
2 parents 5e33905 + ee1acc4 commit 7658a76
Show file tree
Hide file tree
Showing 18 changed files with 145 additions and 79 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,7 @@ Cargo.lock

# cargo fmt
*.bk

# IntelliJ Rust
.idea
*.iml
23 changes: 10 additions & 13 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ndarray-linalg"
version = "0.7.1"
version = "0.8.0"
authors = ["Toshiki Teramura <[email protected]>"]

description = "Linear algebra package for rust-ndarray using LAPACK"
Expand All @@ -12,35 +12,32 @@ readme = "README.md"
categories = ["algorithms", "science"]

[features]
default = ["openblas-static"]
openblas-shared = ["lapack/openblas"]
openblas-static = ["lapack/openblas", "openblas-src/static"]
openblas-system = ["lapack/openblas", "openblas-src/system"]
netlib-shared = ["lapack/netlib"]
netlib-static = ["lapack/netlib", "netlib-src/static"]
netlib-system = ["lapack/netlib", "netlib-src/system"]
intel-mkl = ["intel-mkl-src"]
default = []
openblas = ["openblas-src"]
netlib = ["netlib-src"]
intel-mkl = ["intel-mkl-src"]

[dependencies]
rand = "0.3"
derive-new = "0.4"
derive-new = "0.5"
procedurals = "0.2"
num-traits = "0.1"
num-complex = "0.1"
lapack = { version = "0.13", default-features = false }
lapack-sys = { version = "0.11", default-features = false }
num-complex = { version = "0.1", default-features = false }
lapacke = "0.1.4"

[dependencies.ndarray]
version = "0.10"
default-features = false

[dependencies.openblas-src]
version = "0.5.3"
features = ["static", "cblas", "lapacke"]
default-features = false
optional = true

[dependencies.netlib-src]
version = "0.7.0"
features = ["static", "cblas", "lapacke", "tmg"]
default-features = false
optional = true

Expand Down
63 changes: 46 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,58 @@ ndarray-linalg
[![docs.rs](https://docs.rs/ndarray-linalg/badge.svg)](https://docs.rs/ndarray-linalg)
[![wercker status](https://app.wercker.com/status/f04aeba682ea6e79577e15bd946344a5/s/master "wercker status")](https://app.wercker.com/project/byKey/f04aeba682ea6e79577e15bd946344a5)

Linear algebra package for Rust.
Linear algebra package for Rust with [rust-ndarray](https://github.com/bluss/rust-ndarray).

Dependencies
-------------
LAPACKE Backend
----------------

- [bluss/rust-ndarray](https://github.com/bluss/rust-ndarray)
- [stainless-steel/lapack](https://github.com/stainless-steel/lapack)

and more (See Cargo.toml).

Feature flags
--------------
Currently three LAPACKE implementations are supported and tested:

- [OpenBLAS](https://github.com/cmr/openblas-src)
- `openblas-static`: use OpenBLAS with static link (default)
- `openblas-shared`: use OpenBLAS with shared link
- `openblas-system`: use system OpenBLAS (experimental)
- [Netlib](https://github.com/cmr/netlib-src)
- `netlib-static`: use Netlib with static link (default)
- `netlib-shared`: use Netlib with shared link
- `netlib-system`: use system Netlib (experimental)
- [Intel MKL](https://github.com/termoshtt/rust-intel-mkl) (non-free license, see the linked page)
- `intel-mkl`: use Intel MKL shared link (experimental)

There are two ways to link LAPACKE backend:

### backend features (recommended)
There are three features corresponding to the backend implementations (`openblas` / `netlib` / `intel-mkl`):

```toml
[depencdencies]
ndarray = "0.10"
ndarray-linalg = { version = "0.8", features = ["openblas"] }
```

### link backend crate manually
For the sake of linking flexibility, you can provide LAPACKE implementation (as an `extern crate`) yourself.
You should link a LAPACKE implementation to a final crate (like binary executable or dylib) only, not to a Rust library.

```toml
[depencdencies]
ndarray = "0.10"
ndarray-linalg = "0.8"
openblas-src = "0.5" # or another backend of your choice

```

You must add `extern crate` to your code in this case:

```rust
extern crate ndarray;
extern crate ndarray_linalg;
extern crate openblas_src; // or another backend of your choice
```

### For librarian
If you creating a library depending on this crate, we encourage you not to link any backend for flexibility:

```toml
[depencdencies]
ndarray = "0.10"
ndarray-linalg = { version = "0.8", default-features = false }
```

However, if you hope simplicity instead of the flexibility, you can link your favorite backend in the way described above.

Examples
---------
Expand Down
2 changes: 2 additions & 0 deletions examples/eigh.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@

extern crate ndarray;
extern crate ndarray_linalg;
#[cfg(feature = "lapack-src")]
extern crate lapack_src;

use ndarray::*;
use ndarray_linalg::*;
Expand Down
2 changes: 2 additions & 0 deletions examples/solve.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@

extern crate ndarray;
extern crate ndarray_linalg;
#[cfg(feature = "lapack-src")]
extern crate lapack_src;

use ndarray::*;
use ndarray_linalg::*;
Expand Down
2 changes: 2 additions & 0 deletions examples/solveh.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@

extern crate ndarray;
extern crate ndarray_linalg;
#[cfg(feature = "lapack-src")]
extern crate lapack_src;

use ndarray::*;
use ndarray_linalg::*;
Expand Down
10 changes: 5 additions & 5 deletions src/lapack_traits/cholesky.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Cholesky decomposition

use lapack::c;
use lapacke;

use error::*;
use layout::MatrixLayout;
Expand Down Expand Up @@ -46,7 +46,7 @@ impl Cholesky_ for $scalar {
}
}} // end macro_rules

impl_cholesky!(f64, c::dpotrf, c::dpotri, c::dpotrs);
impl_cholesky!(f32, c::spotrf, c::spotri, c::spotrs);
impl_cholesky!(c64, c::zpotrf, c::zpotri, c::zpotrs);
impl_cholesky!(c32, c::cpotrf, c::cpotri, c::cpotrs);
impl_cholesky!(f64, lapacke::dpotrf, lapacke::dpotri, lapacke::dpotrs);
impl_cholesky!(f32, lapacke::spotrf, lapacke::spotri, lapacke::spotrs);
impl_cholesky!(c64, lapacke::zpotrf, lapacke::zpotri, lapacke::zpotrs);
impl_cholesky!(c32, lapacke::cpotrf, lapacke::cpotri, lapacke::cpotrs);
10 changes: 5 additions & 5 deletions src/lapack_traits/eigh.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Eigenvalue decomposition for Hermite matrices

use lapack::c;
use lapacke;
use num_traits::Zero;

use error::*;
Expand All @@ -27,7 +27,7 @@ impl Eigh_ for $scalar {
}
}} // impl_eigh!

impl_eigh!(f64, c::dsyev);
impl_eigh!(f32, c::ssyev);
impl_eigh!(c64, c::zheev);
impl_eigh!(c32, c::cheev);
impl_eigh!(f64, lapacke::dsyev);
impl_eigh!(f32, lapacke::ssyev);
impl_eigh!(c64, lapacke::zheev);
impl_eigh!(c32, lapacke::cheev);
12 changes: 6 additions & 6 deletions src/lapack_traits/opnorm.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Operator norms of matrices

use lapack::c;
use lapack::c::Layout::ColumnMajor as cm;
use lapacke;
use lapacke::Layout::ColumnMajor as cm;

use layout::MatrixLayout;
use types::*;
Expand All @@ -24,7 +24,7 @@ impl OperatorNorm_ for $scalar {
}
}} // impl_opnorm!

impl_opnorm!(f64, c::dlange);
impl_opnorm!(f32, c::slange);
impl_opnorm!(c64, c::zlange);
impl_opnorm!(c32, c::clange);
impl_opnorm!(f64, lapacke::dlange);
impl_opnorm!(f32, lapacke::slange);
impl_opnorm!(c64, lapacke::zlange);
impl_opnorm!(c32, lapacke::clange);
10 changes: 5 additions & 5 deletions src/lapack_traits/qr.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! QR decomposition

use lapack::c;
use lapacke;
use num_traits::Zero;
use std::cmp::min;

Expand Down Expand Up @@ -44,7 +44,7 @@ impl QR_ for $scalar {
}
}} // endmacro

impl_qr!(f64, c::dgeqrf, c::dorgqr);
impl_qr!(f32, c::sgeqrf, c::sorgqr);
impl_qr!(c64, c::zgeqrf, c::zungqr);
impl_qr!(c32, c::cgeqrf, c::cungqr);
impl_qr!(f64, lapacke::dgeqrf, lapacke::dorgqr);
impl_qr!(f32, lapacke::sgeqrf, lapacke::sorgqr);
impl_qr!(c64, lapacke::zgeqrf, lapacke::zungqr);
impl_qr!(c32, lapacke::cgeqrf, lapacke::cungqr);
34 changes: 29 additions & 5 deletions src/lapack_traits/solve.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Solve linear problem using LU decomposition

use lapack::c;
use lapacke;

use error::*;
use layout::MatrixLayout;
Expand Down Expand Up @@ -65,7 +65,31 @@ impl Solve_ for $scalar {

}} // impl_solve!

impl_solve!(f64, c::dgetrf, c::dgetri, c::dgecon, c::dgetrs);
impl_solve!(f32, c::sgetrf, c::sgetri, c::sgecon, c::sgetrs);
impl_solve!(c64, c::zgetrf, c::zgetri, c::zgecon, c::zgetrs);
impl_solve!(c32, c::cgetrf, c::cgetri, c::cgecon, c::cgetrs);
impl_solve!(
f64,
lapacke::dgetrf,
lapacke::dgetri,
lapacke::dgecon,
lapacke::dgetrs
);
impl_solve!(
f32,
lapacke::sgetrf,
lapacke::sgetri,
lapacke::sgecon,
lapacke::sgetrs
);
impl_solve!(
c64,
lapacke::zgetrf,
lapacke::zgetri,
lapacke::zgecon,
lapacke::zgetrs
);
impl_solve!(
c32,
lapacke::cgetrf,
lapacke::cgetri,
lapacke::cgecon,
lapacke::cgetrs
);
10 changes: 5 additions & 5 deletions src/lapack_traits/solveh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//!
//! See also [the manual of dsytrf](http://www.netlib.org/lapack/lapack-3.1.1/html/dsytrf.f.html)

use lapack::c;
use lapacke;

use error::*;
use layout::MatrixLayout;
Expand Down Expand Up @@ -55,7 +55,7 @@ impl Solveh_ for $scalar {

}} // impl_solveh!

impl_solveh!(f64, c::dsytrf, c::dsytri, c::dsytrs);
impl_solveh!(f32, c::ssytrf, c::ssytri, c::ssytrs);
impl_solveh!(c64, c::zhetrf, c::zhetri, c::zhetrs);
impl_solveh!(c32, c::chetrf, c::chetri, c::chetrs);
impl_solveh!(f64, lapacke::dsytrf, lapacke::dsytri, lapacke::dsytrs);
impl_solveh!(f32, lapacke::ssytrf, lapacke::ssytri, lapacke::ssytrs);
impl_solveh!(c64, lapacke::zhetrf, lapacke::zhetri, lapacke::zhetrs);
impl_solveh!(c32, lapacke::chetrf, lapacke::chetri, lapacke::chetrs);
10 changes: 5 additions & 5 deletions src/lapack_traits/svd.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Singular-value decomposition

use lapack::c;
use lapacke;
use num_traits::Zero;

use error::*;
Expand Down Expand Up @@ -63,7 +63,7 @@ impl SVD_ for $scalar {

}} // impl_svd!

impl_svd!(f64, c::dgesvd);
impl_svd!(f32, c::sgesvd);
impl_svd!(c64, c::zgesvd);
impl_svd!(c32, c::cgesvd);
impl_svd!(f64, lapacke::dgesvd);
impl_svd!(f32, lapacke::sgesvd);
impl_svd!(c64, lapacke::zgesvd);
impl_svd!(c32, lapacke::cgesvd);
10 changes: 5 additions & 5 deletions src/lapack_traits/triangular.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Implement linear solver and inverse matrix

use lapack::c;
use lapacke;

use super::{Transpose, UPLO, into_result};
use error::*;
Expand Down Expand Up @@ -50,7 +50,7 @@ impl Triangular_ for $scalar {

}} // impl_triangular!

impl_triangular!(f64, c::dtrtri, c::dtrtrs);
impl_triangular!(f32, c::strtri, c::strtrs);
impl_triangular!(c64, c::ztrtri, c::ztrtrs);
impl_triangular!(c32, c::ctrtri, c::ctrtrs);
impl_triangular!(f64, lapacke::dtrtri, lapacke::dtrtrs);
impl_triangular!(f32, lapacke::strtri, lapacke::strtrs);
impl_triangular!(c64, lapacke::ztrtri, lapacke::ztrtrs);
impl_triangular!(c32, lapacke::ctrtri, lapacke::ctrtrs);
8 changes: 4 additions & 4 deletions src/layout.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Memory layout of matrices

use lapack::c;
use lapacke;
use ndarray::*;

use super::error::*;
Expand Down Expand Up @@ -45,10 +45,10 @@ impl MatrixLayout {
}
}

pub fn lapacke_layout(&self) -> c::Layout {
pub fn lapacke_layout(&self) -> lapacke::Layout {
match *self {
MatrixLayout::C(_) => c::Layout::RowMajor,
MatrixLayout::F(_) => c::Layout::ColumnMajor,
MatrixLayout::C(_) => lapacke::Layout::RowMajor,
MatrixLayout::F(_) => lapacke::Layout::ColumnMajor,
}
}

Expand Down
9 changes: 7 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
//! - [generator functions](generate/index.html)
//! - [Scalar trait](types/trait.Scalar.html)

extern crate lapack;
extern crate lapack_sys;
extern crate lapacke;
extern crate num_traits;
extern crate num_complex;
extern crate rand;
Expand All @@ -29,6 +28,12 @@ extern crate procedurals;
#[macro_use]
extern crate derive_new;

#[cfg(feature = "openblas")]
extern crate openblas_src;

#[cfg(feature = "netlib")]
extern crate netlib_src;

#[cfg(feature = "intel-mkl")]
extern crate intel_mkl_src;

Expand Down
Loading

0 comments on commit 7658a76

Please sign in to comment.