mlpack  master
param_data.hpp
Go to the documentation of this file.
1 
8 #ifndef MLPACK_CORE_UTIL_PARAM_DATA_HPP
9 #define MLPACK_CORE_UTIL_PARAM_DATA_HPP
10 
11 #include <mlpack/prereqs.hpp>
12 
13 #include <boost/any.hpp>
14 
18 #define TYPENAME(x) (std::string(typeid(x).name()))
19 
20 namespace mlpack {
21 namespace util {
22 
24 template<typename T>
25 struct IsStdVector { const static bool value = false; };
26 
28 template<typename T, typename A>
29 struct IsStdVector<std::vector<T, A>> { const static bool value = true; };
30 
31 // Default: HasSerialize = false.
32 template<bool HasSerialize, typename T>
34 {
35  typedef T type;
36 };
37 
38 // If we have a Serialize() function, then the type is a string.
39 template<typename T>
40 struct ParameterTypeDeducer<true, T>
41 {
42  typedef std::string type;
43 };
44 
50 template<typename T>
52 {
55 };
56 
62 template<typename eT>
63 struct ParameterType<arma::Mat<eT>>
64 {
65  typedef std::string type;
66 };
67 
71 template<typename eT, typename PolicyType>
72 struct ParameterType<std::tuple<mlpack::data::DatasetMapper<PolicyType>,
73  arma::Mat<eT>>>
74 {
75  typedef std::string type;
76 };
77 
90 struct ParamData
91 {
101  char alias;
103  bool isFlag;
108  bool required;
110  bool input;
113  bool loaded;
119  boost::any value;
123  boost::any mappedValue;
129  void (*outputFunction)(const ParamData&);
132  void (*printFunction)(const ParamData&);
134  std::string (*defaultFunction)(const ParamData&);
137  std::string (*stringTypeFunction)();
138 };
139 
144 template<typename T>
146  const std::string& identifier,
147  const typename boost::disable_if<arma::is_arma_type<T>>::type* = 0,
148  const typename boost::disable_if<data::HasSerialize<T>>::type* = 0,
149  const typename boost::disable_if<std::is_same<T,
150  std::tuple<mlpack::data::DatasetInfo, arma::mat>>>::type* = 0);
151 
153 template<typename T>
155  const std::string& identifier,
156  const typename boost::enable_if_c<
157  arma::is_arma_type<T>::value ||
158  std::is_same<T, std::tuple<mlpack::data::DatasetInfo,
159  arma::mat>>::value ||
160  data::HasSerialize<T>::value>::type* /* junk */ = 0);
161 
166 template<typename T>
167 T& HandleParameter(
169  util::ParamData& d,
170  const typename boost::disable_if<arma::is_arma_type<T>>::type* = 0,
171  const typename boost::disable_if<data::HasSerialize<T>>::type* = 0,
172  const typename boost::disable_if<std::is_same<T,
173  std::tuple<mlpack::data::DatasetInfo, arma::mat>>>::type* = 0);
174 
176 template<typename T>
177 T& HandleParameter(
179  util::ParamData& d,
180  const typename boost::enable_if<arma::is_arma_type<T>>::type* = 0);
181 
183 template<typename T>
184 T& HandleParameter(
186  util::ParamData& d,
187  const typename boost::enable_if<std::is_same<T,
188  std::tuple<mlpack::data::DatasetInfo, arma::mat>>>::type* = 0);
189 
191 template<typename T>
192 T& HandleParameter(
194  util::ParamData& d,
195  const typename boost::enable_if<data::HasSerialize<T>>::type* = 0);
196 
198 template<typename T>
201  util::ParamData& /* d */,
202  const typename boost::disable_if<arma::is_arma_type<T>>::type* = 0,
203  const typename boost::disable_if<data::HasSerialize<T>>::type* = 0,
204  const typename boost::disable_if<std::is_same<T,
205  std::tuple<data::DatasetInfo, arma::mat>>>::type* = 0)
206 {
207  return value;
208 }
209 
211 template<typename T>
213  typename util::ParameterType<T>::type& /* value */,
214  util::ParamData& d,
215  const typename boost::enable_if<arma::is_arma_type<T>>::type* = 0)
216 {
217  return *boost::any_cast<T>(&d.mappedValue);
218 }
219 
221 template<typename T>
223  typename util::ParameterType<T>::type& /* value */,
224  util::ParamData& d,
225  const typename boost::enable_if<data::HasSerialize<T>>::type* = 0)
226 {
227  return *boost::any_cast<T>(&d.mappedValue);
228 }
229 
231 template<typename T>
233  typename util::ParameterType<T>::type& /* value */,
234  util::ParamData& d,
235  const typename boost::enable_if<std::is_same<T,
236  std::tuple<data::DatasetInfo, arma::mat>>>::type* = 0)
237 {
238  return *boost::any_cast<T>(&d.mappedValue);
239 }
240 
241 } // namespace util
242 } // namespace mlpack
243 
245 #include "param_data_impl.hpp"
246 
247 #endif
char alias
Alias for this parameter.
Definition: param_data.hpp:101
std::string tname
Type information of this parameter.
Definition: param_data.hpp:99
Auxiliary information for a dataset, including mappings to/from strings and the datatype of each dime...
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: binarize.hpp:18
bool input
True if this option is an input option (otherwise, it is output).
Definition: param_data.hpp:110
The core includes that mlpack expects; standard C++ includes and Armadillo.
Definition: prereqs.hpp:56
std::string desc
Description of this parameter, if any.
Definition: param_data.hpp:96
bool noTranspose
True if this is a matrix that should not be transposed.
Definition: param_data.hpp:106
std::string boostName
The name of the parameter, as seen by boost::program_options.
Definition: param_data.hpp:125
bool isMappedString
If this is a matrix or model parameter, then boost::program_options will actually represent this as a...
Definition: param_data.hpp:116
T & HandleParameter(typename util::ParameterType< T >::type &value, util::ParamData &d, const typename boost::disable_if< arma::is_arma_type< T >>::type *=0, const typename boost::disable_if< data::HasSerialize< T >>::type *=0, const typename boost::disable_if< std::is_same< T, std::tuple< mlpack::data::DatasetInfo, arma::mat >>>::type *=0)
If needed, map &#39;trueValue&#39; to the right type and return it.
std::string MapParameterName(const std::string &identifier, const typename boost::disable_if< arma::is_arma_type< T >>::type *=0, const typename boost::disable_if< data::HasSerialize< T >>::type *=0, const typename boost::disable_if< std::is_same< T, std::tuple< mlpack::data::DatasetInfo, arma::mat >>>::type *=0)
If needed, map the parameter name to the name that is used by boost.
static const bool value
Definition: param_data.hpp:25
T & HandleRawParameter(typename util::ParameterType< T >::type &value, util::ParamData &, const typename boost::disable_if< arma::is_arma_type< T >>::type *=0, const typename boost::disable_if< data::HasSerialize< T >>::type *=0, const typename boost::disable_if< std::is_same< T, std::tuple< data::DatasetInfo, arma::mat >>>::type *=0)
This will just return the value.
Definition: param_data.hpp:199
This structure holds all of the information about a single parameter, including its value (which is s...
Definition: param_data.hpp:90
bool loaded
If this is an input parameter that needs extra loading, this indicates whether or not it has been loa...
Definition: param_data.hpp:113
boost::any mappedValue
The value that the user interacts with, if the type is different than the type of the parameter...
Definition: param_data.hpp:123
Metaprogramming structure for vector detection.
Definition: param_data.hpp:25
ParameterTypeDeducer< data::HasSerialize< T >::value, T >::type type
Definition: param_data.hpp:54
Utility struct to return the type that boost::program_options should accept for a given input type...
Definition: param_data.hpp:51
boost::any value
The actual value that is held, as passed from the user (so the type could be different than the type ...
Definition: param_data.hpp:119
test cpp RESULT_VARIABLE MEX_RESULT_TRASH OUTPUT_VARIABLE MEX_OUTPUT ERROR_VARIABLE MEX_ERROR_TRASH string(REGEX MATCH"Warning: You are using"MEX_WARNING"${MEX_OUTPUT}") if(MEX_WARNING) string(REGEX REPLACE".*using [a-zA-Z]* version \"([0-9.]*)[^\"]*\".*""\\1"OTHER_COMPILER_VERSION"$
Definition: CMakeLists.txt:18
bool isFlag
True if the wasPassed value should not be ignored.
Definition: param_data.hpp:103
std::string name
Name of this parameter.
Definition: param_data.hpp:94
bool required
True if this option is required.
Definition: param_data.hpp:108