src/serialization/eigen.hpp
Go to the documentation of this file.
1 //
2 // Copyright (c) 2017-2020 CNRS INRIA
3 //
4 
5 #ifndef __pinocchio_serialization_eigen_matrix_hpp__
6 #define __pinocchio_serialization_eigen_matrix_hpp__
7 
8 #include <Eigen/Dense>
9 #include "pinocchio/math/tensor.hpp"
10 
11 #include <boost/serialization/split_free.hpp>
12 #include <boost/serialization/vector.hpp>
13 #include <boost/serialization/array.hpp>
14 
15 namespace boost
16 {
17  namespace serialization
18  {
19 
20  template <class Archive, typename Scalar, int Rows, int Cols, int Options, int MaxRows, int MaxCols>
21  void save(Archive & ar, const Eigen::Matrix<Scalar,Rows,Cols,Options,MaxRows,MaxCols> & m, const unsigned int /*version*/)
22  {
23  Eigen::DenseIndex rows(m.rows()), cols(m.cols());
24  if (Rows == Eigen::Dynamic)
25  ar & BOOST_SERIALIZATION_NVP(rows);
26  if (Cols == Eigen::Dynamic)
27  ar & BOOST_SERIALIZATION_NVP(cols);
28  ar & make_nvp("data",make_array(m.data(), (size_t)m.size()));
29  }
30 
31  template <class Archive, typename Scalar, int Rows, int Cols, int Options, int MaxRows, int MaxCols>
32  void load(Archive & ar, Eigen::Matrix<Scalar,Rows,Cols,Options,MaxRows,MaxCols> & m, const unsigned int /*version*/)
33  {
34  Eigen::DenseIndex rows = Rows, cols = Cols;
35  if (Rows == Eigen::Dynamic)
36  ar >> BOOST_SERIALIZATION_NVP(rows);
37  if (Cols == Eigen::Dynamic)
38  ar >> BOOST_SERIALIZATION_NVP(cols);
39  m.resize(rows,cols);
40  ar >> make_nvp("data",make_array(m.data(), (size_t)m.size()));
41  }
42 
43  template <class Archive, typename Scalar, int Rows, int Cols, int Options, int MaxRows, int MaxCols>
44  void serialize(Archive & ar, Eigen::Matrix<Scalar,Rows,Cols,Options,MaxRows,MaxCols> & m, const unsigned int version)
45  {
46  split_free(ar,m,version);
47  }
48 
49  template <class Archive, typename PlainObjectBase, int MapOptions, typename StrideType>
50  void save(Archive & ar, const Eigen::Map<PlainObjectBase,MapOptions,StrideType> & m, const unsigned int /*version*/)
51  {
52  Eigen::DenseIndex rows(m.rows()), cols(m.cols());
53  if (PlainObjectBase::RowsAtCompileTime == Eigen::Dynamic)
54  ar & BOOST_SERIALIZATION_NVP(rows);
55  if (PlainObjectBase::ColsAtCompileTime == Eigen::Dynamic)
56  ar & BOOST_SERIALIZATION_NVP(cols);
57  ar & make_nvp("data",make_array(m.data(), (size_t)m.size()));
58  }
59 
60  template <class Archive, typename PlainObjectBase, int MapOptions, typename StrideType>
61  void load(Archive & ar, Eigen::Map<PlainObjectBase,MapOptions,StrideType> & m, const unsigned int /*version*/)
62  {
63  Eigen::DenseIndex rows = PlainObjectBase::RowsAtCompileTime, cols = PlainObjectBase::ColsAtCompileTime;
64  if (PlainObjectBase::RowsAtCompileTime == Eigen::Dynamic)
65  ar >> BOOST_SERIALIZATION_NVP(rows);
66  if (PlainObjectBase::ColsAtCompileTime == Eigen::Dynamic)
67  ar >> BOOST_SERIALIZATION_NVP(cols);
68  m.resize(rows,cols);
69  ar >> make_nvp("data",make_array(m.data(), (size_t)m.size()));
70  }
71 
72  template <class Archive, typename PlainObjectBase, int MapOptions, typename StrideType>
73  void serialize(Archive & ar, Eigen::Map<PlainObjectBase,MapOptions,StrideType> & m, const unsigned int version)
74  {
75  split_free(ar,m,version);
76  }
77 
78 #if !defined(PINOCCHIO_WITH_EIGEN_TENSOR_MODULE) && ((__cplusplus <= 199711L && EIGEN_COMP_MSVC < 1900) || defined(__CUDACC__) || defined(EIGEN_AVOID_STL_ARRAY))
79  template <class Archive, typename _IndexType, std::size_t _NumIndices>
80  void save(Archive & ar, const Eigen::array<_IndexType,_NumIndices> & a, const unsigned int /*version*/)
81  {
82  ar & make_nvp("array",make_array(&a.front(),_NumIndices));
83  }
84 
85  template <class Archive, typename _IndexType, std::size_t _NumIndices>
86  void load(Archive & ar, Eigen::array<_IndexType,_NumIndices> & a, const unsigned int /*version*/)
87  {
88  ar >> make_nvp("array",make_array(&a.front(),_NumIndices));
89  }
90 
91  template <class Archive, typename _IndexType, std::size_t _NumIndices>
92  void serialize(Archive & ar, Eigen::array<_IndexType,_NumIndices> & a, const unsigned int version)
93  {
94  split_free(ar,a,version);
95  }
96 #else
97  template <class Archive, class T, std::size_t N>
98  void save(Archive& ar, const std::array<T,N> & a, const unsigned int version)
99  {
100  typedef std::array<T,N> Array;
101  serialize(ar,const_cast<Array&>(a),version);
102  }
103 
104  template <class Archive, class T, std::size_t N>
105  void load(Archive& ar, std::array<T,N> & a, const unsigned int version)
106  {
107  serialize(ar,a,version);
108  }
109 #endif
110 
111 #ifdef PINOCCHIO_WITH_EIGEN_TENSOR_MODULE
112 
113  template <class Archive, typename _IndexType, int _NumIndices>
114  void save(Archive & ar, const Eigen::DSizes<_IndexType,_NumIndices> & ds, const unsigned int version)
115  {
116  save(ar,static_cast<const Eigen::array<_IndexType,_NumIndices> &>(ds),version);
117  }
118 
119  template <class Archive, typename _IndexType, int _NumIndices>
120  void load(Archive & ar, Eigen::DSizes<_IndexType,_NumIndices> & ds, const unsigned int version)
121  {
122  load(ar,static_cast<Eigen::array<_IndexType,_NumIndices> &>(ds),version);
123  }
124 
125  template <class Archive, typename _IndexType, int _NumIndices>
126  void serialize(Archive & ar, Eigen::DSizes<_IndexType,_NumIndices> & ds, const unsigned int version)
127  {
128  split_free(ar,static_cast<Eigen::array<_IndexType,_NumIndices> &>(ds),version);
129  }
130 
131 #endif
132 
133  template <class Archive, typename _Scalar, int _NumIndices, int _Options, typename _IndexType>
134  void save(Archive & ar, const ::pinocchio::Tensor<_Scalar,_NumIndices,_Options,_IndexType> & t, const unsigned int /*version*/)
135  {
136  typedef ::pinocchio::Tensor<_Scalar,_NumIndices,_Options,_IndexType> Tensor;
137  const typename Tensor::Dimensions & dimensions = t.dimensions();
138 
139  ar & BOOST_SERIALIZATION_NVP(dimensions);
140  ar & make_nvp("data",make_array(t.data(), (size_t)t.size()));
141  }
142 
143  template <class Archive, typename _Scalar, int _NumIndices, int _Options, typename _IndexType>
144  void load(Archive & ar, ::pinocchio::Tensor<_Scalar,_NumIndices,_Options,_IndexType> & t, const unsigned int /*version*/)
145  {
146  typedef ::pinocchio::Tensor<_Scalar,_NumIndices,_Options,_IndexType> Tensor;
147  typename Tensor::Dimensions dimensions;
148 
149  ar >> BOOST_SERIALIZATION_NVP(dimensions);
150  t.resize(dimensions);
151 
152  ar >> make_nvp("data",make_array(t.data(), (size_t)t.size()));
153  }
154 
155  template <class Archive, typename _Scalar, int _NumIndices, int _Options, typename _IndexType>
156  void serialize(Archive & ar, ::pinocchio::Tensor<_Scalar,_NumIndices,_Options,_IndexType> & t, const unsigned int version)
157  {
158  split_free(ar,t,version);
159  }
160 
161  }
162 }
163 
164 #endif // ifndef __pinocchio_serialization_eigen_matrix_hpp__
int rows
void save(Archive &ar, const Eigen::Matrix< Scalar, Rows, Cols, Options, MaxRows, MaxCols > &m, const unsigned int)
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index size() const
Definition: tensor.hpp:107
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T & front()
Definition: tensor.hpp:28
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar * data()
Definition: tensor.hpp:112
EIGEN_DEVICE_FUNC void resize(const Eigen::array< Index, NumIndices > &dimensions)
Definition: tensor.hpp:234
const nvp< typename pinocchio::container::aligned_vector< T >::vector_base > make_nvp(const char *name, pinocchio::container::aligned_vector< T > &t)
int cols
void load(Archive &ar, Eigen::Matrix< Scalar, Rows, Cols, Options, MaxRows, MaxCols > &m, const unsigned int)
void serialize(Archive &ar, pinocchio::container::aligned_vector< T > &v, const unsigned int version)
list a


pinocchio
Author(s):
autogenerated on Tue Jun 1 2021 02:45:02