MatrixSerialization.h
Go to the documentation of this file.
1 /* ----------------------------------------------------------------------------
2 
3  * GTSAM Copyright 2010, Georgia Tech Research Corporation,
4  * Atlanta, Georgia 30332-0415
5  * All Rights Reserved
6  * Authors: Frank Dellaert, et al. (see THANKS for the full author list)
7 
8  * See LICENSE for the license information
9 
10  * -------------------------------------------------------------------------- */
11 
19 // \callgraph
20 
21 // Defined only if boost serialization is enabled
22 #ifdef GTSAM_ENABLE_BOOST_SERIALIZATION
23 #pragma once
24 
25 #include <gtsam/base/Matrix.h>
26 
27 #include <boost/serialization/array.hpp>
28 #include <boost/serialization/nvp.hpp>
29 #include <boost/serialization/split_free.hpp>
30 
31 namespace boost {
32 namespace serialization {
33 
49 // split version - sends sizes ahead
50 template <class Archive, typename Scalar_, int Rows_, int Cols_, int Ops_,
51  int MaxRows_, int MaxCols_>
52 void save(
53  Archive& ar,
55  const unsigned int /*version*/) {
56  const size_t rows = m.rows(), cols = m.cols();
57  ar << BOOST_SERIALIZATION_NVP(rows);
58  ar << BOOST_SERIALIZATION_NVP(cols);
59  ar << make_nvp("data", make_array(m.data(), m.size()));
60 }
61 
62 template <class Archive, typename Scalar_, int Rows_, int Cols_, int Ops_,
63  int MaxRows_, int MaxCols_>
64 void load(Archive& ar,
66  const unsigned int /*version*/) {
67  size_t rows, cols;
68  ar >> BOOST_SERIALIZATION_NVP(rows);
69  ar >> BOOST_SERIALIZATION_NVP(cols);
70  m.resize(rows, cols);
71  ar >> make_nvp("data", make_array(m.data(), m.size()));
72 }
73 
74 // templated version of BOOST_SERIALIZATION_SPLIT_FREE(Eigen::Matrix);
75 template <class Archive, typename Scalar_, int Rows_, int Cols_, int Ops_,
76  int MaxRows_, int MaxCols_>
77 void serialize(
78  Archive& ar,
80  const unsigned int version) {
81  split_free(ar, m, version);
82 }
83 
84 // specialized to Matrix for MATLAB wrapper
85 template <class Archive>
86 void serialize(Archive& ar, gtsam::Matrix& m, const unsigned int version) {
87  split_free(ar, m, version);
88 }
89 
90 } // namespace serialization
91 } // namespace boost
92 #endif
Matrix3f m
std::string serialize(const T &input)
serializes to a string
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar * data() const
Eigen::MatrixXd Matrix
Definition: base/Matrix.h:39
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR Index rows() const EIGEN_NOEXCEPT
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void resize(Index rows, Index cols)
The matrix class, also used for vectors and row-vectors.
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR Index cols() const EIGEN_NOEXCEPT


gtsam
Author(s):
autogenerated on Tue Jul 4 2023 02:34:54