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 "param_data.hpp"
11 #include "binding_details.hpp"
12 
13 namespace mlpack {
14 namespace util {
15 
20 class Params
21 {
22  public:
23  // Convenience typedef for function maps.
24  typedef std::map<std::string, std::map<std::string,
25  void (*)(ParamData&, const void*, void*)>> FunctionMapType;
26 
31  Params(const std::map<char, std::string>& aliases,
32  const std::map<std::string, ParamData>& parameters,
34  const std::string& bindingName,
35  const BindingDetails& doc);
36 
40  Params();
41 
47  bool Has(const std::string& identifier) const;
48 
55  template<typename T>
56  T& Get(const std::string& identifier);
57 
66  template<typename T>
67  std::string GetPrintable(const std::string& identifier);
68 
78  template<typename T>
79  T& GetRaw(const std::string& identifier);
80 
90  // TODO: it would be really nice to remove this! It's only used by MeanShift
91  // and KMeans bindings.
92  void MakeInPlaceCopy(const std::string& outputParamName,
93  const std::string& inputParamName);
94 
96  std::map<std::string, ParamData>& Parameters() { return parameters; }
98  std::map<char, std::string>& Aliases() { return aliases; }
99 
101  const std::string& BindingName() const { return bindingName; }
102 
104  const BindingDetails& Doc() const { return doc; }
105 
111  void SetPassed(const std::string& identifier);
112 
117  void CheckInputMatrices();
118 
119  private:
121  std::map<char, std::string> aliases;
123  std::map<std::string, ParamData> parameters;
124 
125  public:
131 
132  private:
134  std::string bindingName;
135 
137  BindingDetails doc;
138 
140  template<typename T>
141  void CheckInputMatrix(const T& matrix, const std::string& identifier);
142 };
143 
144 } // namespace util
145 } // namespace mlpack
146 
147 // Include implementation.
148 #include "params_impl.hpp"
149 
150 #endif
const BindingDetails & Doc() const
Get the binding details.
Definition: params.hpp:104
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:98
std::map< std::string, ParamData > & Parameters()
Get the map of parameters.
Definition: params.hpp:96
This structure holds all of the information about a single parameter, including its value (which is s...
Definition: param_data.hpp:52
std::map< std::string, std::map< std::string, void(*)(ParamData &, const void *, void *)> > FunctionMapType
Definition: params.hpp:25
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:130
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:20
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:101