gtsam 4.2.0
gtsam
VectorSerialization.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#pragma once
20
21#include <gtsam/base/Vector.h>
22
23#include <boost/serialization/array.hpp>
24#include <boost/serialization/nvp.hpp>
25#include <boost/serialization/split_free.hpp>
26
27namespace boost {
28namespace serialization {
29
30// split version - copies into an STL vector for serialization
31template <class Archive>
32void save(Archive& ar, const gtsam::Vector& v, unsigned int /*version*/) {
33 const size_t size = v.size();
34 ar << BOOST_SERIALIZATION_NVP(size);
35 ar << make_nvp("data", make_array(v.data(), v.size()));
36}
37
38template <class Archive>
39void load(Archive& ar, gtsam::Vector& v, unsigned int /*version*/) {
40 size_t size;
41 ar >> BOOST_SERIALIZATION_NVP(size);
42 v.resize(size);
43 ar >> make_nvp("data", make_array(v.data(), v.size()));
44}
45
46// split version - copies into an STL vector for serialization
47template <class Archive, int D>
48void save(Archive& ar, const Eigen::Matrix<double, D, 1>& v,
49 unsigned int /*version*/) {
50 ar << make_nvp("data", make_array(v.data(), v.RowsAtCompileTime));
51}
52
53template <class Archive, int D>
54void load(Archive& ar, Eigen::Matrix<double, D, 1>& v,
55 unsigned int /*version*/) {
56 ar >> make_nvp("data", make_array(v.data(), v.RowsAtCompileTime));
57}
58
59} // namespace serialization
60} // namespace boost
61
62BOOST_SERIALIZATION_SPLIT_FREE(gtsam::Vector)
63BOOST_SERIALIZATION_SPLIT_FREE(gtsam::Vector2)
64BOOST_SERIALIZATION_SPLIT_FREE(gtsam::Vector3)
65BOOST_SERIALIZATION_SPLIT_FREE(gtsam::Vector6)
typedef and functions to augment Eigen's VectorXd
void save(const Matrix &A, const string &s, const string &filename)
save a matrix to file, which can be loaded by matlab
Definition: Matrix.cpp:167