param.hpp
Go to the documentation of this file.
1 
15 #ifndef MLPACK_CORE_UTIL_PARAM_HPP
16 #define MLPACK_CORE_UTIL_PARAM_HPP
17 
18 #include "forward.hpp"
19 
25 // These are ugly, but necessary utility functions we must use to generate a
26 // unique identifier inside of the PARAM() module.
27 #define JOIN(x, y) JOIN_AGAIN(x, y)
28 #define JOIN_AGAIN(x, y) x ## y
29 #define STRINGIFY(x) STRINGIFY_AGAIN(x)
30 #define STRINGIFY_AGAIN(x) #x
31 
38 #define BINDING_FUNCTION(...) BINDING_NAME(__VA_ARGS__)
39 
53 #ifdef __COUNTER__
54  #define BINDING_USER_NAME(NAME) static \
55  mlpack::util::BindingName \
56  JOIN(io_bindingusername_dummy_object, __COUNTER__) = \
57  mlpack::util::BindingName( \
58  STRINGIFY(BINDING_NAME), NAME);
59 #else
60  #define BINDING_USER_NAME(NAME) static \
61  mlpack::util::BindingName \
62  JOIN(JOIN(io_bindingusername_dummy_object, __LINE__), opt) = \
63  mlpack::util::BindingName( \
64  STRINGIFY(BINDING_NAME), NAME);
65 #endif
66 
82 #ifdef __COUNTER__
83  #define BINDING_SHORT_DESC(SHORT_DESC) static \
84  mlpack::util::ShortDescription \
85  JOIN(io_programshort_desc_dummy_object, __COUNTER__) = \
86  mlpack::util::ShortDescription( \
87  STRINGIFY(BINDING_NAME), SHORT_DESC);
88 #else
89  #define BINDING_SHORT_DESC(SHORT_DESC) static \
90  mlpack::util::ShortDescription \
91  JOIN(JOIN(io_programshort_desc_dummy_object, __LINE__), opt) = \
92  mlpack::util::ShortDescription( \
93  STRINGIFY(BINDING_NAME), SHORT_DESC);
94 #endif
95 
116 #ifdef __COUNTER__
117  #define BINDING_LONG_DESC(LONG_DESC) static \
118  mlpack::util::LongDescription \
119  JOIN(io_programlong_desc_dummy_object, __COUNTER__) = \
120  mlpack::util::LongDescription( \
121  STRINGIFY(BINDING_NAME), []() { return std::string(LONG_DESC); });
122 #else
123  #define BINDING_LONG_DESC(LONG_DESC) static \
124  mlpack::util::LongDescription \
125  JOIN(JOIN(io_programlong_desc_dummy_object, __LINE__), opt) = \
126  mlpack::util::LongDescription( \
127  STRINGIFY(BINDING_NAME), []() { return std::string(LONG_DESC); });
128 #endif
129 
147 #ifdef __COUNTER__
148  #define BINDING_EXAMPLE(EXAMPLE) static \
149  mlpack::util::Example \
150  JOIN(io_programexample_dummy_object_, __COUNTER__) = \
151  mlpack::util::Example( \
152  STRINGIFY(BINDING_NAME), []() { return(std::string(EXAMPLE)); });
153 #else
154  #define BINDING_EXAMPLE(EXAMPLE) static \
155  mlpack::util::Example \
156  JOIN(JOIN(io_programexample_dummy_object_, __LINE__), opt) = \
157  mlpack::util::Example( \
158  STRINGIFY(BINDING_NAME), []() { return(std::string(EXAMPLE)); });
159 #endif
160 
184 #ifdef __COUNTER__
185  #define BINDING_SEE_ALSO(DESCRIPTION, LINK) static \
186  mlpack::util::SeeAlso \
187  JOIN(io_programsee_also_dummy_object_, __COUNTER__) = \
188  mlpack::util::SeeAlso(STRINGIFY(BINDING_NAME), DESCRIPTION, LINK);
189 #else
190  #define BINDING_SEE_ALSO(DESCRIPTION, LINK) static \
191  mlpack::util::SeeAlso \
192  JOIN(JOIN(io_programsee_also_dummy_object_, __LINE__), opt) = \
193  mlpack::util::SeeAlso(STRINGIFY(BINDING_NAME), DESCRIPTION, LINK);
194 #endif
195 
216 #define PARAM_FLAG(ID, DESC, ALIAS) \
217  PARAM_IN(bool, ID, DESC, ALIAS, false, false);
218 
244 #define PARAM_INT_IN(ID, DESC, ALIAS, DEF) \
245  PARAM_IN(int, ID, DESC, ALIAS, DEF, false)
246 
275 #define PARAM_INT_OUT(ID, DESC) \
276  PARAM_OUT(int, ID, DESC, "", 0, false)
277 
302 #define PARAM_DOUBLE_IN(ID, DESC, ALIAS, DEF) \
303  PARAM_IN(double, ID, DESC, ALIAS, DEF, false)
304 
333 #define PARAM_DOUBLE_OUT(ID, DESC) \
334  PARAM_OUT(double, ID, DESC, "", 0.0, false)
335 
362 #define PARAM_STRING_IN(ID, DESC, ALIAS, DEF) \
363  PARAM_IN(std::string, ID, DESC, ALIAS, DEF, false)
364 
394 #define PARAM_STRING_OUT(ID, DESC, ALIAS) \
395  PARAM_OUT(std::string, ID, DESC, ALIAS, "", false)
396 
422 #define PARAM_MATRIX_IN(ID, DESC, ALIAS) \
423  PARAM_MATRIX(ID, DESC, ALIAS, false, true, true)
424 
450 #define PARAM_MATRIX_IN_REQ(ID, DESC, ALIAS) \
451  PARAM_MATRIX(ID, DESC, ALIAS, true, true, true)
452 
483 #define PARAM_MATRIX_OUT(ID, DESC, ALIAS) \
484  PARAM_MATRIX(ID, DESC, ALIAS, false, true, false)
485 
512 #define PARAM_TMATRIX_IN(ID, DESC, ALIAS) \
513  PARAM_MATRIX(ID, DESC, ALIAS, false, false, true)
514 
542 #define PARAM_TMATRIX_IN_REQ(ID, DESC, ALIAS) \
543  PARAM_MATRIX(ID, DESC, ALIAS, true, false, true)
544 
577 #define PARAM_TMATRIX_OUT(ID, DESC, ALIAS) \
578  PARAM_MATRIX(ID, DESC, ALIAS, false, false, false)
579 
605 #define PARAM_UMATRIX_IN(ID, DESC, ALIAS) \
606  PARAM_UMATRIX(ID, DESC, ALIAS, false, true, true)
607 
634 #define PARAM_UMATRIX_IN_REQ(ID, DESC, ALIAS) \
635  PARAM_UMATRIX(ID, DESC, ALIAS, true, true, true)
636 
668 #define PARAM_UMATRIX_OUT(ID, DESC, ALIAS) \
669  PARAM_UMATRIX(ID, DESC, ALIAS, false, true, false)
670 
671 
697 #define PARAM_COL_IN(ID, DESC, ALIAS) \
698  PARAM_COL(ID, DESC, ALIAS, false, true, true)
699 
725 #define PARAM_COL_IN_REQ(ID, DESC, ALIAS) \
726  PARAM_COL(ID, DESC, ALIAS, true, true, true)
727 
753 #define PARAM_ROW_IN(ID, DESC, ALIAS) \
754  PARAM_ROW(ID, DESC, ALIAS, false, true, true)
755 
781 #define PARAM_UCOL_IN(ID, DESC, ALIAS) \
782  PARAM_UCOL(ID, DESC, ALIAS, false, true, true)
783 
810 #define PARAM_UROW_IN(ID, DESC, ALIAS) \
811  PARAM_UROW(ID, DESC, ALIAS, false, true, true)
812 
843 #define PARAM_COL_OUT(ID, DESC, ALIAS) \
844  PARAM_COL(ID, DESC, ALIAS, false, true, false)
845 
876 #define PARAM_ROW_OUT(ID, DESC, ALIAS) \
877  PARAM_ROW(ID, DESC, ALIAS, false, true, false)
878 
909 #define PARAM_UCOL_OUT(ID, DESC, ALIAS) \
910  PARAM_UCOL(ID, DESC, ALIAS, false, true, false)
911 
942 #define PARAM_UROW_OUT(ID, DESC, ALIAS) \
943  PARAM_UROW(ID, DESC, ALIAS, false, true, false)
944 
969 #define PARAM_VECTOR_IN(T, ID, DESC, ALIAS) \
970  PARAM_IN(std::vector<T>, ID, DESC, ALIAS, std::vector<T>(), false)
971 
1003 #define PARAM_VECTOR_OUT(T, ID, DESC, ALIAS) \
1004  PARAM_OUT(std::vector<T>, ID, DESC, ALIAS, std::vector<T>(), false)
1005 
1043 #define TUPLE_TYPE std::tuple<mlpack::data::DatasetInfo, arma::mat>
1044 #define PARAM_MATRIX_AND_INFO_IN(ID, DESC, ALIAS) \
1045  PARAM(TUPLE_TYPE, ID, DESC, ALIAS, \
1046  "std::tuple<mlpack::data::DatasetInfo, arma::mat>", false, true, true, \
1047  TUPLE_TYPE())
1048 
1077 #define PARAM_MODEL_IN(TYPE, ID, DESC, ALIAS) \
1078  PARAM_MODEL(TYPE, ID, DESC, ALIAS, false, true)
1079 
1108 #define PARAM_MODEL_IN_REQ(TYPE, ID, DESC, ALIAS) \
1109  PARAM_MODEL(TYPE, ID, DESC, ALIAS, true, true)
1110 
1133 #define PARAM_MODEL_OUT(TYPE, ID, DESC, ALIAS) \
1134  PARAM_MODEL(TYPE, ID, DESC, ALIAS, false, false)
1135 
1158 #define PARAM_INT_IN_REQ(ID, DESC, ALIAS) \
1159  PARAM_IN(int, ID, DESC, ALIAS, 0, true)
1160 
1183 #define PARAM_DOUBLE_IN_REQ(ID, DESC, ALIAS) \
1184  PARAM_IN(double, ID, DESC, ALIAS, 0.0, true)
1185 
1208 #define PARAM_STRING_IN_REQ(ID, DESC, ALIAS) \
1209  PARAM_IN(std::string, ID, DESC, ALIAS, "", true)
1210 
1235 #define PARAM_VECTOR_IN_REQ(T, ID, DESC, ALIAS) \
1236  PARAM_IN(std::vector<T>, ID, DESC, ALIAS, std::vector<T>(), true);
1237 
1241 #define PARAM_IN(T, ID, DESC, ALIAS, DEF, REQ) \
1242  PARAM(T, ID, DESC, ALIAS, #T, REQ, true, false, DEF);
1243 
1244 #define PARAM_OUT(T, ID, DESC, ALIAS, DEF, REQ) \
1245  PARAM(T, ID, DESC, ALIAS, #T, REQ, false, false, DEF);
1246 
1247 #define PARAM_MATRIX(ID, DESC, ALIAS, REQ, TRANS, IN) \
1248  PARAM(arma::mat, ID, DESC, ALIAS, "arma::mat", REQ, IN, \
1249  TRANS, arma::mat());
1250 
1251 #define PARAM_UMATRIX(ID, DESC, ALIAS, REQ, TRANS, IN) \
1252  PARAM(arma::Mat<size_t>, ID, DESC, ALIAS, "arma::Mat<size_t>", \
1253  REQ, IN, TRANS, arma::Mat<size_t>());
1254 
1255 #define PARAM_COL(ID, DESC, ALIAS, REQ, TRANS, IN) \
1256  PARAM(arma::vec, ID, DESC, ALIAS, "arma::vec", REQ, IN, TRANS, \
1257  arma::vec());
1258 
1259 #define PARAM_UCOL(ID, DESC, ALIAS, REQ, TRANS, IN) \
1260  PARAM(arma::Col<size_t>, ID, DESC, ALIAS, "arma::Col<size_t>", \
1261  REQ, IN, TRANS, arma::Col<size_t>());
1262 
1263 #define PARAM_ROW(ID, DESC, ALIAS, REQ, TRANS, IN) \
1264  PARAM(arma::rowvec, ID, DESC, ALIAS, "arma::rowvec", REQ, IN, \
1265  TRANS, arma::rowvec());
1266 
1267 #define PARAM_UROW(ID, DESC, ALIAS, REQ, TRANS, IN) \
1268  PARAM(arma::Row<size_t>, ID, DESC, ALIAS, "arma::Row<size_t>", \
1269  REQ, IN, TRANS, arma::Row<size_t>());
1270 
1287 #ifdef __COUNTER__
1288  #define PARAM(T, ID, DESC, ALIAS, NAME, REQ, IN, TRANS, DEF) \
1289  static mlpack::util::Option<T> \
1290  JOIN(io_option_dummy_object_in_, __COUNTER__) \
1291  (DEF, ID, DESC, ALIAS, NAME, REQ, IN, !TRANS, STRINGIFY(BINDING_NAME));
1292 
1293  #define PARAM_GLOBAL(T, ID, DESC, ALIAS, NAME, REQ, IN, TRANS, DEF) \
1294  static mlpack::util::Option<T> \
1295  JOIN(io_option_global_dummy_object_in_, __COUNTER__) \
1296  (DEF, ID, DESC, ALIAS, NAME, REQ, IN, !TRANS, "");
1297 
1298  // There are no uses of required models, so that is not an option to this
1299  // macro (it would be easy to add).
1300  #define PARAM_MODEL(TYPE, ID, DESC, ALIAS, REQ, IN) \
1301  static mlpack::util::Option<TYPE*> \
1302  JOIN(io_option_dummy_model_, __COUNTER__) \
1303  (nullptr, ID, DESC, ALIAS, #TYPE, REQ, IN, false, \
1304  STRINGIFY(BINDING_NAME));
1305 #else
1306  // We have to do some really bizarre stuff since __COUNTER__ isn't defined. I
1307  // don't think we can absolutely guarantee success, but it should be "good
1308  // enough". We use the __LINE__ macro and the type of the parameter to try
1309  // and get a good guess at something unique.
1310  #define PARAM(T, ID, DESC, ALIAS, NAME, REQ, IN, TRANS, DEF) \
1311  static mlpack::util::Option<T> \
1312  JOIN(JOIN(io_option_dummy_object_in_, __LINE__), opt) \
1313  (DEF, ID, DESC, ALIAS, NAME, REQ, IN, !TRANS, STRINGIFY(BINDING_NAME));
1314 
1315  #define PARAM_GLOBAL(T, ID, DESC, ALIAS, NAME, REQ, IN, TRANS, DEF) \
1316  static mlpack::util::Option<T> \
1317  JOIN(JOIN(io_option_global_dummy_object_in_, __LINE__), opt) \
1318  (DEF, ID, DESC, ALIAS, NAME, REQ, IN, !TRANS, "");
1319 
1320  #define PARAM_MODEL(TYPE, ID, DESC, ALIAS, REQ, IN) \
1321  static mlpack::util::Option<TYPE*> \
1322  JOIN(JOIN(io_option_dummy_object_model_, __LINE__), opt) \
1323  (nullptr, ID, DESC, ALIAS, #TYPE, REQ, IN, false, \
1324  STRINGIFY(BINDING_NAME));
1325 #endif
1326 
1327 #endif