Skip to content

Commit

Permalink
Upgrade to nalegbra 0.33, remove derive_more dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
contagon committed Nov 5, 2024
1 parent 9bd7d10 commit 05cec8c
Show file tree
Hide file tree
Showing 8 changed files with 804 additions and 561 deletions.
1,206 changes: 743 additions & 463 deletions Cargo.lock

Large diffs are not rendered by default.

25 changes: 12 additions & 13 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,29 +16,28 @@ rustdoc-args = ["--html-in-header", "assets/katex-header.html"]
[dependencies]
# base
ahash = "0.8.11"
derive_more = "0.99.17"
paste = "1.0.15"
downcast-rs = "1.2.1"
log = "0.4.21"
log = "0.4.22"

# numerical
faer = { version = "0.19.0", default-features = false, features = [
faer = { version = "0.19.4", default-features = false, features = [
"perf-warn",
"std",
"matrixcompare",
] }
faer-ext = { version = "0.2.0", features = ["nalgebra"] }
nalgebra = { version = "0.32.5", features = ["compare"] }
num-dual = "0.9.1"
matrixcompare = { version = "0.1" }
faer-ext = { version = "0.3.0", features = ["nalgebra"] }
nalgebra = { version = "0.33.2", features = ["compare"] }
num-dual = "0.10.0"
matrixcompare = { version = "0.3" }

# serialization
serde = { version = "1.0.203", optional = true }
typetag = { version = "0.2.16", optional = true }
serde_json = { version = "1.0.120", optional = true }
serde = { version = "1.0.214", optional = true }
typetag = { version = "0.2.18", optional = true }
serde_json = { version = "1.0.132", optional = true }

# rerun support
rerun = { version = "0.18", optional = true, default-features = false, features = [
rerun = { version = "0.19", optional = true, default-features = false, features = [
"sdk",
] }

Expand Down Expand Up @@ -71,8 +70,8 @@ rerun = ["dep:rerun"]

[dev-dependencies]
matrixcompare = "0.3.0"
pretty_env_logger = "0.4"
nalgebra = { version = "0.32.5", features = ["compare"] }
pretty_env_logger = "0.5"
nalgebra = { version = "0.33.2", features = ["compare"] }

[[example]]
name = "g2o"
Expand Down
10 changes: 2 additions & 8 deletions src/linalg/dual.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,13 @@ pub type DualScalar = num_dual::Dual<dtype, dtype>;

/// Make allocator binds easier for dual numbers
pub trait DualAllocator<N: Dim>:
Allocator<dtype, N>
+ Allocator<dtype, Const<1>, N>
+ Allocator<dtype, N, Const<1>>
+ Allocator<dtype, N, N>
Allocator<N> + Allocator<Const<1>, N> + Allocator<N, Const<1>> + Allocator<N, N>
{
}

impl<
N: Dim,
T: Allocator<dtype, N>
+ Allocator<dtype, Const<1>, N>
+ Allocator<dtype, N, Const<1>>
+ Allocator<dtype, N, N>,
T: Allocator<N> + Allocator<Const<1>, N> + Allocator<N, Const<1>> + Allocator<N, N>,
> DualAllocator<N> for T
{
}
Expand Down
18 changes: 5 additions & 13 deletions src/linalg/nalgebra_wrap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,14 @@
// Misc imports
use nalgebra::{self as na, OVector};
pub use nalgebra::{
allocator::Allocator,
dmatrix as matrixx,
dvector as vectorx,
ComplexField,
Const,
DefaultAllocator,
Dim,
DimName,
Dyn,
RealField,
allocator::Allocator, dmatrix as matrixx, dvector as vectorx, ComplexField, Const,
DefaultAllocator, Dim, DimName, Dyn, RealField,
};

use crate::dtype;

// Make it easier to bind the buffer type
pub type AllocatorBuffer<N> = <DefaultAllocator as Allocator<dtype, N>>::Buffer;
pub type AllocatorBuffer<N> = <DefaultAllocator as Allocator<N>>::Buffer<dtype>;

// ------------------------- Vector/Matrix Aliases ------------------------- //
// Vectors
Expand Down Expand Up @@ -99,7 +91,7 @@ pub type Matrix<const R: usize, const C: usize = 1, D = dtype> = na::Matrix<
D,
Const<R>,
Const<C>,
<na::DefaultAllocator as Allocator<D, Const<R>, Const<C>>>::Buffer,
<na::DefaultAllocator as Allocator<Const<R>, Const<C>>>::Buffer<D>,
>;
pub type MatrixView<'a, const R: usize, const C: usize = 1, D = dtype> =
na::MatrixView<'a, D, Const<R>, Const<C>>;
Expand All @@ -116,5 +108,5 @@ pub type VectorView6<'a, D = dtype> = na::VectorView<'a, D, Const<6>>;
// Generic, taking in sizes with Const
pub type VectorDim<N, D = dtype> = OVector<D, N>;
pub type MatrixDim<R, C = Const<1>, D = dtype> =
na::Matrix<D, R, C, <na::DefaultAllocator as Allocator<D, R, C>>::Buffer>;
na::Matrix<D, R, C, <na::DefaultAllocator as Allocator<R, C>>::Buffer<D>>;
pub type MatrixViewDim<'a, R, C = Const<1>, D = dtype> = na::MatrixView<'a, D, R, C>;
10 changes: 9 additions & 1 deletion src/noise/unit.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use core::fmt;

use super::NoiseModel;
use crate::{
linalg::{Const, MatrixX, VectorX},
Expand Down Expand Up @@ -26,7 +28,7 @@ tag_noise!(
///
/// Represents a noise model that does not modify the input, or equal weighting
/// in a [factor](crate::containers::Factor).
#[derive(Clone, Debug, derive_more::Display)]
#[derive(Clone, Debug)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct UnitNoise<const N: usize>;

Expand All @@ -41,3 +43,9 @@ impl<const N: usize> NoiseModel for UnitNoise<N> {
m
}
}

impl<const N: usize> fmt::Display for UnitNoise<N> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{:?}", self)
}
}
36 changes: 13 additions & 23 deletions src/residuals/between.rs
Original file line number Diff line number Diff line change
@@ -1,35 +1,19 @@
use core::fmt;

use nalgebra::{DimNameAdd, DimNameSum};

use super::{Residual, Residual2};
#[allow(unused_imports)]
use crate::{
containers::{Key, Values},
linalg::{
AllocatorBuffer,
Const,
DefaultAllocator,
DiffResult,
DualAllocator,
DualVector,
ForwardProp,
MatrixX,
Numeric,
VectorX,
AllocatorBuffer, Const, DefaultAllocator, DiffResult, DualAllocator, DualVector,
ForwardProp, MatrixX, Numeric, VectorX,
},
tag_residual,
variables::{
Variable,
VariableUmbrella,
VectorVar1,
VectorVar2,
VectorVar3,
VectorVar4,
VectorVar5,
VectorVar6,
SE2,
SE3,
SO2,
SO3,
Variable, VariableUmbrella, VectorVar1, VectorVar2, VectorVar3, VectorVar4, VectorVar5,
VectorVar6, SE2, SE3, SO2, SO3,
},
};

Expand All @@ -56,7 +40,7 @@ tag_residual!(
/// $$
///
/// where $z$ is the measured value.
#[derive(Clone, Debug, derive_more::Display)]
#[derive(Clone, Debug)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
pub struct BetweenResidual<P: Variable> {
delta: P,
Expand Down Expand Up @@ -107,3 +91,9 @@ where
self.residual2_jacobian(values, keys)
}
}

impl<P: Variable> fmt::Display for BetweenResidual<P> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{:?}", self)
}
}
36 changes: 13 additions & 23 deletions src/residuals/prior.rs
Original file line number Diff line number Diff line change
@@ -1,33 +1,17 @@
use core::fmt;

use super::{Residual, Residual1};
#[allow(unused_imports)]
use crate::{
containers::{Key, Values},
linalg::{
AllocatorBuffer,
Const,
DefaultAllocator,
DiffResult,
DualAllocator,
DualVector,
ForwardProp,
MatrixX,
Numeric,
VectorX,
AllocatorBuffer, Const, DefaultAllocator, DiffResult, DualAllocator, DualVector,
ForwardProp, MatrixX, Numeric, VectorX,
},
tag_residual,
variables::{
Variable,
VariableUmbrella,
VectorVar1,
VectorVar2,
VectorVar3,
VectorVar4,
VectorVar5,
VectorVar6,
SE2,
SE3,
SO2,
SO3,
Variable, VariableUmbrella, VectorVar1, VectorVar2, VectorVar3, VectorVar4, VectorVar5,
VectorVar6, SE2, SE3, SO2, SO3,
},
};

Expand All @@ -51,7 +35,7 @@ tag_residual!(
/// z \ominus v
/// $$
/// where $z$ is the prior value and $v$ is the variable being estimated.
#[derive(Clone, Debug, derive_more::Display)]
#[derive(Clone, Debug)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
pub struct PriorResidual<P: Variable> {
prior: P,
Expand Down Expand Up @@ -96,6 +80,12 @@ where
}
}

impl<P: Variable> fmt::Display for PriorResidual<P> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{:?}", self)
}
}

#[cfg(test)]
mod test {

Expand Down
24 changes: 7 additions & 17 deletions src/variables/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,8 @@ use downcast_rs::{impl_downcast, Downcast};
use crate::{
dtype,
linalg::{
AllocatorBuffer,
Const,
DefaultAllocator,
DimName,
DualAllocator,
DualVector,
MatrixDim,
MatrixViewDim,
Numeric,
VectorDim,
VectorViewX,
VectorX,
AllocatorBuffer, Const, DefaultAllocator, DimName, DualAllocator, DualVector, MatrixDim,
MatrixViewDim, Numeric, VectorDim, VectorViewX, VectorX,
},
};

Expand Down Expand Up @@ -233,11 +223,11 @@ use nalgebra as na;
/// properties here.
pub trait MatrixLieGroup<D: Numeric = dtype>: Variable<D>
where
na::DefaultAllocator: na::allocator::Allocator<D, Self::TangentDim, Self::TangentDim>,
na::DefaultAllocator: na::allocator::Allocator<D, Self::MatrixDim, Self::MatrixDim>,
na::DefaultAllocator: na::allocator::Allocator<D, Self::VectorDim, Self::TangentDim>,
na::DefaultAllocator: na::allocator::Allocator<D, Self::TangentDim, Const<1>>,
na::DefaultAllocator: na::allocator::Allocator<D, Self::VectorDim, Const<1>>,
na::DefaultAllocator: na::allocator::Allocator<Self::TangentDim, Self::TangentDim>,
na::DefaultAllocator: na::allocator::Allocator<Self::MatrixDim, Self::MatrixDim>,
na::DefaultAllocator: na::allocator::Allocator<Self::VectorDim, Self::TangentDim>,
na::DefaultAllocator: na::allocator::Allocator<Self::TangentDim, Const<1>>,
na::DefaultAllocator: na::allocator::Allocator<Self::VectorDim, Const<1>>,
{
/// Dimension of the tangent space
type TangentDim: DimName;
Expand Down

0 comments on commit 05cec8c

Please sign in to comment.