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 // Defined only if boost serialization is enabled
20 #ifdef GTSAM_ENABLE_BOOST_SERIALIZATION
21 #pragma once
22 
23 #include <gtsam/base/Vector.h>
24 
25 #include <boost/serialization/array.hpp>
26 #include <boost/serialization/nvp.hpp>
27 #include <boost/serialization/split_free.hpp>
28 
29 namespace boost {
30 namespace serialization {
31 
32 // split version - copies into an STL vector for serialization
33 template <class Archive>
34 void save(Archive& ar, const gtsam::Vector& v, unsigned int /*version*/) {
35  const size_t size = v.size();
36  ar << BOOST_SERIALIZATION_NVP(size);
37  ar << make_nvp("data", make_array(v.data(), v.size()));
38 }
39 
40 template <class Archive>
41 void load(Archive& ar, gtsam::Vector& v, unsigned int /*version*/) {
42  size_t size;
43  ar >> BOOST_SERIALIZATION_NVP(size);
44  v.resize(size);
45  ar >> make_nvp("data", make_array(v.data(), v.size()));
46 }
47 
48 // split version - copies into an STL vector for serialization
49 template <class Archive, int D>
50 void save(Archive& ar, const Eigen::Matrix<double, D, 1>& v,
51  unsigned int /*version*/) {
52  ar << make_nvp("data", make_array(v.data(), v.RowsAtCompileTime));
53 }
54 
55 template <class Archive, int D>
56 void load(Archive& ar, Eigen::Matrix<double, D, 1>& v,
57  unsigned int /*version*/) {
58  ar >> make_nvp("data", make_array(v.data(), v.RowsAtCompileTime));
59 }
60 
61 } // namespace serialization
62 } // namespace boost
63 
64 BOOST_SERIALIZATION_SPLIT_FREE(gtsam::Vector)
65 BOOST_SERIALIZATION_SPLIT_FREE(gtsam::Vector2)
66 BOOST_SERIALIZATION_SPLIT_FREE(gtsam::Vector3)
67 BOOST_SERIALIZATION_SPLIT_FREE(gtsam::Vector6)
68 #endif
Eigen::Vector3d Vector3
Definition: Vector.h:43
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar * data() const
Scalar Scalar int size
Definition: benchVecAdd.cpp:17
Eigen::VectorXd Vector
Definition: Vector.h:38
Array< int, Dynamic, 1 > v
typedef and functions to augment Eigen&#39;s VectorXd
Eigen::Vector2d Vector2
Definition: Vector.h:42
The matrix class, also used for vectors and row-vectors.


gtsam
Author(s):
autogenerated on Tue Jul 4 2023 02:40:43