Skip to content

Commit 4937702

Browse files
authored
Feature/qr and colpiv qr improvements and solver (#1561)
* add coupled blas and lapack dependency * factor out some qr code so I can reuse it from the unpivoted qr implementation * update internal docs, add safety checks * factor out qr solver as well * start reworking the (colpiv) qr traits * factor out error * rework qr traits for better error handling * start unifying colpiv qr and qr trait interfaces to lapack * unification of qr traits complete * kill some useless trait bounds * add solver and q multiplication methods to the non-pivoted qr factorization * more cleanups and refactorings * add trmm interface * start with r multiplication stuff * start with unifying qr implementation * unify calculation logic for most of qr logic in one trait * doc updates * export decomposition from crate root * start with left R multiplication functions * R*B and R^T*B multiplication * r mul mut test failing * r multiplication rework * restrict QR decomposition to overdetermined system m>=n * docs and changelog * fix snafu * more exhaustive tests for QR decomposition * update docs * update changelog * add tests for Q^T, Q multiplication from left and right * improve trmm impl * add R, R^T multiplication functionality from left and right * add proptests for Q multiplication * update changelog * [ai assisted, manually reviewed] updates to documentation * better safeguards for lapack calls
1 parent 57b83b8 commit 4937702

File tree

21 files changed

+1787
-989
lines changed

21 files changed

+1787
-989
lines changed

nalgebra-lapack/CHANGELOG.md

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,38 @@ For the **changes between versions 0.4.0 and 0.27.0** see the main
55

66
## Unreleased
77

8-
* bugfixes in Schur decomposition
9-
* bugfixes in LU decomposition
10-
* fix failing tests for Cholesky decomposition
11-
* fix compilation with `serde-serialize` feature enabled
12-
* add column-pivoting QR decomposition and solver
13-
* fix logic error in calculation of complex eigenvalues in eigen-decomposition.
14-
* change the feature flags for choosing the lapack backend, update docs accordingly
8+
* Bugfixes in Schur decomposition
9+
* Bugfixes in LU decomposition
10+
* Fix failing tests for Cholesky decomposition
11+
* Fix compilation with `serde-serialize` feature enabled
12+
* Add column-pivoting QR decomposition and solver
13+
* Introduce a common, trait-based interface to QR and column-pivoted QR
14+
* Extend QR decompositions to allow multiplication with Q, Q^T, R, R^T efficiently
15+
from both sides
16+
* Fix logic error in calculation of complex eigenvalues in eigen-decomposition
17+
* Change the feature flags for choosing the LAPACK backend, update docs accordingly
18+
* Remove untested complex support in QR decomposition
19+
* Remove `Qr::unpack`, since it brings no practical benefit over `(qr.q(), qr.r())`,
20+
but looks like it would bring an efficiency gain
21+
* QR decomposition restricted to m >= n
1522

1623
## [0.4.0] - 2016-09-07
1724

1825
* Made all traits use associated types for their output type parameters. This
1926
simplifies usage of the traits and is consistent with the concept of
2027
associated types used as output type parameters (not input type parameters) as
2128
described in [the associated type
22-
RFC](https://github.com/rust-lang/rfcs/blob/master/text/0195-associated-items.md).
23-
* Implemented `check_info!` macro to check all LAPACK calls.
24-
* Implemented error handling with [error_chain](https://crates.io/crates/error-chain).
29+
RFC](https://github.com/rust-lang/rfcs/blob/master/text/0195-associated-items.md)
30+
* Implemented `check_info!` macro to check all LAPACK calls
31+
* Implemented error handling with [error_chain](https://crates.io/crates/error-chain)
2532

2633
## [0.3.0] - 2016-09-06
2734

2835
* Documentation is hosted at https://docs.rs/nalgebra-lapack/
29-
* Updated `nalgebra` to 0.10.
30-
* Rename traits `HasSVD` to `SVD` and `HasEigensystem` to `Eigensystem`.
31-
* Added `Solve` trait for solving a linear matrix equation.
32-
* Added `Inverse` for computing the multiplicative inverse of a matrix.
33-
* Added `Cholesky` for decomposing a positive-definite matrix.
36+
* Updated `nalgebra` to 0.10
37+
* Rename traits `HasSVD` to `SVD` and `HasEigensystem` to `Eigensystem`
38+
* Added `Solve` trait for solving a linear matrix equation
39+
* Added `Inverse` for computing the multiplicative inverse of a matrix
40+
* Added `Cholesky` for decomposing a positive-definite matrix
3441
* The `Eigensystem` and `SVD` traits are now generic over types. The
35-
associated types have been removed.
42+
associated types have been removed

nalgebra-lapack/Cargo.toml

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ authors = ["Sébastien Crozet <developer@crozet.re>", "Andrew Straw <strawman@as
66
description = "Matrix decompositions using nalgebra matrices and Lapack bindings."
77
homepage = "https://nalgebra.rs"
88
repository = "https://github.com/dimforge/nalgebra"
9-
readme = "../README.md"
9+
readme = "README.md"
1010
categories = ["science", "mathematics"]
1111
keywords = ["linear", "algebra", "matrix", "vector", "lapack"]
1212
license = "MIT"
@@ -23,14 +23,14 @@ arbitrary = ["nalgebra/arbitrary"]
2323
slow-tests = []
2424

2525
# For BLAS/LAPACK
26-
lapack-openblas = ["lapack-src/openblas"]
27-
lapack-netlib = ["lapack-src/netlib"]
28-
lapack-accelerate = ["lapack-src/accelerate"]
26+
lapack-openblas = ["lapack-src/openblas", "blas-src/openblas"]
27+
lapack-netlib = ["lapack-src/netlib", "blas-src/netlib"]
28+
lapack-accelerate = ["lapack-src/accelerate", "blas-src/accelerate"]
2929
lapack-mkl = ["lapack-mkl-static-seq"]
30-
lapack-mkl-static-seq = ["lapack-src/intel-mkl-static-sequential"]
31-
lapack-mkl-static-par = ["lapack-src/intel-mkl-static-parallel"]
32-
lapack-mkl-dynamic-seq = ["lapack-src/intel-mkl-dynamic-sequential"]
33-
lapack-mkl-dynamic-par = ["lapack-src/intel-mkl-dynamic-parallel"]
30+
lapack-mkl-static-seq = ["lapack-src/intel-mkl-static-sequential", "blas-src/intel-mkl-static-sequential"]
31+
lapack-mkl-static-par = ["lapack-src/intel-mkl-static-parallel", "blas-src/intel-mkl-static-parallel"]
32+
lapack-mkl-dynamic-seq = ["lapack-src/intel-mkl-dynamic-sequential", "blas-src/intel-mkl-dynamic-sequential"]
33+
lapack-mkl-dynamic-par = ["lapack-src/intel-mkl-dynamic-parallel", "blas-src/intel-mkl-dynamic-parallel"]
3434
lapack-custom = []
3535

3636
[dependencies]
@@ -40,9 +40,10 @@ num-complex = { version = "0.4", default-features = false }
4040
simba = "0.9"
4141
serde = { version = "1.0", features = ["derive"], optional = true }
4242
lapack = { version = "0.20", default-features = false }
43-
lapack-src = { version = "0.13", optional = true}
43+
blas = { version = "0.23", default-features = false }
44+
lapack-src = { version = "0.13", optional = true }
45+
blas-src = { version = "0.14", optional = true, default-features = false}
4446
thiserror = "1.0"
45-
# clippy = "*"
4647

4748
[dev-dependencies]
4849
nalgebra = { version = "0.34", features = ["arbitrary", "rand"], path = ".." }

nalgebra-lapack/README.md

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# nalgebra-lapack [![Version][version-img]][version-url] [![Status][status-img]][status-url] [![Doc][doc-img]][doc-url]
1+
# nalgebra-lapack [![Version][version-img]][version-url] [![Doc][doc-img]][doc-url]
22

33
Rust library for linear algebra using nalgebra and LAPACK.
44

@@ -10,45 +10,43 @@ Documentation is available [here](https://docs.rs/nalgebra-lapack/).
1010

1111
MIT
1212

13-
## Cargo features to select lapack provider
13+
## Cargo features to select LAPACK provider
1414

1515
Like the [lapack crate](https://crates.io/crates/lapack) from which this
1616
behavior is inherited, nalgebra-lapack uses [cargo
1717
features](https://doc.crates.io/manifest.html#the-[features]-section) to select
18-
which lapack provider (or implementation) is used. Command line arguments to
18+
which LAPACK provider (or implementation) is used. Command line arguments to
1919
cargo are the easiest way to do this, and the best provider depends on your
2020
particular system. In some cases, the providers can be further tuned with
2121
environment variables.
2222

2323
Below are given examples of how to invoke `cargo build` on two different systems
24-
using two different providers. The `--no-default-features --features "provider"`
24+
using two different providers. The `--no-default-features --features "lapack-*"`
2525
arguments will be consistent for other `cargo` commands.
2626

2727
### Ubuntu
2828

29-
As tested on Ubuntu 12.04, do this to build the lapack package against
29+
As tested on Ubuntu 24.04, do this to build the LAPACK package against
3030
the system installation of netlib without LAPACKE (note the E) or
3131
CBLAS:
3232

33-
sudo apt-get install gfortran libblas3gf liblapack3gf
33+
sudo apt-get install gfortran libblas-dev liblapack-dev
3434
export CARGO_FEATURE_SYSTEM_NETLIB=1
3535
export CARGO_FEATURE_EXCLUDE_LAPACKE=1
3636
export CARGO_FEATURE_EXCLUDE_CBLAS=1
3737

38-
export CARGO_FEATURES="--no-default-features --features netlib"
38+
export CARGO_FEATURES="--no-default-features --features lapack-netlib"
3939
cargo build ${CARGO_FEATURES}
4040

4141
### macOS
4242

4343
On macOS, do this to use Apple's Accelerate framework:
4444

45-
export CARGO_FEATURES="--no-default-features --features accelerate"
45+
export CARGO_FEATURES="--no-default-features --features lapack-accelerate"
4646
cargo build ${CARGO_FEATURES}
4747

4848
[version-img]: https://img.shields.io/crates/v/nalgebra-lapack.svg
4949
[version-url]: https://crates.io/crates/nalgebra-lapack
50-
[status-img]: https://travis-ci.org/strawlab/nalgebra-lapack.svg?branch=master
51-
[status-url]: https://travis-ci.org/strawlab/nalgebra-lapack
5250
[doc-img]: https://docs.rs/nalgebra-lapack/badge.svg
5351
[doc-url]: https://docs.rs/nalgebra-lapack/
5452

nalgebra-lapack/src/cholesky.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use na::{DefaultAllocator, Matrix, OMatrix, Scalar};
1111

1212
use lapack;
1313

14-
/// The cholesky decomposition of a symmetric-definite-positive matrix.
14+
/// The Cholesky decomposition of a symmetric positive-definite matrix.
1515
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
1616
#[cfg_attr(
1717
feature = "serde-serialize",
@@ -42,7 +42,7 @@ impl<T: CholeskyScalar + Zero, D: Dim> Cholesky<T, D>
4242
where
4343
DefaultAllocator: Allocator<D, D>,
4444
{
45-
/// Computes the cholesky decomposition of the given symmetric-definite-positive square
45+
/// Computes the Cholesky decomposition of the given symmetric positive-definite square
4646
/// matrix.
4747
///
4848
/// Only the lower-triangular part of the input matrix is considered.
@@ -51,7 +51,7 @@ where
5151
// TODO: check symmetry as well?
5252
assert!(
5353
m.is_square(),
54-
"Unable to compute the cholesky decomposition of a non-square matrix."
54+
"Unable to compute the Cholesky decomposition of a non-square matrix."
5555
);
5656

5757
let uplo = b'L';
@@ -64,13 +64,13 @@ where
6464
Some(Self { l: m })
6565
}
6666

67-
/// Retrieves the lower-triangular factor of the cholesky decomposition.
67+
/// Retrieves the lower-triangular factor of the Cholesky decomposition.
6868
pub fn unpack(mut self) -> OMatrix<T, D, D> {
6969
self.l.fill_upper_triangle(Zero::zero(), 1);
7070
self.l
7171
}
7272

73-
/// Retrieves the lower-triangular factor of che cholesky decomposition, without zeroing-out
73+
/// Retrieves the lower-triangular factor of the Cholesky decomposition, without zeroing-out
7474
/// its strict upper-triangular part.
7575
///
7676
/// This is an allocation-less version of `self.l()`. The values of the strict upper-triangular
@@ -79,15 +79,15 @@ where
7979
self.l
8080
}
8181

82-
/// Retrieves the lower-triangular factor of the cholesky decomposition.
82+
/// Retrieves the lower-triangular factor of the Cholesky decomposition.
8383
#[must_use]
8484
pub fn l(&self) -> OMatrix<T, D, D> {
8585
let mut res = self.l.clone();
8686
res.fill_upper_triangle(Zero::zero(), 1);
8787
res
8888
}
8989

90-
/// Retrieves the lower-triangular factor of the cholesky decomposition, without zeroing-out
90+
/// Retrieves the lower-triangular factor of the Cholesky decomposition, without zeroing-out
9191
/// its strict upper-triangular part.
9292
///
9393
/// This is an allocation-less version of `self.l()`. The values of the strict upper-triangular
@@ -177,7 +177,7 @@ where
177177
*
178178
*/
179179
/// Trait implemented by floats (`f32`, `f64`) and complex floats (`Complex<f32>`, `Complex<f64>`)
180-
/// supported by the cholesky decomposition.
180+
/// supported by the Cholesky decomposition.
181181
pub trait CholeskyScalar: Scalar + Copy {
182182
#[allow(missing_docs)]
183183
fn xpotrf(uplo: u8, n: i32, a: &mut [Self], lda: i32, info: &mut i32);

0 commit comments

Comments
 (0)