Skip to content

Commit 7658a76

Browse files
committed
Merge branch 'update-lapack'
2 parents 5e33905 + ee1acc4 commit 7658a76

File tree

18 files changed

+145
-79
lines changed

18 files changed

+145
-79
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,7 @@ Cargo.lock
1010

1111
# cargo fmt
1212
*.bk
13+
14+
# IntelliJ Rust
15+
.idea
16+
*.iml

Cargo.toml

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "ndarray-linalg"
3-
version = "0.7.1"
3+
version = "0.8.0"
44
authors = ["Toshiki Teramura <[email protected]>"]
55

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

1414
[features]
15-
default = ["openblas-static"]
16-
openblas-shared = ["lapack/openblas"]
17-
openblas-static = ["lapack/openblas", "openblas-src/static"]
18-
openblas-system = ["lapack/openblas", "openblas-src/system"]
19-
netlib-shared = ["lapack/netlib"]
20-
netlib-static = ["lapack/netlib", "netlib-src/static"]
21-
netlib-system = ["lapack/netlib", "netlib-src/system"]
22-
intel-mkl = ["intel-mkl-src"]
15+
default = []
16+
openblas = ["openblas-src"]
17+
netlib = ["netlib-src"]
18+
intel-mkl = ["intel-mkl-src"]
2319

2420
[dependencies]
2521
rand = "0.3"
26-
derive-new = "0.4"
22+
derive-new = "0.5"
2723
procedurals = "0.2"
2824
num-traits = "0.1"
29-
num-complex = "0.1"
30-
lapack = { version = "0.13", default-features = false }
31-
lapack-sys = { version = "0.11", default-features = false }
25+
num-complex = { version = "0.1", default-features = false }
26+
lapacke = "0.1.4"
3227

3328
[dependencies.ndarray]
3429
version = "0.10"
3530
default-features = false
3631

3732
[dependencies.openblas-src]
3833
version = "0.5.3"
34+
features = ["static", "cblas", "lapacke"]
3935
default-features = false
4036
optional = true
4137

4238
[dependencies.netlib-src]
4339
version = "0.7.0"
40+
features = ["static", "cblas", "lapacke", "tmg"]
4441
default-features = false
4542
optional = true
4643

README.md

Lines changed: 46 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,58 @@ ndarray-linalg
44
[![docs.rs](https://docs.rs/ndarray-linalg/badge.svg)](https://docs.rs/ndarray-linalg)
55
[![wercker status](https://app.wercker.com/status/f04aeba682ea6e79577e15bd946344a5/s/master "wercker status")](https://app.wercker.com/project/byKey/f04aeba682ea6e79577e15bd946344a5)
66

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

9-
Dependencies
10-
-------------
9+
LAPACKE Backend
10+
----------------
1111

12-
- [bluss/rust-ndarray](https://github.com/bluss/rust-ndarray)
13-
- [stainless-steel/lapack](https://github.com/stainless-steel/lapack)
14-
15-
and more (See Cargo.toml).
16-
17-
Feature flags
18-
--------------
12+
Currently three LAPACKE implementations are supported and tested:
1913

2014
- [OpenBLAS](https://github.com/cmr/openblas-src)
21-
- `openblas-static`: use OpenBLAS with static link (default)
22-
- `openblas-shared`: use OpenBLAS with shared link
23-
- `openblas-system`: use system OpenBLAS (experimental)
2415
- [Netlib](https://github.com/cmr/netlib-src)
25-
- `netlib-static`: use Netlib with static link (default)
26-
- `netlib-shared`: use Netlib with shared link
27-
- `netlib-system`: use system Netlib (experimental)
2816
- [Intel MKL](https://github.com/termoshtt/rust-intel-mkl) (non-free license, see the linked page)
29-
- `intel-mkl`: use Intel MKL shared link (experimental)
17+
18+
There are two ways to link LAPACKE backend:
19+
20+
### backend features (recommended)
21+
There are three features corresponding to the backend implementations (`openblas` / `netlib` / `intel-mkl`):
22+
23+
```toml
24+
[depencdencies]
25+
ndarray = "0.10"
26+
ndarray-linalg = { version = "0.8", features = ["openblas"] }
27+
```
28+
29+
### link backend crate manually
30+
For the sake of linking flexibility, you can provide LAPACKE implementation (as an `extern crate`) yourself.
31+
You should link a LAPACKE implementation to a final crate (like binary executable or dylib) only, not to a Rust library.
32+
33+
```toml
34+
[depencdencies]
35+
ndarray = "0.10"
36+
ndarray-linalg = "0.8"
37+
openblas-src = "0.5" # or another backend of your choice
38+
39+
```
40+
41+
You must add `extern crate` to your code in this case:
42+
43+
```rust
44+
extern crate ndarray;
45+
extern crate ndarray_linalg;
46+
extern crate openblas_src; // or another backend of your choice
47+
```
48+
49+
### For librarian
50+
If you creating a library depending on this crate, we encourage you not to link any backend for flexibility:
51+
52+
```toml
53+
[depencdencies]
54+
ndarray = "0.10"
55+
ndarray-linalg = { version = "0.8", default-features = false }
56+
```
57+
58+
However, if you hope simplicity instead of the flexibility, you can link your favorite backend in the way described above.
3059

3160
Examples
3261
---------

examples/eigh.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11

22
extern crate ndarray;
33
extern crate ndarray_linalg;
4+
#[cfg(feature = "lapack-src")]
5+
extern crate lapack_src;
46

57
use ndarray::*;
68
use ndarray_linalg::*;

examples/solve.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11

22
extern crate ndarray;
33
extern crate ndarray_linalg;
4+
#[cfg(feature = "lapack-src")]
5+
extern crate lapack_src;
46

57
use ndarray::*;
68
use ndarray_linalg::*;

examples/solveh.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11

22
extern crate ndarray;
33
extern crate ndarray_linalg;
4+
#[cfg(feature = "lapack-src")]
5+
extern crate lapack_src;
46

57
use ndarray::*;
68
use ndarray_linalg::*;

src/lapack_traits/cholesky.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Cholesky decomposition
22
3-
use lapack::c;
3+
use lapacke;
44

55
use error::*;
66
use layout::MatrixLayout;
@@ -46,7 +46,7 @@ impl Cholesky_ for $scalar {
4646
}
4747
}} // end macro_rules
4848

49-
impl_cholesky!(f64, c::dpotrf, c::dpotri, c::dpotrs);
50-
impl_cholesky!(f32, c::spotrf, c::spotri, c::spotrs);
51-
impl_cholesky!(c64, c::zpotrf, c::zpotri, c::zpotrs);
52-
impl_cholesky!(c32, c::cpotrf, c::cpotri, c::cpotrs);
49+
impl_cholesky!(f64, lapacke::dpotrf, lapacke::dpotri, lapacke::dpotrs);
50+
impl_cholesky!(f32, lapacke::spotrf, lapacke::spotri, lapacke::spotrs);
51+
impl_cholesky!(c64, lapacke::zpotrf, lapacke::zpotri, lapacke::zpotrs);
52+
impl_cholesky!(c32, lapacke::cpotrf, lapacke::cpotri, lapacke::cpotrs);

src/lapack_traits/eigh.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Eigenvalue decomposition for Hermite matrices
22
3-
use lapack::c;
3+
use lapacke;
44
use num_traits::Zero;
55

66
use error::*;
@@ -27,7 +27,7 @@ impl Eigh_ for $scalar {
2727
}
2828
}} // impl_eigh!
2929

30-
impl_eigh!(f64, c::dsyev);
31-
impl_eigh!(f32, c::ssyev);
32-
impl_eigh!(c64, c::zheev);
33-
impl_eigh!(c32, c::cheev);
30+
impl_eigh!(f64, lapacke::dsyev);
31+
impl_eigh!(f32, lapacke::ssyev);
32+
impl_eigh!(c64, lapacke::zheev);
33+
impl_eigh!(c32, lapacke::cheev);

src/lapack_traits/opnorm.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Operator norms of matrices
22
3-
use lapack::c;
4-
use lapack::c::Layout::ColumnMajor as cm;
3+
use lapacke;
4+
use lapacke::Layout::ColumnMajor as cm;
55

66
use layout::MatrixLayout;
77
use types::*;
@@ -24,7 +24,7 @@ impl OperatorNorm_ for $scalar {
2424
}
2525
}} // impl_opnorm!
2626

27-
impl_opnorm!(f64, c::dlange);
28-
impl_opnorm!(f32, c::slange);
29-
impl_opnorm!(c64, c::zlange);
30-
impl_opnorm!(c32, c::clange);
27+
impl_opnorm!(f64, lapacke::dlange);
28+
impl_opnorm!(f32, lapacke::slange);
29+
impl_opnorm!(c64, lapacke::zlange);
30+
impl_opnorm!(c32, lapacke::clange);

src/lapack_traits/qr.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! QR decomposition
22
3-
use lapack::c;
3+
use lapacke;
44
use num_traits::Zero;
55
use std::cmp::min;
66

@@ -44,7 +44,7 @@ impl QR_ for $scalar {
4444
}
4545
}} // endmacro
4646

47-
impl_qr!(f64, c::dgeqrf, c::dorgqr);
48-
impl_qr!(f32, c::sgeqrf, c::sorgqr);
49-
impl_qr!(c64, c::zgeqrf, c::zungqr);
50-
impl_qr!(c32, c::cgeqrf, c::cungqr);
47+
impl_qr!(f64, lapacke::dgeqrf, lapacke::dorgqr);
48+
impl_qr!(f32, lapacke::sgeqrf, lapacke::sorgqr);
49+
impl_qr!(c64, lapacke::zgeqrf, lapacke::zungqr);
50+
impl_qr!(c32, lapacke::cgeqrf, lapacke::cungqr);

src/lapack_traits/solve.rs

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Solve linear problem using LU decomposition
22
3-
use lapack::c;
3+
use lapacke;
44

55
use error::*;
66
use layout::MatrixLayout;
@@ -65,7 +65,31 @@ impl Solve_ for $scalar {
6565

6666
}} // impl_solve!
6767

68-
impl_solve!(f64, c::dgetrf, c::dgetri, c::dgecon, c::dgetrs);
69-
impl_solve!(f32, c::sgetrf, c::sgetri, c::sgecon, c::sgetrs);
70-
impl_solve!(c64, c::zgetrf, c::zgetri, c::zgecon, c::zgetrs);
71-
impl_solve!(c32, c::cgetrf, c::cgetri, c::cgecon, c::cgetrs);
68+
impl_solve!(
69+
f64,
70+
lapacke::dgetrf,
71+
lapacke::dgetri,
72+
lapacke::dgecon,
73+
lapacke::dgetrs
74+
);
75+
impl_solve!(
76+
f32,
77+
lapacke::sgetrf,
78+
lapacke::sgetri,
79+
lapacke::sgecon,
80+
lapacke::sgetrs
81+
);
82+
impl_solve!(
83+
c64,
84+
lapacke::zgetrf,
85+
lapacke::zgetri,
86+
lapacke::zgecon,
87+
lapacke::zgetrs
88+
);
89+
impl_solve!(
90+
c32,
91+
lapacke::cgetrf,
92+
lapacke::cgetri,
93+
lapacke::cgecon,
94+
lapacke::cgetrs
95+
);

src/lapack_traits/solveh.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//!
33
//! See also [the manual of dsytrf](http://www.netlib.org/lapack/lapack-3.1.1/html/dsytrf.f.html)
44
5-
use lapack::c;
5+
use lapacke;
66

77
use error::*;
88
use layout::MatrixLayout;
@@ -55,7 +55,7 @@ impl Solveh_ for $scalar {
5555

5656
}} // impl_solveh!
5757

58-
impl_solveh!(f64, c::dsytrf, c::dsytri, c::dsytrs);
59-
impl_solveh!(f32, c::ssytrf, c::ssytri, c::ssytrs);
60-
impl_solveh!(c64, c::zhetrf, c::zhetri, c::zhetrs);
61-
impl_solveh!(c32, c::chetrf, c::chetri, c::chetrs);
58+
impl_solveh!(f64, lapacke::dsytrf, lapacke::dsytri, lapacke::dsytrs);
59+
impl_solveh!(f32, lapacke::ssytrf, lapacke::ssytri, lapacke::ssytrs);
60+
impl_solveh!(c64, lapacke::zhetrf, lapacke::zhetri, lapacke::zhetrs);
61+
impl_solveh!(c32, lapacke::chetrf, lapacke::chetri, lapacke::chetrs);

src/lapack_traits/svd.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Singular-value decomposition
22
3-
use lapack::c;
3+
use lapacke;
44
use num_traits::Zero;
55

66
use error::*;
@@ -63,7 +63,7 @@ impl SVD_ for $scalar {
6363

6464
}} // impl_svd!
6565

66-
impl_svd!(f64, c::dgesvd);
67-
impl_svd!(f32, c::sgesvd);
68-
impl_svd!(c64, c::zgesvd);
69-
impl_svd!(c32, c::cgesvd);
66+
impl_svd!(f64, lapacke::dgesvd);
67+
impl_svd!(f32, lapacke::sgesvd);
68+
impl_svd!(c64, lapacke::zgesvd);
69+
impl_svd!(c32, lapacke::cgesvd);

src/lapack_traits/triangular.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Implement linear solver and inverse matrix
22
3-
use lapack::c;
3+
use lapacke;
44

55
use super::{Transpose, UPLO, into_result};
66
use error::*;
@@ -50,7 +50,7 @@ impl Triangular_ for $scalar {
5050

5151
}} // impl_triangular!
5252

53-
impl_triangular!(f64, c::dtrtri, c::dtrtrs);
54-
impl_triangular!(f32, c::strtri, c::strtrs);
55-
impl_triangular!(c64, c::ztrtri, c::ztrtrs);
56-
impl_triangular!(c32, c::ctrtri, c::ctrtrs);
53+
impl_triangular!(f64, lapacke::dtrtri, lapacke::dtrtrs);
54+
impl_triangular!(f32, lapacke::strtri, lapacke::strtrs);
55+
impl_triangular!(c64, lapacke::ztrtri, lapacke::ztrtrs);
56+
impl_triangular!(c32, lapacke::ctrtri, lapacke::ctrtrs);

src/layout.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Memory layout of matrices
22
3-
use lapack::c;
3+
use lapacke;
44
use ndarray::*;
55

66
use super::error::*;
@@ -45,10 +45,10 @@ impl MatrixLayout {
4545
}
4646
}
4747

48-
pub fn lapacke_layout(&self) -> c::Layout {
48+
pub fn lapacke_layout(&self) -> lapacke::Layout {
4949
match *self {
50-
MatrixLayout::C(_) => c::Layout::RowMajor,
51-
MatrixLayout::F(_) => c::Layout::ColumnMajor,
50+
MatrixLayout::C(_) => lapacke::Layout::RowMajor,
51+
MatrixLayout::F(_) => lapacke::Layout::ColumnMajor,
5252
}
5353
}
5454

src/lib.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@
1717
//! - [generator functions](generate/index.html)
1818
//! - [Scalar trait](types/trait.Scalar.html)
1919
20-
extern crate lapack;
21-
extern crate lapack_sys;
20+
extern crate lapacke;
2221
extern crate num_traits;
2322
extern crate num_complex;
2423
extern crate rand;
@@ -29,6 +28,12 @@ extern crate procedurals;
2928
#[macro_use]
3029
extern crate derive_new;
3130

31+
#[cfg(feature = "openblas")]
32+
extern crate openblas_src;
33+
34+
#[cfg(feature = "netlib")]
35+
extern crate netlib_src;
36+
3237
#[cfg(feature = "intel-mkl")]
3338
extern crate intel_mkl_src;
3439

0 commit comments

Comments
 (0)