Skip to content

Commit 2268269

Browse files
authored
Merge pull request #153 from fabinsch/fix-eigen-transposeInPlace
transposeInPlace only if eigen >= 3.4.0
2 parents 3a60ec7 + 7e1e8f0 commit 2268269

File tree

4 files changed

+24
-32
lines changed

4 files changed

+24
-32
lines changed

bindings/python/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ function(CREATE_PYTHON_TARGET target_name COMPILE_OPTIONS dependencies)
5252
target_compile_definitions(${target_name}
5353
PRIVATE PYTHON_MODULE_NAME=${target_name})
5454
target_include_directories(
55-
${target_name} PRIVATE ${PROJECT_SOURCE_DIR}/external/cereal/include)
55+
${target_name} SYSTEM PRIVATE ${PROJECT_SOURCE_DIR}/external/cereal/include)
5656
set_target_properties(
5757
${target_name}
5858
PROPERTIES OUTPUT_NAME ${target_name}

include/proxsuite/serialization/eigen.hpp

Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -16,54 +16,48 @@
1616
namespace cereal {
1717

1818
// dense matrices
19-
template<class Archive,
20-
class _Scalar,
21-
int _Rows,
22-
int _Cols,
23-
int _Options,
24-
int _MaxRows,
25-
int _MaxCols>
19+
template<class Archive, class Derived>
2620
inline void
27-
save(
28-
Archive& ar,
29-
Eigen::Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols> const& m)
21+
save(Archive& ar, Eigen::PlainObjectBase<Derived> const& m)
3022
{
23+
typedef Eigen::PlainObjectBase<Derived> PlainType;
24+
3125
Eigen::Index rows = m.rows();
3226
Eigen::Index cols = m.cols();
33-
ar(rows);
34-
ar(cols);
35-
ar(_Options);
27+
ar(CEREAL_NVP(rows));
28+
ar(CEREAL_NVP(cols));
29+
bool is_row_major = PlainType::IsRowMajor;
30+
ar(CEREAL_NVP(is_row_major));
3631

3732
for (Eigen::Index i = 0; i < m.size(); i++)
3833
ar(m.data()[i]);
3934
}
4035

41-
template<class Archive,
42-
class _Scalar,
43-
int _Rows,
44-
int _Cols,
45-
int _Options,
46-
int _MaxRows,
47-
int _MaxCols>
36+
template<class Archive, class Derived>
4837
inline void
49-
load(Archive& ar,
50-
Eigen::Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>& m)
38+
load(Archive& ar, Eigen::PlainObjectBase<Derived>& m)
5139
{
40+
typedef Eigen::PlainObjectBase<Derived> PlainType;
41+
5242
Eigen::Index rows;
5343
Eigen::Index cols;
54-
int _OptionsLoaded;
55-
ar(rows);
56-
ar(cols);
57-
ar(_OptionsLoaded);
44+
bool is_row_major;
45+
ar(CEREAL_NVP(rows));
46+
ar(CEREAL_NVP(cols));
47+
ar(CEREAL_NVP(is_row_major));
5848

5949
m.resize(rows, cols);
6050

6151
for (Eigen::Index i = 0; i < m.size(); i++)
6252
ar(m.data()[i]);
6353

6454
// Account for different storage orders
65-
if (!(_OptionsLoaded == _Options)) {
55+
if (is_row_major != PlainType::IsRowMajor) {
56+
#if EIGEN_VERSION_AT_LEAST(3, 4, 0)
6657
m.transposeInPlace();
58+
#else
59+
m = m.transpose().eval();
60+
#endif
6761
}
6862
}
6963

test/CMakeLists.txt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,13 @@ endmacro(ADD_TEST_CFLAGS)
5151

5252
make_directory("${CMAKE_CURRENT_BINARY_DIR}/serialization-data")
5353
proxsuite_test(serialization src/serialization.cpp)
54-
target_compile_definitions(test-cpp-serialization
55-
PRIVATE PROXSUITE_WITH_SERIALIZATION)
5654
add_test_cflags(
5755
test-cpp-serialization
5856
"-DTEST_SERIALIZATION_FOLDER=\\\\\"${CMAKE_CURRENT_BINARY_DIR}/serialization-data\\\\\""
5957
)
6058
target_include_directories(
61-
test-cpp-serialization PRIVATE ${PROJECT_SOURCE_DIR}/external/cereal/include)
59+
test-cpp-serialization SYSTEM
60+
PRIVATE ${PROJECT_SOURCE_DIR}/external/cereal/include)
6261

6362
if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug" AND NOT MSVC)
6463
proxsuite_test(dense_maros_meszaros src/dense_maros_meszaros.cpp)

test/src/serialization.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@ DOCTEST_TEST_CASE("test serialization of qp model, results and settings")
113113
{
114114
std::cout << "--- serialization ---" << std::endl;
115115
double sparsity_factor = 0.15;
116-
T eps_abs = T(1e-9);
117116
utils::rand::set_seed(1);
118117
dense::isize dim = 10;
119118

0 commit comments

Comments
 (0)