NeuralNet 1.0
Loading...
Searching...
No Matches
Serialize.hpp
1#pragma once
2
3#include <Eigen/Dense>
4#include <cereal/archives/binary.hpp>
5#include <cereal/cereal.hpp>
6#include <cereal/types/common.hpp>
7#include <cereal/types/vector.hpp>
8
9#include "Enums.hpp"
10
11namespace cereal {
12template <class Archive, class _Scalar, int _Rows, int _Cols, int _Options,
13 int _MaxRows, int _MaxCols>
14void save(Archive &ar, Eigen::Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows,
15 _MaxCols> const &m) {
16 int32_t rows = m.rows();
17 int32_t cols = m.cols();
18 ar(rows);
19 ar(cols);
20 ar(binary_data(m.data(), rows * cols * sizeof(_Scalar)));
21}
22
23template <class Archive, class _Scalar, int _Rows, int _Cols, int _Options,
24 int _MaxRows, int _MaxCols>
25void load(
26 Archive &ar,
27 Eigen::Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols> &m) {
28 int32_t rows;
29 int32_t cols;
30 ar(rows);
31 ar(cols);
32
33 m.resize(rows, cols);
34
35 ar(binary_data(m.data(),
36 static_cast<std::size_t>(rows * cols * sizeof(_Scalar))));
37}
38
39template <class Archive, class T1, class T2>
40void save(Archive &ar, const std::tuple<T1, T2> &t) {
41 ar(std::get<0>(t), std::get<1>(t));
42}
43
44template <class Archive, class T1, class T2>
45void load(Archive &ar, std::tuple<T1, T2> &t) {
46 ar(std::get<0>(t), std::get<1>(t));
47}
48} // namespace cereal