24 #ifndef SOM_SERIALIZE_H
25 #define SOM_SERIALIZE_H
28 #include <boost/archive/binary_iarchive.hpp>
29 #include <boost/archive/binary_oarchive.hpp>
30 #include <CCfits/CCfits>
38 template <std::
size_t ND,
typename DistFunc>
42 boost::archive::binary_oarchive boa {out};
46 template <std::
size_t ND,
typename DistFunc=Distance::L2<ND>>
48 boost::archive::binary_iarchive bia {in};
58 template <std::
size_t ND,
typename DistFunc>
66 long ax_sizes[3] = {(long)x, (
long)y, (long)ND};
67 CCfits::FITS fits (filename, DOUBLE_IMG, n_axes, ax_sizes);
70 fits.pHDU().addKey(
"DISTFUNC",
typeid(DistFunc).name(),
"");
77 for (
auto& w_arr : som) {
82 fits.pHDU().write(1, total_size, data);
86 template <std::
size_t ND,
typename DistFunc=Distance::L2<ND>>
89 CCfits::FITS fits (filename, CCfits::Read);
93 fits.pHDU().readKey(
"DISTFUNC", dist_func_type);
94 if (dist_func_type !=
typeid(DistFunc).name()) {
96 << dist_func_type <<
" and is read as " <<
typeid(DistFunc).name();
100 if (fits.pHDU().axes() != 3) {
101 throw Elements::Exception() <<
"Data array in file " << filename <<
" does not have 3 dimensions";
103 if (fits.pHDU().axis(2) != ND) {
105 " should have size " << ND <<
" but was " << fits.pHDU().axis(2);
112 fits.pHDU().read(data);
118 for (
auto& w_arr : result) {
119 w_arr[w_i] = data[i];