|
16 | 16 | namespace cereal { |
17 | 17 |
|
18 | 18 | // 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> |
26 | 20 | 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) |
30 | 22 | { |
| 23 | + typedef Eigen::PlainObjectBase<Derived> PlainType; |
| 24 | + |
31 | 25 | Eigen::Index rows = m.rows(); |
32 | 26 | Eigen::Index cols = m.cols(); |
33 | 27 | ar(CEREAL_NVP(rows)); |
34 | 28 | ar(CEREAL_NVP(cols)); |
35 | | - int storage_order; |
36 | | - if (m.IsRowMajor) { |
37 | | - storage_order = 1; |
38 | | - } else { |
39 | | - storage_order = 0; |
40 | | - } |
41 | | - ar(CEREAL_NVP(storage_order)); |
| 29 | + bool is_row_major = PlainType::IsRowMajor; |
| 30 | + ar(CEREAL_NVP(is_row_major)); |
42 | 31 |
|
43 | 32 | for (Eigen::Index i = 0; i < m.size(); i++) |
44 | 33 | ar(m.data()[i]); |
45 | 34 | } |
46 | 35 |
|
47 | | -template<class Archive, |
48 | | - class _Scalar, |
49 | | - int _Rows, |
50 | | - int _Cols, |
51 | | - int _Options, |
52 | | - int _MaxRows, |
53 | | - int _MaxCols> |
| 36 | +template<class Archive, class Derived> |
54 | 37 | inline void |
55 | | -load(Archive& ar, |
56 | | - Eigen::Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>& m) |
| 38 | +load(Archive& ar, Eigen::PlainObjectBase<Derived>& m) |
57 | 39 | { |
| 40 | + typedef Eigen::PlainObjectBase<Derived> PlainType; |
| 41 | + |
58 | 42 | Eigen::Index rows; |
59 | 43 | Eigen::Index cols; |
60 | | - int storage_order; |
| 44 | + bool is_row_major; |
61 | 45 | ar(CEREAL_NVP(rows)); |
62 | 46 | ar(CEREAL_NVP(cols)); |
63 | | - ar(CEREAL_NVP(storage_order)); |
| 47 | + ar(CEREAL_NVP(is_row_major)); |
64 | 48 |
|
65 | 49 | m.resize(rows, cols); |
66 | 50 |
|
67 | 51 | for (Eigen::Index i = 0; i < m.size(); i++) |
68 | 52 | ar(m.data()[i]); |
69 | 53 |
|
70 | 54 | // Account for different storage orders |
71 | | - if (!(storage_order == m.IsRowMajor)) { |
| 55 | + if (is_row_major != PlainType::IsRowMajor) { |
72 | 56 | #if EIGEN_VERSION_AT_LEAST(3, 4, 0) |
73 | 57 | m.transposeInPlace(); |
74 | 58 | #else |
75 | | - Eigen::Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols> m_t( |
76 | | - m.transpose()); |
77 | | - m = m_t; |
| 59 | + m = m.transpose().eval(); |
78 | 60 | #endif |
79 | 61 | } |
80 | 62 | } |
|
0 commit comments