Last active
October 23, 2022 19:29
-
-
Save alecjacobson/af9df5da30615db21a3600653f9be01b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// via https://stackoverflow.com/a/22885856/148668 | |
#include <cereal/cereal.hpp> | |
#include <cereal/archives/binary.hpp> | |
#include <igl/writeDMAT.h> | |
#include <Eigen/Dense> | |
#include <fstream> | |
namespace cereal | |
{ | |
template <class Archive, class _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols> inline | |
typename std::enable_if<traits::is_output_serializable<BinaryData<_Scalar>, Archive>::value, void>::type | |
save(Archive & ar, Eigen::Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols> const & m) | |
{ | |
int32_t rows = m.rows(); | |
int32_t cols = m.cols(); | |
ar(rows); | |
ar(cols); | |
ar(binary_data(m.data(), rows * cols * sizeof(_Scalar))); | |
} | |
template <class Archive, class _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols> inline | |
typename std::enable_if<traits::is_input_serializable<BinaryData<_Scalar>, Archive>::value, void>::type | |
load(Archive & ar, Eigen::Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols> & m) | |
{ | |
int32_t rows; | |
int32_t cols; | |
ar(rows); | |
ar(cols); | |
m.resize(rows, cols); | |
ar(binary_data(m.data(), static_cast<std::size_t>(rows * cols * sizeof(_Scalar)))); | |
} | |
} | |
int main(int argc, char * argv[]) { | |
Eigen::MatrixXd A; | |
{ | |
std::ifstream in(argv[1], std::ios::binary); | |
cereal::BinaryInputArchive archive_i(in); | |
archive_i(A); | |
} | |
igl::writeDMAT(argv[2],A); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment