Bertini 2 d882924 (2026-10-06 19:56 UTC)
Numerical algebraic geometry library (C++ core)
Loading...
Searching...
No Matches
eigen_serialization_addon.hpp
Go to the documentation of this file.
1
2
3
4// the following code comes from
5// https://stackoverflow.com/questions/18382457/eigen-and-boostserialize
6// and adds support for serialization of Eigen types
7//
8// question asked by user Gabriel and answered by iNFINITEi
9//
10// answer code repeated here verbatim.
11// please update this comment if this code is changed,
12// and post the modifications to the above referenced post on SO.
13
14
15
19
20#ifndef EIGEN_SERIALIZATION_ADDON_HPP
21#define EIGEN_SERIALIZATION_ADDON_HPP
22
23#pragma once
24
26// This file is an Eigen plugin fragment: its contents are injected into the body
27// of Eigen::DenseBase, so the members below have no enclosing class of their own
28// here. Hidden from Doxygen, which would otherwise fail to resolve them.
29
30friend class boost::serialization::access;
31template<class Archive>
32void save(Archive & ar, const unsigned int /*version*/) const {
33 derived().eval();
34 const Eigen::Index rows = derived().rows(), cols = derived().cols();
35 ar & rows;
36 ar & cols;
37 for (Index j = 0; j < cols; ++j )
38 for (Index i = 0; i < rows; ++i )
39 ar & derived().coeff(i, j);
40}
41
42template<class Archive>
43void load(Archive & ar, const unsigned int /*version*/) {
44 Eigen::Index rows, cols;
45 ar & rows;
46 ar & cols;
47 if (rows != derived().rows() || cols != derived().cols() )
48 derived().resize(rows, cols);
49 ar & boost::serialization::make_array(derived().data(), derived().size());
50}
51
52template<class Archive>
53void serialize(Archive & ar, const unsigned int file_version) {
54 boost::serialization::split_member(ar, *this, file_version);
55}
57
58#endif // EIGEN_SERIALIZATION_ADDON_HPP
void load(Archive &ar, ::boost::multiprecision::backends::mpc_complex_backend< 0 > &r, unsigned)
Load a mpc_complex type from a boost archive.
Definition mpfr_complex.hpp:208
void save(Archive &ar, ::boost::multiprecision::backends::mpc_complex_backend< 0 > const &r, unsigned)
Save a mpc_complex type to a boost archive.
Definition mpfr_complex.hpp:196