Skip to content

Rewrite LAPACKE by Rust, call LAPACK directly #206

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 61 commits into from
Jul 26, 2020
Merged
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
e652fcc
Add lapack and blas
termoshtt Jun 29, 2020
77b6269
Rewrite lapack::eigh using lapack crate
termoshtt Jun 30, 2020
e4ee6d6
Split eigenvalue and eigenvector tests
termoshtt Jul 5, 2020
27f5bfb
Add doctest
termoshtt Jul 5, 2020
261e79a
Impl eig using LAPACK instead of LAPACKE
termoshtt Jul 5, 2020
f7d93f4
Fix unsafe signature
termoshtt Jul 5, 2020
a7dc42c
Impl solve using LAPACK
termoshtt Jul 6, 2020
b6e48b9
Handling empty matrix case
termoshtt Jul 10, 2020
c9b6d13
Handle norm type based on matrix layout
termoshtt Jul 10, 2020
43908b0
Merge pull request #213 from rust-ndarray/lapack-solve
termoshtt Jul 10, 2020
ea91231
Impl bk, solveh, and invh using LAPACK
termoshtt Jul 10, 2020
9ccb6af
Revise deth
termoshtt Jul 10, 2020
fc1fca3
Merge pull request #216 from rust-ndarray/lapack-solveh
termoshtt Jul 10, 2020
62c950a
Merge branch 'master' into lapack
termoshtt Jul 10, 2020
34c7f5a
Drop unsafe of solveh and others in #216
termoshtt Jul 10, 2020
ea930d0
SVD using LAPACK
termoshtt Jul 11, 2020
2373b43
Add test for complex in SVD
termoshtt Jul 11, 2020
7e0f582
Merge pull request #218 from rust-ndarray/lapack-svd
termoshtt Jul 11, 2020
cb30107
Split real/complex of svddc
termoshtt Jul 12, 2020
8afd53c
Rewrite impl_svddc_real
termoshtt Jul 12, 2020
797b71b
Add svddc test for complex numbers
termoshtt Jul 13, 2020
acb88aa
Impl SVDDC_ for c32/c64
termoshtt Jul 13, 2020
cf56af5
Use convert::into_matrix
termoshtt Jul 13, 2020
8c1b069
Merge pull request #219 from rust-ndarray/lapack-svddc
termoshtt Jul 13, 2020
8b23d8c
Merge impl_svd_{real,complex} macros
termoshtt Jul 15, 2020
e3a7767
Merge impl_eigh! and impl_eighc!
termoshtt Jul 15, 2020
a21f738
Merge pull request #221 from rust-ndarray/lapack-merge-macros
termoshtt Jul 15, 2020
bdb2ffb
Merge branch 'master' into lapack
termoshtt Jul 15, 2020
cbe6df7
Rewrite QR using LAPACK
termoshtt Jul 16, 2020
64e37bf
Merge pull request #224 from rust-ndarray/lapack-qr
termoshtt Jul 17, 2020
5f2b598
clippy mem::replace must_use warning
termoshtt Jul 17, 2020
4a96e4d
Use into_matrix
termoshtt Jul 17, 2020
e352347
Drop unsafe of cholesky
termoshtt Jul 17, 2020
df396b5
WIP
termoshtt Jul 17, 2020
5f6a2c3
Rewrite opnorm by LAPACK
termoshtt Jul 17, 2020
06a6c65
square_transpose
termoshtt Jul 18, 2020
76c06d4
Split tests of cholesky
termoshtt Jul 18, 2020
44b2adb
Take complex conjugate
termoshtt Jul 18, 2020
fea408d
Merge pull request #225 from rust-ndarray/lapack-cholesky
termoshtt Jul 18, 2020
ffb6bef
Merge branch 'master' into lapack
termoshtt Jul 24, 2020
d7cf503
Split impl for real based on LAPACK
termoshtt Jul 15, 2020
45c7170
Query liwork
termoshtt Jul 15, 2020
6df2779
Use least_squares_nrhs for 1-dim b case
termoshtt Jul 15, 2020
f417f6f
Fix test scalar types
termoshtt Jul 24, 2020
8ff555d
Out-place transpose
termoshtt Jul 24, 2020
200b9d4
Take transpose
termoshtt Jul 25, 2020
87f0cea
Support complex case
termoshtt Jul 25, 2020
b742f6f
Fix assert to support under-determined case
termoshtt Jul 25, 2020
5ad4343
Enable tests for C/F mixed cases #234
termoshtt Jul 25, 2020
00b044b
Fix error handling
termoshtt Jul 25, 2020
962497e
Drop unsafe
termoshtt Jul 25, 2020
24888ec
Merge pull request #220 from rust-ndarray/lapack-least-square
termoshtt Jul 25, 2020
e9c3481
Impl triangular inv/solve using LAPACK
termoshtt Jul 25, 2020
373a18a
Impl tridiagonal by LAPACK
termoshtt Jul 25, 2020
46b0dcd
Transpose if C-contiguous
termoshtt Jul 26, 2020
2a6154f
Drop unsafe
termoshtt Jul 26, 2020
f86d104
Merge pull request #235 from rust-ndarray/lapack-tridiagonal
termoshtt Jul 26, 2020
29bef1a
Remove lapacke dep
termoshtt Jul 26, 2020
6f870a5
Remove unnecessarily unsafe
termoshtt Jul 26, 2020
d470ad2
Remove unnecessary unsafe more
termoshtt Jul 26, 2020
6571d86
Use sup norm for testing least_squares
termoshtt Jul 26, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lax/Cargo.toml
Original file line number Diff line number Diff line change
@@ -11,10 +11,10 @@ netlib = ["lapack-src/netlib", "blas-src/netlib"]
openblas = ["lapack-src/openblas", "blas-src/openblas"]

[dependencies]
thiserror = "1"
cauchy = "0.2"
lapacke = "0.2.0"
thiserror = "1.0"
cauchy = "0.2.0"
num-traits = "0.2"
lapack = "0.16.0"

[dependencies.blas-src]
version = "0.6.1"
70 changes: 52 additions & 18 deletions lax/src/cholesky.rs
Original file line number Diff line number Diff line change
@@ -1,56 +1,90 @@
//! Cholesky decomposition
use super::*;
use crate::{error::*, layout::MatrixLayout};
use crate::{error::*, layout::*};
use cauchy::*;

pub trait Cholesky_: Sized {
/// Cholesky: wrapper of `*potrf`
///
/// **Warning: Only the portion of `a` corresponding to `UPLO` is written.**
unsafe fn cholesky(l: MatrixLayout, uplo: UPLO, a: &mut [Self]) -> Result<()>;
fn cholesky(l: MatrixLayout, uplo: UPLO, a: &mut [Self]) -> Result<()>;

/// Wrapper of `*potri`
///
/// **Warning: Only the portion of `a` corresponding to `UPLO` is written.**
unsafe fn inv_cholesky(l: MatrixLayout, uplo: UPLO, a: &mut [Self]) -> Result<()>;
fn inv_cholesky(l: MatrixLayout, uplo: UPLO, a: &mut [Self]) -> Result<()>;

/// Wrapper of `*potrs`
unsafe fn solve_cholesky(l: MatrixLayout, uplo: UPLO, a: &[Self], b: &mut [Self])
-> Result<()>;
fn solve_cholesky(l: MatrixLayout, uplo: UPLO, a: &[Self], b: &mut [Self]) -> Result<()>;
}

macro_rules! impl_cholesky {
($scalar:ty, $trf:path, $tri:path, $trs:path) => {
impl Cholesky_ for $scalar {
unsafe fn cholesky(l: MatrixLayout, uplo: UPLO, a: &mut [Self]) -> Result<()> {
fn cholesky(l: MatrixLayout, uplo: UPLO, a: &mut [Self]) -> Result<()> {
let (n, _) = l.size();
$trf(l.lapacke_layout(), uplo as u8, n, a, n).as_lapack_result()?;
if matches!(l, MatrixLayout::C { .. }) {
square_transpose(l, a);
}
let mut info = 0;
unsafe {
$trf(uplo as u8, n, a, n, &mut info);
}
info.as_lapack_result()?;
if matches!(l, MatrixLayout::C { .. }) {
square_transpose(l, a);
}
Ok(())
}

unsafe fn inv_cholesky(l: MatrixLayout, uplo: UPLO, a: &mut [Self]) -> Result<()> {
fn inv_cholesky(l: MatrixLayout, uplo: UPLO, a: &mut [Self]) -> Result<()> {
let (n, _) = l.size();
$tri(l.lapacke_layout(), uplo as u8, n, a, l.lda()).as_lapack_result()?;
if matches!(l, MatrixLayout::C { .. }) {
square_transpose(l, a);
}
let mut info = 0;
unsafe {
$tri(uplo as u8, n, a, l.lda(), &mut info);
}
info.as_lapack_result()?;
if matches!(l, MatrixLayout::C { .. }) {
square_transpose(l, a);
}
Ok(())
}

unsafe fn solve_cholesky(
fn solve_cholesky(
l: MatrixLayout,
uplo: UPLO,
mut uplo: UPLO,
a: &[Self],
b: &mut [Self],
) -> Result<()> {
let (n, _) = l.size();
let nrhs = 1;
let ldb = 1;
$trs(l.lapacke_layout(), uplo as u8, n, nrhs, a, l.lda(), b, ldb)
.as_lapack_result()?;
let mut info = 0;
if matches!(l, MatrixLayout::C { .. }) {
uplo = uplo.t();
for val in b.iter_mut() {
*val = val.conj();
}
}
unsafe {
$trs(uplo as u8, n, nrhs, a, l.lda(), b, n, &mut info);
}
info.as_lapack_result()?;
if matches!(l, MatrixLayout::C { .. }) {
for val in b.iter_mut() {
*val = val.conj();
}
}
Ok(())
}
}
};
} // end macro_rules

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);
impl_cholesky!(f64, lapack::dpotrf, lapack::dpotri, lapack::dpotrs);
impl_cholesky!(f32, lapack::spotrf, lapack::spotri, lapack::spotrs);
impl_cholesky!(c64, lapack::zpotrf, lapack::zpotri, lapack::zpotrs);
impl_cholesky!(c32, lapack::cpotrf, lapack::cpotri, lapack::cpotrs);
Loading