// Example for supporting serialization in boost::numeric::ublas::symmetrix_matrix. // ===================================================================== // In response to https://svn.boost.org/trac/boost/ticket/10045 // Author // ============== // Shivam Mittal // Email - 2015csb1032@iitrpr.ac.in // Github profile - github.com/shivam5 // Date - 2nd April 2017 // Compiling // ========== // g++ -I symmetric_matrix_serialize.cpp -L -static -lboost_serialization // Example (my computer): // g++ -I /home/shivam/Desktop/boost/modular_boost/ symmetric_matrix_serialize.cpp -L/home/shivam/Desktop/boost/modular_boost/stage/lib -static -lboost_serialization // Running // ========== // ./a.out #include #include #include #include #include #include #include using namespace boost::numeric::ublas; template void save_smatrix(const symmetric_matrix &s, const char * filename){ std::ofstream ofs(filename); boost::archive::text_oarchive oa(ofs); oa << s; } template void load_smatrix(symmetric_matrix &s, const char * filename){ std::ifstream ifs(filename); boost::archive::text_iarchive ia(ifs); ia >> s; } int main () { std::string filename = "filename"; symmetric_matrix ml (3, 3); for (unsigned i = 0; i < ml.size1 (); ++ i) for (unsigned j = 0; j <= i; ++ j) ml (i, j) = 3 * i + j; symmetric_matrix mu (3, 3); for (unsigned i = 0; i < mu.size1 (); ++ i) for (unsigned j = i; j < mu.size2 (); ++ j) mu (i, j) = 3 * i + j; std::cout << ml << std::endl; save_smatrix (ml, filename.c_str()); symmetric_matrix ml2 (3, 3); load_smatrix (ml2, filename.c_str()); std::cout << ml2 << std::endl; std::cout << mu << std::endl; save_smatrix (mu, filename.c_str()); symmetric_matrix mu2 (3, 3); load_smatrix (mu2, filename.c_str()); std::cout << mu2 << std::endl; return 0; }