mlpack  1.0.12
save_restore_utility.hpp
Go to the documentation of this file.
1 
17 #ifndef __MLPACK_CORE_UTIL_SAVE_RESTORE_UTILITY_HPP
18 #define __MLPACK_CORE_UTIL_SAVE_RESTORE_UTILITY_HPP
19 
20 #include <mlpack/prereqs.hpp>
21 #include <list>
22 #include <map>
23 #include <sstream>
24 #include <string>
25 
26 #include <libxml/parser.h>
27 #include <libxml/tree.h>
28 
29 #include <boost/tokenizer.hpp>
30 
31 namespace mlpack {
32 namespace util {
33 
35 {
36  private:
40  std::map<std::string, std::string> parameters;
41 
45  void RecurseOnNodes(xmlNode* n);
46 
47  public:
49  ~SaveRestoreUtility() { parameters.clear(); }
50 
54  bool ReadFile(const std::string& filename);
55 
59  bool WriteFile(const std::string& filename);
60 
64  template<typename T>
65  T& LoadParameter(T& t, const std::string& name);
66 
70  template<typename T>
71  std::vector<T>& LoadParameter(std::vector<T>& v, const std::string& name);
72 
76  char LoadParameter(char c, const std::string& name);
77 
81  std::string LoadParameter(std::string& str, const std::string& name);
82 
86  arma::mat& LoadParameter(arma::mat& matrix, const std::string& name);
87 
91  template<typename T>
92  void SaveParameter(const T& t, const std::string& name);
93 
94 
95 
99  template<typename T>
100  void SaveParameter(const std::vector<T>& v, const std::string& name);
101 
105  void SaveParameter(const char c, const std::string& name);
106 
110  void SaveParameter(const arma::mat& mat, const std::string& name);
111 };
112 
114 template<>
115 arma::vec& SaveRestoreUtility::LoadParameter(arma::vec& t,
116  const std::string& name);
117 
119 template<>
120 void SaveRestoreUtility::SaveParameter(const arma::vec& t,
121  const std::string& name);
122 
123 }; /* namespace util */
124 }; /* namespace mlpack */
125 
126 // Include implementation.
127 #include "save_restore_utility_impl.hpp"
128 
129 #endif
void SaveParameter(const T &t, const std::string &name)
SaveParameter saves a parameter to the parameters map.
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: load.hpp:23
The core includes that mlpack expects; standard C++ includes and Armadillo.
void RecurseOnNodes(xmlNode *n)
RecurseOnNodes performs a depth first search of the XML tree.
T & LoadParameter(T &t, const std::string &name)
LoadParameter loads a parameter from the parameters map.
std::map< std::string, std::string > parameters
parameters contains a list of names and parameters in string form.
bool ReadFile(const std::string &filename)
ReadFile reads an XML tree from a file.
bool WriteFile(const std::string &filename)
WriteFile writes the XML tree to a file.