Skip to content

Commit

Permalink
Add nalgebra 0.33 support
Browse files Browse the repository at this point in the history
  • Loading branch information
0e4ef622 authored and stefan-k committed Oct 27, 2024
1 parent be2444e commit 3ce9adc
Show file tree
Hide file tree
Showing 18 changed files with 86 additions and 49 deletions.
4 changes: 3 additions & 1 deletion crates/argmin-math/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ exclude = []

[dependencies]
# nalgebra
nalgebra_0_33 = { package = "nalgebra", version = "0.33", optional = true }
nalgebra_0_32 = { package = "nalgebra", version = "0.32", optional = true }
nalgebra_0_31 = { package = "nalgebra", version = "0.31", optional = true }
nalgebra_0_30 = { package = "nalgebra", version = "0.30", optional = true }
Expand Down Expand Up @@ -57,7 +58,8 @@ vec = ["primitives", "num-complex_0_4"]

# nalgebra
nalgebra_all = ["primitives"]
nalgebra_latest = ["nalgebra_v0_32"]
nalgebra_latest = ["nalgebra_v0_33"]
nalgebra_v0_33 = ["nalgebra_0_33", "num-complex_0_4", "nalgebra_all"]
nalgebra_v0_32 = ["nalgebra_0_32", "num-complex_0_4", "nalgebra_all"]
nalgebra_v0_31 = ["nalgebra_0_31", "num-complex_0_4", "nalgebra_all"]
nalgebra_v0_30 = ["nalgebra_0_30", "num-complex_0_4", "nalgebra_all"]
Expand Down
47 changes: 46 additions & 1 deletion crates/argmin-math/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
//! | Feature | Default | Comment |
//! |------------------------|---------|------------------------------------------|
//! | `nalgebra_latest` | no | latest supported version |
//! | `nalgebra_v0_33` | no | version 0.33 |
//! | `nalgebra_v0_32` | no | version 0.32 |
//! | `nalgebra_v0_31` | no | version 0.31 |
//! | `nalgebra_v0_30` | no | version 0.30 |
Expand Down Expand Up @@ -131,14 +132,58 @@
#![deny(clippy::float_cmp)]

cfg_if::cfg_if! {
if #[cfg(feature = "nalgebra_0_32")] {
if #[cfg(feature = "nalgebra_0_33")] {
extern crate nalgebra_0_33 as nalgebra;
trait Allocator<T, R, C = nalgebra::U1>: nalgebra::allocator::Allocator<R, C>
where
R: nalgebra::Dim,
C: nalgebra::Dim,
{}
impl<T, R, C, U> Allocator<T, R, C> for U
where
U: nalgebra::allocator::Allocator<R, C>,
R: nalgebra::Dim,
C: nalgebra::Dim,
{}
trait SameShapeAllocator<T, R1, C1, R2, C2>: nalgebra::allocator::SameShapeAllocator<R1, C1, R2, C2>
where
R1: nalgebra::Dim,
C1: nalgebra::Dim,
R2: nalgebra::Dim,
C2: nalgebra::Dim,
nalgebra::constraint::ShapeConstraint: nalgebra::constraint::SameNumberOfRows<R1,R2> + nalgebra::constraint::SameNumberOfColumns<C1,C2>,
{}
impl<T, R1, C1, R2, C2, U> SameShapeAllocator<T, R1, C1, R2, C2> for U
where
U: nalgebra::allocator::SameShapeAllocator<R1, C1, R2, C2>,
R1: nalgebra::Dim,
C1: nalgebra::Dim,
R2: nalgebra::Dim,
C2: nalgebra::Dim,
nalgebra::constraint::ShapeConstraint: nalgebra::constraint::SameNumberOfRows<R1,R2> + nalgebra::constraint::SameNumberOfColumns<C1,C2>,
{}
use nalgebra::{
ClosedAddAssign as ClosedAdd,
ClosedSubAssign as ClosedSub,
ClosedDivAssign as ClosedDiv,
ClosedMulAssign as ClosedMul,
};
} else if #[cfg(feature = "nalgebra_0_32")] {
extern crate nalgebra_0_32 as nalgebra;
use nalgebra::allocator::{Allocator, SameShapeAllocator};
use nalgebra::{ClosedAdd, ClosedSub, ClosedDiv, ClosedMul};
} else if #[cfg(feature = "nalgebra_0_31")] {
extern crate nalgebra_0_31 as nalgebra;
use nalgebra::allocator::{Allocator, SameShapeAllocator};
use nalgebra::{ClosedAdd, ClosedSub, ClosedDiv, ClosedMul};
} else if #[cfg(feature = "nalgebra_0_30")] {
extern crate nalgebra_0_30 as nalgebra;
use nalgebra::allocator::{Allocator, SameShapeAllocator};
use nalgebra::{ClosedAdd, ClosedSub, ClosedDiv, ClosedMul};
} else if #[cfg(feature = "nalgebra_0_29")] {
extern crate nalgebra_0_29 as nalgebra;
use nalgebra::allocator::{Allocator, SameShapeAllocator};
use nalgebra::{ClosedAdd, ClosedSub, ClosedDiv, ClosedMul};
}
}

Expand Down
6 changes: 3 additions & 3 deletions crates/argmin-math/src/nalgebra_m/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@
// http://opensource.org/licenses/MIT>, at your option. This file may not be
// copied, modified, or distributed except according to those terms.

use crate::ArgminAdd;
use crate::{Allocator, ArgminAdd, SameShapeAllocator};

use crate::ClosedAdd;
use nalgebra::{
base::{
allocator::{Allocator, SameShapeAllocator},
constraint::{SameNumberOfColumns, SameNumberOfRows, ShapeConstraint},
dimension::Dim,
storage::Storage,
Scalar,
},
ClosedAdd, DefaultAllocator, Matrix, MatrixSum, OMatrix,
DefaultAllocator, Matrix, MatrixSum, OMatrix,
};

impl<N, R, C, S> ArgminAdd<N, OMatrix<N, R, C>> for Matrix<N, R, C, S>
Expand Down
7 changes: 2 additions & 5 deletions crates/argmin-math/src/nalgebra_m/conj.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,9 @@
// http://opensource.org/licenses/MIT>, at your option. This file may not be
// copied, modified, or distributed except according to those terms.

use crate::ArgminConj;
use crate::{Allocator, ArgminConj};

use nalgebra::{
base::{allocator::Allocator, dimension::Dim},
DefaultAllocator, OMatrix, SimdComplexField,
};
use nalgebra::{base::dimension::Dim, DefaultAllocator, OMatrix, SimdComplexField};

impl<N, R, C> ArgminConj for OMatrix<N, R, C>
where
Expand Down
6 changes: 3 additions & 3 deletions crates/argmin-math/src/nalgebra_m/div.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@
// http://opensource.org/licenses/MIT>, at your option. This file may not be
// copied, modified, or distributed except according to those terms.

use crate::ArgminDiv;
use crate::{Allocator, ArgminDiv, SameShapeAllocator};

use crate::ClosedDiv;
use nalgebra::{
base::{
allocator::{Allocator, SameShapeAllocator},
constraint::{SameNumberOfColumns, SameNumberOfRows, ShapeConstraint},
dimension::Dim,
storage::Storage,
MatrixSum, Scalar,
},
ClosedDiv, DefaultAllocator, Matrix, OMatrix,
DefaultAllocator, Matrix, OMatrix,
};

impl<N, R, C, S> ArgminDiv<N, OMatrix<N, R, C>> for Matrix<N, R, C, S>
Expand Down
6 changes: 3 additions & 3 deletions crates/argmin-math/src/nalgebra_m/dot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@
// http://opensource.org/licenses/MIT>, at your option. This file may not be
// copied, modified, or distributed except according to those terms.

use crate::ArgminDot;
use crate::{Allocator, ArgminDot};

use num_traits::{One, Zero};

use crate::{ClosedAdd, ClosedMul};
use nalgebra::{
base::{
allocator::Allocator,
constraint::{AreMultipliable, DimEq, ShapeConstraint},
dimension::Dim,
storage::Storage,
Scalar,
},
ClosedAdd, ClosedMul, DefaultAllocator, Matrix, OMatrix,
DefaultAllocator, Matrix, OMatrix,
};

impl<N, R1, R2, C1, C2, SA, SB> ArgminDot<Matrix<N, R2, C2, SB>, N> for Matrix<N, R1, C1, SA>
Expand Down
7 changes: 2 additions & 5 deletions crates/argmin-math/src/nalgebra_m/eye.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,11 @@
// http://opensource.org/licenses/MIT>, at your option. This file may not be
// copied, modified, or distributed except according to those terms.

use crate::ArgminEye;
use crate::{Allocator, ArgminEye};

use num_traits::{One, Zero};

use nalgebra::{
base::{allocator::Allocator, dimension::Dim},
DefaultAllocator, OMatrix, Scalar,
};
use nalgebra::{base::dimension::Dim, DefaultAllocator, OMatrix, Scalar};

impl<N, R, C> ArgminEye for OMatrix<N, R, C>
where
Expand Down
4 changes: 2 additions & 2 deletions crates/argmin-math/src/nalgebra_m/inv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
// http://opensource.org/licenses/MIT>, at your option. This file may not be
// copied, modified, or distributed except according to those terms.

use crate::{ArgminInv, Error};
use crate::{Allocator, ArgminInv, Error};
use nalgebra::{
base::{allocator::Allocator, dimension::Dim, storage::Storage},
base::{dimension::Dim, storage::Storage},
ComplexField, DefaultAllocator, OMatrix, SquareMatrix,
};
use std::fmt;
Expand Down
7 changes: 4 additions & 3 deletions crates/argmin-math/src/nalgebra_m/minmax.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
// http://opensource.org/licenses/MIT>, at your option. This file may not be
// copied, modified, or distributed except according to those terms.

use crate::ArgminMinMax;
use crate::{Allocator, ArgminMinMax};

use crate::ClosedMul;
use nalgebra::{
base::{allocator::Allocator, dimension::Dim, Scalar},
ClosedMul, DefaultAllocator, OMatrix,
base::{dimension::Dim, Scalar},
DefaultAllocator, OMatrix,
};

impl<N, R, C> ArgminMinMax for OMatrix<N, R, C>
Expand Down
6 changes: 3 additions & 3 deletions crates/argmin-math/src/nalgebra_m/mul.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@
// http://opensource.org/licenses/MIT>, at your option. This file may not be
// copied, modified, or distributed except according to those terms.

use crate::ArgminMul;
use crate::{Allocator, ArgminMul, SameShapeAllocator};

use crate::ClosedMul;
use nalgebra::{
base::{
allocator::{Allocator, SameShapeAllocator},
constraint::{SameNumberOfColumns, SameNumberOfRows, ShapeConstraint},
dimension::Dim,
storage::Storage,
MatrixSum, Scalar,
},
ClosedMul, DefaultAllocator, Matrix, OMatrix,
DefaultAllocator, Matrix, OMatrix,
};

impl<N, R, C, S> ArgminMul<N, OMatrix<N, R, C>> for Matrix<N, R, C, S>
Expand Down
4 changes: 2 additions & 2 deletions crates/argmin-math/src/nalgebra_m/random.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@

use rand::{distributions::uniform::SampleUniform, Rng};

use crate::ArgminRandom;
use crate::{Allocator, ArgminRandom};

use nalgebra::{
base::{allocator::Allocator, dimension::Dim, Scalar},
base::{dimension::Dim, Scalar},
DefaultAllocator, OMatrix,
};

Expand Down
7 changes: 2 additions & 5 deletions crates/argmin-math/src/nalgebra_m/signum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,9 @@
// http://opensource.org/licenses/MIT>, at your option. This file may not be
// copied, modified, or distributed except according to those terms.

use crate::ArgminSignum;
use crate::{Allocator, ArgminSignum};

use nalgebra::{
base::{allocator::Allocator, dimension::Dim},
DefaultAllocator, OMatrix, SimdComplexField,
};
use nalgebra::{base::dimension::Dim, DefaultAllocator, OMatrix, SimdComplexField};

impl<N, R, C> ArgminSignum for OMatrix<N, R, C>
where
Expand Down
7 changes: 4 additions & 3 deletions crates/argmin-math/src/nalgebra_m/sub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@

use std::ops::Sub;

use crate::ArgminSub;
use crate::{Allocator, ArgminSub};

use crate::ClosedSub;
use nalgebra::{
base::{allocator::Allocator, dimension::Dim, storage::Storage, Scalar},
ClosedSub, DefaultAllocator, Matrix, OMatrix,
base::{dimension::Dim, storage::Storage, Scalar},
DefaultAllocator, Matrix, OMatrix,
};

impl<N, R, C, S> ArgminSub<N, OMatrix<N, R, C>> for Matrix<N, R, C, S>
Expand Down
4 changes: 2 additions & 2 deletions crates/argmin-math/src/nalgebra_m/transpose.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
// Note: This is not really the preferred way I think. Maybe this should also be implemented for
// ArrayViews, which would probably make it more efficient.

use crate::ArgminTranspose;
use crate::{Allocator, ArgminTranspose};

use nalgebra::{
base::{allocator::Allocator, dimension::Dim, storage::Storage, Scalar},
base::{dimension::Dim, storage::Storage, Scalar},
DefaultAllocator, Matrix, OMatrix,
};

Expand Down
7 changes: 2 additions & 5 deletions crates/argmin-math/src/nalgebra_m/zero.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,11 @@
// http://opensource.org/licenses/MIT>, at your option. This file may not be
// copied, modified, or distributed except according to those terms.

use crate::{ArgminZero, ArgminZeroLike};
use crate::{Allocator, ArgminZero, ArgminZeroLike};

use num_traits::Zero;

use nalgebra::{
base::{allocator::Allocator, dimension::Dim},
DefaultAllocator, OMatrix, Scalar,
};
use nalgebra::{base::dimension::Dim, DefaultAllocator, OMatrix, Scalar};

impl<N, R, C> ArgminZeroLike for OMatrix<N, R, C>
where
Expand Down
2 changes: 1 addition & 1 deletion examples/gaussnewton_nalgebra/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ publish = false
argmin = { version = "*", path = "../../crates/argmin" }
argmin-math = { version = "*", features = ["nalgebra_latest"], path = "../../crates/argmin-math" }
argmin-observer-slog = { version = "*", path = "../../crates/argmin-observer-slog" }
nalgebra = "0.32.3"
nalgebra = "0.33.0"
2 changes: 1 addition & 1 deletion examples/lbfgs_nalgebra/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ argmin = { version = "*", path = "../../crates/argmin" }
argmin-math = { version = "*", features = ["nalgebra_latest"], path = "../../crates/argmin-math" }
argmin-observer-slog = { version = "*", path = "../../crates/argmin-observer-slog" }
argmin_testfunctions = { version = "*", path = "../../crates/argmin-testfunctions" }
nalgebra = "0.32.3"
nalgebra = "0.33.0"
2 changes: 1 addition & 1 deletion examples/particleswarm_nalgebra/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ argmin = { version = "*", path = "../../crates/argmin" }
argmin-math = { version = "*", features = ["nalgebra_latest"], path = "../../crates/argmin-math" }
argmin-observer-slog = { version = "*", path = "../../crates/argmin-observer-slog" }
argmin_testfunctions = { version = "*", path = "../../crates/argmin-testfunctions" }
nalgebra = { version = "0.32.3", features = ["serde-serialize"] }
nalgebra = { version = "0.33.0", features = ["serde-serialize"] }

0 comments on commit 3ce9adc

Please sign in to comment.