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 
73 template<typename eT>
74 struct ParameterType<arma::Col<eT>>
75 {
76  typedef std::string type;
77 };
78 
84 template<typename eT>
85 struct ParameterType<arma::Row<eT>>
86 {
87  typedef std::string type;
88 };
89 
93 template<typename eT, typename PolicyType>
94 struct ParameterType<std::tuple<mlpack::data::DatasetMapper<PolicyType>,
95  arma::Mat<eT>>>
96 {
97  typedef std::string type;
98 };
99 
112 struct ParamData
113 {
123  char alias;
125  bool isFlag;
130  bool required;
132  bool input;
135  bool loaded;
141  boost::any value;
145  boost::any mappedValue;
151  void (*outputFunction)(const ParamData&);
154  void (*printFunction)(const ParamData&);
156  std::string (*defaultFunction)(const ParamData&);
159  std::string (*stringTypeFunction)();
160 };
161 
166 template<typename T>
168  const std::string& identifier,
169  const typename boost::disable_if<arma::is_arma_type<T>>::type* = 0,
170  const typename boost::disable_if<data::HasSerialize<T>>::type* = 0,
171  const typename boost::disable_if<std::is_same<T,
172  std::tuple<mlpack::data::DatasetInfo, arma::mat>>>::type* = 0);
173 
175 template<typename T>
177  const std::string& identifier,
178  const typename boost::enable_if_c<
179  arma::is_arma_type<T>::value ||
180  std::is_same<T, std::tuple<mlpack::data::DatasetInfo,
181  arma::mat>>::value ||
182  data::HasSerialize<T>::value>::type* /* junk */ = 0);
183 
188 template<typename T>
189 T& HandleParameter(
191  util::ParamData& d,
192  const typename boost::disable_if<arma::is_arma_type<T>>::type* = 0,
193  const typename boost::disable_if<data::HasSerialize<T>>::type* = 0,
194  const typename boost::disable_if<std::is_same<T,
195  std::tuple<mlpack::data::DatasetInfo, arma::mat>>>::type* = 0);
196 
198 template<typename T>
199 T& HandleParameter(
201  util::ParamData& d,
202  const typename boost::enable_if<arma::is_arma_type<T>>::type* = 0);
203 
205 template<typename T>
206 T& HandleParameter(
208  util::ParamData& d,
209  const typename boost::enable_if<std::is_same<T,
210  std::tuple<mlpack::data::DatasetInfo, arma::mat>>>::type* = 0);
211 
213 template<typename T>
214 T& HandleParameter(
216  util::ParamData& d,
217  const typename boost::enable_if<data::HasSerialize<T>>::type* = 0);
218 
220 template<typename T>
223  util::ParamData& /* d */,
224  const typename boost::disable_if<arma::is_arma_type<T>>::type* = 0,
225  const typename boost::disable_if<data::HasSerialize<T>>::type* = 0,
226  const typename boost::disable_if<std::is_same<T,
227  std::tuple<data::DatasetInfo, arma::mat>>>::type* = 0)
228 {
229  return value;
230 }
231 
233 template<typename T>
235  typename util::ParameterType<T>::type& /* value */,
236  util::ParamData& d,
237  const typename boost::enable_if<arma::is_arma_type<T>>::type* = 0)
238 {
239  return *boost::any_cast<T>(&d.mappedValue);
240 }
241 
243 template<typename T>
245  typename util::ParameterType<T>::type& /* value */,
246  util::ParamData& d,
247  const typename boost::enable_if<data::HasSerialize<T>>::type* = 0)
248 {
249  return *boost::any_cast<T>(&d.mappedValue);
250 }
251 
253 template<typename T>
255  typename util::ParameterType<T>::type& /* value */,
256  util::ParamData& d,
257  const typename boost::enable_if<std::is_same<T,
258  std::tuple<data::DatasetInfo, arma::mat>>>::type* = 0)
259 {
260  return *boost::any_cast<T>(&d.mappedValue);
261 }
262 
263 } // namespace util
264 } // namespace mlpack
265 
267 #include "param_data_impl.hpp"
268 
269 #endif
char alias
Alias for this parameter.
Definition: param_data.hpp:123
std::string tname
Type information of this parameter.
Definition: param_data.hpp:121
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:132
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:118
bool noTranspose
True if this is a matrix that should not be transposed.
Definition: param_data.hpp:128
std::string boostName
The name of the parameter, as seen by boost::program_options.
Definition: param_data.hpp:147
bool isMappedString
If this is a matrix or model parameter, then boost::program_options will actually represent this as a...
Definition: param_data.hpp:138
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:221
This structure holds all of the information about a single parameter, including its value (which is s...
Definition: param_data.hpp:112
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:135
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:145
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:141
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:125
std::string name
Name of this parameter.
Definition: param_data.hpp:116
bool required
True if this option is required.
Definition: param_data.hpp:130