serialization.hpp
Go to the documentation of this file.
1 
12 #ifndef MLPACK_BINDINGS_PYTHON_MLPACK_SERIALIZATION_HPP
13 #define MLPACK_BINDINGS_PYTHON_MLPACK_SERIALIZATION_HPP
14 
15 #include <mlpack/core.hpp>
16 
17 namespace mlpack {
18 namespace bindings {
19 namespace python {
20 
21 template<typename T>
22 std::string SerializeOut(T* t, const std::string& name)
23 {
24  std::ostringstream oss;
25  {
26  cereal::BinaryOutputArchive b(oss);
27 
28  b(cereal::make_nvp(name.c_str(), *t));
29  }
30  return oss.str();
31 }
32 
33 template<typename T>
34 void SerializeIn(T* t, const std::string& str, const std::string& name)
35 {
36  std::istringstream iss(str);
37  cereal::BinaryInputArchive b(iss);
38  b(cereal::make_nvp(name.c_str(), *t));
39 }
40 
41 template<typename T>
42 std::string SerializeOutJSON(T* t, const std::string& name)
43 {
44  std::ostringstream oss;
45  {
46  cereal::JSONOutputArchive b(oss);
47 
48  b(cereal::make_nvp(name.c_str(), *t));
49  }
50  return oss.str();
51 }
52 
53 template<typename T>
54 void SerializeInJSON(T* t, const std::string& str, const std::string& name)
55 {
56  std::istringstream iss(str);
57  cereal::JSONInputArchive b(iss);
58  b(cereal::make_nvp(name.c_str(), *t));
59 }
60 
61 } // namespace python
62 } // namespace bindings
63 } // namespace mlpack
64 
65 #endif
Linear algebra utility functions, generally performed on matrices or vectors.
std::string SerializeOutJSON(T *t, const std::string &name)
python
Definition: CMakeLists.txt:7
Include all of the base components required to write mlpack methods, and the main mlpack Doxygen docu...
std::string SerializeOut(T *t, const std::string &name)
void SerializeInJSON(T *t, const std::string &str, const std::string &name)
void SerializeIn(T *t, const std::string &str, const std::string &name)