params.hpp
Go to the documentation of this file.
1 
7 #ifndef MLPACK_CORE_UTIL_PARAMS_HPP
8 #define MLPACK_CORE_UTIL_PARAMS_HPP
9 
10 //#include "forward.hpp"
11 #include "param_data.hpp"
12 #include "binding_details.hpp"
13 #include <map>
14 
15 namespace mlpack {
16 namespace util {
17 
22 class Params
23 {
24  public:
25  // Convenience typedef for function maps.
26  typedef std::map<std::string, std::map<std::string,
27  void (*)(ParamData&, const void*, void*)>> FunctionMapType;
28 
33  Params(const std::map<char, std::string>& aliases,
34  const std::map<std::string, ParamData>& parameters,
36  const std::string& bindingName,
37  const BindingDetails& doc);
38 
42  Params();
43 
49  bool Has(const std::string& identifier) const;
50 
57  template<typename T>
58  T& Get(const std::string& identifier);
59 
68  template<typename T>
69  std::string GetPrintable(const std::string& identifier);
70 
80  template<typename T>
81  T& GetRaw(const std::string& identifier);
82 
92  // TODO: it would be really nice to remove this! It's only used by MeanShift
93  // and KMeans bindings.
94  void MakeInPlaceCopy(const std::string& outputParamName,
95  const std::string& inputParamName);
96 
98  std::map<std::string, ParamData>& Parameters() { return parameters; }
100  std::map<char, std::string>& Aliases() { return aliases; }
101 
103  const std::string& BindingName() const { return bindingName; }
104 
106  const BindingDetails& Doc() const { return doc; }
107 
113  void SetPassed(const std::string& identifier);
114 
119  void CheckInputMatrices();
120 
121  private:
123  std::map<char, std::string> aliases;
125  std::map<std::string, ParamData> parameters;
126 
127  public:
133 
134  private:
136  std::string bindingName;
137 
139  BindingDetails doc;
140 
142  template<typename T>
143  void CheckInputMatrix(const T& matrix, const std::string& identifier);
144 };
145 
146 } // namespace util
147 } // namespace mlpack
148 
149 // Implementation intentionally not included.
150 
151 #endif
const BindingDetails & Doc() const
Get the binding details.
Definition: params.hpp:106
Linear algebra utility functions, generally performed on matrices or vectors.
void MakeInPlaceCopy(const std::string &outputParamName, const std::string &inputParamName)
Given two (matrix) parameters, ensure that the first is an in-place copy of the second.
std::map< char, std::string > & Aliases()
Get the map of aliases.
Definition: params.hpp:100
std::map< std::string, ParamData > & Parameters()
Get the map of parameters.
Definition: params.hpp:98
This structure holds all of the information about a single parameter, including its value (which is s...
Definition: param_data.hpp:38
std::map< std::string, std::map< std::string, void(*)(ParamData &, const void *, void *)> > FunctionMapType
Definition: params.hpp:27
T & Get(const std::string &identifier)
Get the value of type T found for the parameter specified by identifier.
std::string GetPrintable(const std::string &identifier)
Cast the given parameter of the given type to a short, printable std::string, for use in status messa...
bool Has(const std::string &identifier) const
Return true if the specified parameter was given.
void CheckInputMatrices()
Check all input matrices for NaN and inf values, and throw an exception if any are found...
Params()
Empty constructor.
FunctionMapType functionMap
Map for functions and types.
Definition: params.hpp:132
T & GetRaw(const std::string &identifier)
Get the raw value of the parameter before any processing that Get() might normally do...
The Params class holds all information about the parameters passed to a specific binding.
Definition: params.hpp:22
This structure holds all of the information about bindings documentation.
void SetPassed(const std::string &identifier)
Set the particular parameter as passed.
const std::string & BindingName() const
Get the binding name.
Definition: params.hpp:103