Skip to content

Commit 3bd6b04

Browse files
authored
Merge pull request #596 from jcarpent/topic/eigen5
Fix compilation issues related to Eigen 5
2 parents ff5d79c + e4a9c0d commit 3bd6b04

File tree

7 files changed

+82
-45
lines changed

7 files changed

+82
-45
lines changed

.github/workflows/nix.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,15 @@ jobs:
1616
fail-fast: false
1717
matrix:
1818
os: [ubuntu, macos]
19+
eigen: [3, 5]
1920
steps:
2021
- uses: actions/checkout@v5
2122
- uses: cachix/install-nix-action@v31
2223
- uses: cachix/cachix-action@v16
2324
with:
2425
name: gepetto
2526
authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}'
26-
- run: nix build -L
27+
- run: nix build -L ".#eigenpy-eigen${{ matrix.eigen }}"
2728

2829
check:
2930
if: always()

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
1515

1616
### Fixed
1717
- Fix partly the support of the change of API of GeneralizedEigenSolver in Eigen 5+ ([#594](https://github.com/stack-of-tasks/eigenpy/pull/594))
18+
- Fix Eigen decompositions and solvers for Eigen 5 ([#596](https://github.com/stack-of-tasks/eigenpy/pull/596))
1819

1920
## [3.12.0] - 2025-08-12
2021

flake.nix

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,27 @@
1919
};
2020
devShells.default = pkgs.mkShell { inputsFrom = [ self'.packages.default ]; };
2121
packages = {
22-
default = self'.packages.eigenpy;
23-
eigen = pkgs.eigen.overrideAttrs {
24-
# Apply https://gitlab.com/libeigen/eigen/-/merge_requests/977
25-
postPatch = ''
26-
substituteInPlace Eigen/src/SVD/BDCSVD.h \
27-
--replace-fail "if (l == 0) {" "if (i >= k && l == 0) {"
28-
'';
29-
};
30-
eigenpy =
31-
(pkgs.python3Packages.eigenpy.override { inherit (self'.packages) eigen; }).overrideAttrs
22+
default = self'.packages.eigenpy-eigen5;
23+
eigen3 = pkgs.eigen.overrideAttrs (super: rec {
24+
version = "3.4.1";
25+
src = pkgs.fetchFromGitLab {
26+
inherit (super.src) owner repo;
27+
tag = version;
28+
hash = "sha256-NSq1tUfy2thz5gtsyASsKeYE4vMf71aSG4uXfrX86rk=";
29+
};
30+
patches = [ ];
31+
postPatch = "";
32+
});
33+
eigen5 = self'.packages.eigen3.overrideAttrs (super: rec {
34+
version = "5.0.0";
35+
src = pkgs.fetchFromGitLab {
36+
inherit (super.src) owner repo;
37+
tag = version;
38+
hash = "sha256-L1KUFZsaibC/FD6abTXrT3pvaFhbYnw+GaWsxM2gaxM=";
39+
};
40+
});
41+
eigenpy-eigen3 =
42+
(pkgs.python3Packages.eigenpy.override { eigen = self'.packages.eigen3; }).overrideAttrs
3243
(_: {
3344
src = pkgs.lib.fileset.toSource {
3445
root = ./.;
@@ -43,6 +54,7 @@
4354
];
4455
};
4556
});
57+
eigenpy-eigen5 = self'.packages.eigenpy-eigen3.override { eigen = self'.packages.eigen5; };
4658
};
4759
};
4860
};

include/eigenpy/decompositions/BDCSVD.hpp

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -35,22 +35,27 @@ struct BDCSVDVisitor
3535

3636
.def("cols", &Solver::cols, bp::arg("self"),
3737
"Returns the number of columns. ")
38-
.def("compute",
39-
(Solver & (Solver::*)(const MatrixType &matrix)) & Solver::compute,
40-
bp::args("self", "matrix"),
41-
"Method performing the decomposition of given matrix. Computes "
42-
"Thin/Full "
43-
"unitaries U/V if specified using the Options template parameter "
44-
"or the class constructor. ",
45-
bp::return_self<>())
46-
.def("compute",
47-
(Solver & (Solver::*)(const MatrixType &matrix,
48-
unsigned int computationOptions)) &
49-
Solver::compute,
50-
bp::args("self", "matrix", "computationOptions"),
51-
"Method performing the decomposition of given matrix, as "
52-
"specified by the computationOptions parameter. ",
53-
bp::return_self<>())
38+
.def(
39+
"compute",
40+
+[](Solver &self, const MatrixType &matrix) -> Solver & {
41+
return self.compute(matrix);
42+
},
43+
bp::args("self", "matrix"),
44+
"Method performing the decomposition of given matrix. Computes "
45+
"Thin/Full "
46+
"unitaries U/V if specified using the Options template parameter "
47+
"or the class constructor. ",
48+
bp::return_self<>())
49+
.def(
50+
"compute",
51+
+[](Solver &self, const MatrixType &matrix,
52+
unsigned int computationOptions) -> Solver & {
53+
return self.compute(matrix, computationOptions);
54+
},
55+
bp::args("self", "matrix", "computationOptions"),
56+
"Method performing the decomposition of given matrix, as "
57+
"specified by the computationOptions parameter. ",
58+
bp::return_self<>())
5459
.def("rows", &Solver::rows, bp::arg("self"),
5560
"Returns the number of rows. ")
5661
.def("setSwitchSize", &Solver::setSwitchSize, bp::args("self", "s"))

include/eigenpy/decompositions/JacobiSVD.hpp

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ namespace eigenpy {
1818
template <typename JacobiSVD>
1919
struct JacobiSVDVisitor
2020
: public boost::python::def_visitor<JacobiSVDVisitor<JacobiSVD>> {
21+
typedef JacobiSVD Solver;
2122
typedef typename JacobiSVD::MatrixType MatrixType;
23+
typedef Eigen::MatrixBase<MatrixType> MatrixBaseType;
2224
typedef typename MatrixType::Scalar Scalar;
2325

2426
template <class PyClass>
@@ -34,23 +36,27 @@ struct JacobiSVDVisitor
3436

3537
.def("cols", &JacobiSVD::cols, bp::arg("self"),
3638
"Returns the number of columns. ")
37-
.def("compute",
38-
(JacobiSVD & (JacobiSVD::*)(const MatrixType &matrix)) &
39-
JacobiSVD::compute,
40-
bp::args("self", "matrix"),
41-
"Method performing the decomposition of given matrix. Computes "
42-
"Thin/Full "
43-
"unitaries U/V if specified using the Options template parameter "
44-
"or the class constructor. ",
45-
bp::return_self<>())
46-
.def("compute",
47-
(JacobiSVD & (JacobiSVD::*)(const MatrixType &matrix,
48-
unsigned int computationOptions)) &
49-
JacobiSVD::compute,
50-
bp::args("self", "matrix", "computationOptions"),
51-
"Method performing the decomposition of given matrix, as "
52-
"specified by the computationOptions parameter. ",
53-
bp::return_self<>())
39+
.def(
40+
"compute",
41+
+[](Solver &self, const MatrixType &matrix) -> Solver & {
42+
return self.compute(matrix);
43+
},
44+
bp::args("self", "matrix"),
45+
"Method performing the decomposition of given matrix. Computes "
46+
"Thin/Full "
47+
"unitaries U/V if specified using the Options template parameter "
48+
"or the class constructor. ",
49+
bp::return_self<>())
50+
.def(
51+
"compute",
52+
+[](Solver &self, const MatrixType &matrix,
53+
unsigned int computationOptions) -> Solver & {
54+
return self.compute(matrix, computationOptions);
55+
},
56+
bp::args("self", "matrix", "computation_options"),
57+
"Method performing the decomposition of given matrix, as "
58+
"specified by the computationOptions parameter. ",
59+
bp::return_self<>())
5460
.def("rows", &JacobiSVD::rows, bp::arg("self"),
5561
"Returns the number of rows.")
5662

include/eigenpy/decompositions/sparse/SparseLU.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,14 @@ struct SparseLUVisitor : public boost::python::def_visitor<
9898

9999
typedef typename Solver::SCMatrix SCMatrix;
100100
typedef typename MatrixType::StorageIndex StorageIndex;
101+
102+
#if EIGEN_VERSION_AT_LEAST(3, 4, 90)
103+
typedef Eigen::Map<Eigen::SparseMatrix<Scalar, Eigen::ColMajor, StorageIndex>>
104+
MappedSparseMatrix;
105+
#else
101106
typedef Eigen::MappedSparseMatrix<Scalar, Eigen::ColMajor, StorageIndex>
102107
MappedSparseMatrix;
108+
#endif
103109
typedef Eigen::SparseLUMatrixLReturnType<SCMatrix> LType;
104110
typedef Eigen::SparseLUMatrixUReturnType<SCMatrix, MappedSparseMatrix> UType;
105111

src/decompositions/sparse-lu-solver.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,14 @@ void exposeSparseLUSolver() {
1515

1616
typedef typename SparseLUType::Scalar Scalar;
1717
typedef typename SparseLUType::SCMatrix SCMatrix;
18-
typedef Eigen::MappedSparseMatrix<Scalar, ColMajor, StorageIndex>
18+
19+
#if EIGEN_VERSION_AT_LEAST(3, 4, 90)
20+
typedef Eigen::Map<Eigen::SparseMatrix<Scalar, Eigen::ColMajor, StorageIndex>>
21+
MappedSparseMatrix;
22+
#else
23+
typedef Eigen::MappedSparseMatrix<Scalar, Eigen::ColMajor, StorageIndex>
1924
MappedSparseMatrix;
25+
#endif
2026

2127
SparseLUMatrixLReturnTypeVisitor<SCMatrix>::expose(
2228
("SparseLUMatrixLReturnType"));

0 commit comments

Comments
 (0)