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
libsize.save
save
Definition: libsize.py:15
Matrix.h
typedef and functions to augment Eigen's MatrixXd
gtsam::Matrix
Eigen::MatrixXd Matrix
Definition: base/Matrix.h:39
boost
Definition: boostmultiprec.cpp:109
rows
int rows
Definition: Tutorial_commainit_02.cpp:1
conf.version
version
Definition: gtsam/3rdparty/GeographicLib/python/doc/conf.py:67
m
Matrix3f m
Definition: AngleAxis_mimic_euler.cpp:1
Eigen::Matrix
The matrix class, also used for vectors and row-vectors.
Definition: 3rdparty/Eigen/Eigen/src/Core/Matrix.h:178
cols
int cols
Definition: Tutorial_commainit_02.cpp:1


gtsam
Author(s):
autogenerated on Sat Nov 16 2024 04:03:09