gtsam 4.2.0
gtsam
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#pragma once
22
23#include <gtsam/base/Matrix.h>
24
25#include <boost/serialization/array.hpp>
26#include <boost/serialization/nvp.hpp>
27#include <boost/serialization/split_free.hpp>
28
29namespace boost {
30namespace serialization {
31
47// split version - sends sizes ahead
48template <class Archive, typename Scalar_, int Rows_, int Cols_, int Ops_,
49 int MaxRows_, int MaxCols_>
50void save(
51 Archive& ar,
52 const Eigen::Matrix<Scalar_, Rows_, Cols_, Ops_, MaxRows_, MaxCols_>& m,
53 const unsigned int /*version*/) {
54 const size_t rows = m.rows(), cols = m.cols();
55 ar << BOOST_SERIALIZATION_NVP(rows);
56 ar << BOOST_SERIALIZATION_NVP(cols);
57 ar << make_nvp("data", make_array(m.data(), m.size()));
58}
59
60template <class Archive, typename Scalar_, int Rows_, int Cols_, int Ops_,
61 int MaxRows_, int MaxCols_>
62void load(Archive& ar,
63 Eigen::Matrix<Scalar_, Rows_, Cols_, Ops_, MaxRows_, MaxCols_>& m,
64 const unsigned int /*version*/) {
65 size_t rows, cols;
66 ar >> BOOST_SERIALIZATION_NVP(rows);
67 ar >> BOOST_SERIALIZATION_NVP(cols);
68 m.resize(rows, cols);
69 ar >> make_nvp("data", make_array(m.data(), m.size()));
70}
71
72// templated version of BOOST_SERIALIZATION_SPLIT_FREE(Eigen::Matrix);
73template <class Archive, typename Scalar_, int Rows_, int Cols_, int Ops_,
74 int MaxRows_, int MaxCols_>
75void serialize(
76 Archive& ar,
77 Eigen::Matrix<Scalar_, Rows_, Cols_, Ops_, MaxRows_, MaxCols_>& m,
78 const unsigned int version) {
79 split_free(ar, m, version);
80}
81
82// specialized to Matrix for MATLAB wrapper
83template <class Archive>
84void serialize(Archive& ar, gtsam::Matrix& m, const unsigned int version) {
85 split_free(ar, m, version);
86}
87
88} // namespace serialization
89} // namespace boost
typedef and functions to augment Eigen's MatrixXd