Skip to content

Commit

Permalink
feat: use GAT to remove the scalar type T from the Allocator trait (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
sebcrozet authored Jun 12, 2024
1 parent 28e993a commit c23807a
Show file tree
Hide file tree
Showing 92 changed files with 943 additions and 1,032 deletions.
2 changes: 1 addition & 1 deletion examples/dimensional_genericity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ fn reflect_wrt_hyperplane_with_dimensional_genericity<T: RealField, D: Dim>(
where
T: RealField,
D: Dim,
DefaultAllocator: Allocator<T, D>,
DefaultAllocator: Allocator<D>,
{
let n = plane_normal.as_ref(); // Get the underlying V.
vector - n * (n.dot(vector) * na::convert(2.0))
Expand Down
46 changes: 23 additions & 23 deletions nalgebra-lapack/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,47 +1,47 @@
[package]
name = "nalgebra-lapack"
name = "nalgebra-lapack"
version = "0.24.0"
authors = [ "Sébastien Crozet <[email protected]>", "Andrew Straw <[email protected]>" ]
authors = ["Sébastien Crozet <[email protected]>", "Andrew Straw <[email protected]>"]

description = "Matrix decompositions using nalgebra matrices and Lapack bindings."
description = "Matrix decompositions using nalgebra matrices and Lapack bindings."
documentation = "https://www.nalgebra.org/docs"
homepage = "https://nalgebra.org"
repository = "https://github.com/dimforge/nalgebra"
readme = "../README.md"
categories = [ "science", "mathematics" ]
keywords = [ "linear", "algebra", "matrix", "vector", "lapack" ]
categories = ["science", "mathematics"]
keywords = ["linear", "algebra", "matrix", "vector", "lapack"]
license = "MIT"
edition = "2018"

[badges]
maintenance = { status = "actively-developed" }

[features]
serde-serialize = [ "serde", "nalgebra/serde-serialize" ]
proptest-support = [ "nalgebra/proptest-support" ]
arbitrary = [ "nalgebra/arbitrary" ]
serde-serialize = ["serde", "nalgebra/serde-serialize"]
proptest-support = ["nalgebra/proptest-support"]
arbitrary = ["nalgebra/arbitrary"]

# For BLAS/LAPACK
default = ["netlib"]
openblas = ["lapack-src/openblas"]
netlib = ["lapack-src/netlib"]
default = ["netlib"]
openblas = ["lapack-src/openblas"]
netlib = ["lapack-src/netlib"]
accelerate = ["lapack-src/accelerate"]
intel-mkl = ["lapack-src/intel-mkl"]
intel-mkl = ["lapack-src/intel-mkl"]

[dependencies]
nalgebra = { version = "0.32", path = ".." }
num-traits = "0.2"
num-complex = { version = "0.4", default-features = false }
simba = "0.8"
serde = { version = "1.0", features = [ "derive" ], optional = true }
lapack = { version = "0.19", default-features = false }
lapack-src = { version = "0.8", default-features = false }
nalgebra = { version = "0.32", path = ".." }
num-traits = "0.2"
num-complex = { version = "0.4", default-features = false }
simba = "0.8"
serde = { version = "1.0", features = ["derive"], optional = true }
lapack = { version = "0.19", default-features = false }
lapack-src = { version = "0.8", default-features = false }
# clippy = "*"

[dev-dependencies]
nalgebra = { version = "0.32", features = [ "arbitrary", "rand" ], path = ".." }
proptest = { version = "1", default-features = false, features = ["std"] }
nalgebra = { version = "0.32", features = ["arbitrary", "rand"], path = ".." }
proptest = { version = "1", default-features = false, features = ["std"] }
quickcheck = "1"
approx = "0.5"
rand = "0.8"
approx = "0.5"
rand = "0.8"

14 changes: 7 additions & 7 deletions nalgebra-lapack/src/cholesky.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,32 +15,32 @@ use lapack;
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
#[cfg_attr(
feature = "serde-serialize",
serde(bound(serialize = "DefaultAllocator: Allocator<T, D>,
serde(bound(serialize = "DefaultAllocator: Allocator<D>,
OMatrix<T, D, D>: Serialize"))
)]
#[cfg_attr(
feature = "serde-serialize",
serde(bound(deserialize = "DefaultAllocator: Allocator<T, D>,
serde(bound(deserialize = "DefaultAllocator: Allocator<D>,
OMatrix<T, D, D>: Deserialize<'de>"))
)]
#[derive(Clone, Debug)]
pub struct Cholesky<T: Scalar, D: Dim>
where
DefaultAllocator: Allocator<T, D, D>,
DefaultAllocator: Allocator<D, D>,
{
l: OMatrix<T, D, D>,
}

impl<T: Scalar + Copy, D: Dim> Copy for Cholesky<T, D>
where
DefaultAllocator: Allocator<T, D, D>,
DefaultAllocator: Allocator<D, D>,
OMatrix<T, D, D>: Copy,
{
}

impl<T: CholeskyScalar + Zero, D: Dim> Cholesky<T, D>
where
DefaultAllocator: Allocator<T, D, D>,
DefaultAllocator: Allocator<D, D>,
{
/// Computes the cholesky decomposition of the given symmetric-definite-positive square
/// matrix.
Expand Down Expand Up @@ -105,7 +105,7 @@ where
) -> Option<OMatrix<T, R2, C2>>
where
S2: Storage<T, R2, C2>,
DefaultAllocator: Allocator<T, R2, C2>,
DefaultAllocator: Allocator<R2, C2>,
{
let mut res = b.clone_owned();
if self.solve_mut(&mut res) {
Expand All @@ -119,7 +119,7 @@ where
/// the unknown to be determined.
pub fn solve_mut<R2: Dim, C2: Dim>(&self, b: &mut OMatrix<T, R2, C2>) -> bool
where
DefaultAllocator: Allocator<T, R2, C2>,
DefaultAllocator: Allocator<R2, C2>,
{
let dim = self.l.nrows();

Expand Down
22 changes: 9 additions & 13 deletions nalgebra-lapack/src/eigen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,20 @@ use lapack;
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
#[cfg_attr(
feature = "serde-serialize",
serde(
bound(serialize = "DefaultAllocator: Allocator<T, D, D> + Allocator<T, D>,
serde(bound(serialize = "DefaultAllocator: Allocator<D, D> + Allocator<D>,
OVector<T, D>: Serialize,
OMatrix<T, D, D>: Serialize")
)
OMatrix<T, D, D>: Serialize"))
)]
#[cfg_attr(
feature = "serde-serialize",
serde(
bound(deserialize = "DefaultAllocator: Allocator<T, D, D> + Allocator<T, D>,
serde(bound(deserialize = "DefaultAllocator: Allocator<D, D> + Allocator<D>,
OVector<T, D>: Serialize,
OMatrix<T, D, D>: Deserialize<'de>")
)
OMatrix<T, D, D>: Deserialize<'de>"))
)]
#[derive(Clone, Debug)]
pub struct Eigen<T: Scalar, D: Dim>
where
DefaultAllocator: Allocator<T, D> + Allocator<T, D, D>,
DefaultAllocator: Allocator<D> + Allocator<D, D>,
{
/// The real parts of eigenvalues of the decomposed matrix.
pub eigenvalues_re: OVector<T, D>,
Expand All @@ -47,15 +43,15 @@ where

impl<T: Scalar + Copy, D: Dim> Copy for Eigen<T, D>
where
DefaultAllocator: Allocator<T, D> + Allocator<T, D, D>,
DefaultAllocator: Allocator<D> + Allocator<D, D>,
OVector<T, D>: Copy,
OMatrix<T, D, D>: Copy,
{
}

impl<T: EigenScalar + RealField, D: Dim> Eigen<T, D>
where
DefaultAllocator: Allocator<T, D, D> + Allocator<T, D>,
DefaultAllocator: Allocator<D, D> + Allocator<D>,
{
/// Computes the eigenvalues and eigenvectors of the square matrix `m`.
///
Expand Down Expand Up @@ -177,7 +173,7 @@ where
Option<Vec<OVector<T, D>>>,
)
where
DefaultAllocator: Allocator<T, D>,
DefaultAllocator: Allocator<D>,
{
let (number_of_elements, _) = self.eigenvalues_re.shape_generic();
let number_of_elements_value = number_of_elements.value();
Expand Down Expand Up @@ -234,7 +230,7 @@ where
Option<Vec<OVector<Complex<T>, D>>>,
)
where
DefaultAllocator: Allocator<Complex<T>, D>,
DefaultAllocator: Allocator<D>,
{
match self.eigenvalues_are_real() {
true => (None, None, None),
Expand Down
23 changes: 9 additions & 14 deletions nalgebra-lapack/src/generalized_eigenvalues.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,20 @@ use lapack;
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
#[cfg_attr(
feature = "serde-serialize",
serde(
bound(serialize = "DefaultAllocator: Allocator<T, D, D> + Allocator<T, D>,
serde(bound(serialize = "DefaultAllocator: Allocator<D, D> + Allocator<D>,
OVector<T, D>: Serialize,
OMatrix<T, D, D>: Serialize")
)
OMatrix<T, D, D>: Serialize"))
)]
#[cfg_attr(
feature = "serde-serialize",
serde(
bound(deserialize = "DefaultAllocator: Allocator<T, D, D> + Allocator<T, D>,
serde(bound(deserialize = "DefaultAllocator: Allocator<D, D> + Allocator<D>,
OVector<T, D>: Deserialize<'de>,
OMatrix<T, D, D>: Deserialize<'de>")
)
OMatrix<T, D, D>: Deserialize<'de>"))
)]
#[derive(Clone, Debug)]
pub struct GeneralizedEigen<T: Scalar, D: Dim>
where
DefaultAllocator: Allocator<T, D> + Allocator<T, D, D>,
DefaultAllocator: Allocator<D> + Allocator<D, D>,
{
alphar: OVector<T, D>,
alphai: OVector<T, D>,
Expand All @@ -58,15 +54,15 @@ where

impl<T: Scalar + Copy, D: Dim> Copy for GeneralizedEigen<T, D>
where
DefaultAllocator: Allocator<T, D, D> + Allocator<T, D>,
DefaultAllocator: Allocator<D, D> + Allocator<D>,
OMatrix<T, D, D>: Copy,
OVector<T, D>: Copy,
{
}

impl<T: GeneralizedEigenScalar + RealField + Copy, D: Dim> GeneralizedEigen<T, D>
where
DefaultAllocator: Allocator<T, D, D> + Allocator<T, D>,
DefaultAllocator: Allocator<D, D> + Allocator<D>,
{
/// Attempts to compute the generalized eigenvalues, and left and right associated eigenvectors
/// via the raw returns from LAPACK's dggev and sggev routines
Expand Down Expand Up @@ -162,8 +158,7 @@ where
/// as columns.
pub fn eigenvectors(&self) -> (OMatrix<Complex<T>, D, D>, OMatrix<Complex<T>, D, D>)
where
DefaultAllocator:
Allocator<Complex<T>, D, D> + Allocator<Complex<T>, D> + Allocator<(Complex<T>, T), D>,
DefaultAllocator: Allocator<D, D> + Allocator<D>,
{
/*
How the eigenvectors are built up:
Expand Down Expand Up @@ -230,7 +225,7 @@ where
#[must_use]
pub fn raw_eigenvalues(&self) -> OVector<(Complex<T>, T), D>
where
DefaultAllocator: Allocator<(Complex<T>, T), D>,
DefaultAllocator: Allocator<D>,
{
let mut out = Matrix::from_element_generic(
self.vsl.shape_generic().0,
Expand Down
16 changes: 8 additions & 8 deletions nalgebra-lapack/src/hessenberg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,38 +12,38 @@ use lapack;
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
#[cfg_attr(
feature = "serde-serialize",
serde(bound(serialize = "DefaultAllocator: Allocator<T, D, D> +
Allocator<T, DimDiff<D, U1>>,
serde(bound(serialize = "DefaultAllocator: Allocator<D, D> +
Allocator<DimDiff<D, U1>>,
OMatrix<T, D, D>: Serialize,
OVector<T, DimDiff<D, U1>>: Serialize"))
)]
#[cfg_attr(
feature = "serde-serialize",
serde(bound(deserialize = "DefaultAllocator: Allocator<T, D, D> +
Allocator<T, DimDiff<D, U1>>,
serde(bound(deserialize = "DefaultAllocator: Allocator<D, D> +
Allocator<DimDiff<D, U1>>,
OMatrix<T, D, D>: Deserialize<'de>,
OVector<T, DimDiff<D, U1>>: Deserialize<'de>"))
)]
#[derive(Clone, Debug)]
pub struct Hessenberg<T: Scalar, D: DimSub<U1>>
where
DefaultAllocator: Allocator<T, D, D> + Allocator<T, DimDiff<D, U1>>,
DefaultAllocator: Allocator<D, D> + Allocator<DimDiff<D, U1>>,
{
h: OMatrix<T, D, D>,
tau: OVector<T, DimDiff<D, U1>>,
}

impl<T: Scalar + Copy, D: DimSub<U1>> Copy for Hessenberg<T, D>
where
DefaultAllocator: Allocator<T, D, D> + Allocator<T, DimDiff<D, U1>>,
DefaultAllocator: Allocator<D, D> + Allocator<DimDiff<D, U1>>,
OMatrix<T, D, D>: Copy,
OVector<T, DimDiff<D, U1>>: Copy,
{
}

impl<T: HessenbergScalar + Zero, D: DimSub<U1>> Hessenberg<T, D>
where
DefaultAllocator: Allocator<T, D, D> + Allocator<T, DimDiff<D, U1>>,
DefaultAllocator: Allocator<D, D> + Allocator<DimDiff<D, U1>>,
{
/// Computes the hessenberg decomposition of the matrix `m`.
pub fn new(mut m: OMatrix<T, D, D>) -> Self {
Expand Down Expand Up @@ -97,7 +97,7 @@ where

impl<T: HessenbergReal + Zero, D: DimSub<U1>> Hessenberg<T, D>
where
DefaultAllocator: Allocator<T, D, D> + Allocator<T, DimDiff<D, U1>>,
DefaultAllocator: Allocator<D, D> + Allocator<DimDiff<D, U1>>,
{
/// Computes the matrices `(Q, H)` of this decomposition.
#[inline]
Expand Down
Loading

0 comments on commit c23807a

Please sign in to comment.