1 /**
2  * @file core/util/param.hpp
3  * @author Matthew Amidon
4  * @author Ryan Curtin
5  *
6  * Definition of PARAM_*_IN() and PARAM_*_OUT() macros, as well as the
7  * Documentation related macro, which are used to define input and output
8  * parameters of command-line programs and bindings to other languages.
9  *
10  * mlpack is free software; you may redistribute it and/or modify it under the
11  * terms of the 3-clause BSD license.  You should have received a copy of the
12  * 3-clause BSD license along with mlpack.  If not, see
13  * http://www.opensource.org/licenses/BSD-3-Clause for more information.
14  */
15 #ifndef MLPACK_CORE_UTIL_PARAM_HPP
16 #define MLPACK_CORE_UTIL_PARAM_HPP
17 
18 // Required forward declarations.
19 namespace mlpack {
20 namespace data {
21 
22 class IncrementPolicy;
23 
24 template<typename PolicyType, typename InputType>
25 class DatasetMapper;
26 
27 using DatasetInfo = DatasetMapper<IncrementPolicy, std::string>;
28 
29 } // namespace data
30 } // namespace mlpack
31 
32 /**
33  * @cond
34  * Don't document internal macros.
35  */
36 
37 // These are ugly, but necessary utility functions we must use to generate a
38 // unique identifier inside of the PARAM() module.
39 #define JOIN(x, y) JOIN_AGAIN(x, y)
40 #define JOIN_AGAIN(x, y) x ## y
41 
42 /** @endcond */
43 
44 /**
45  * Specify the program name of a binding.  Only one instance of this macro
46  * should be present in your program!  Therefore, use it in the main.cpp
47  * (or corresponding binding) in your program.
48  *
49  * @see mlpack::IO, PARAM_FLAG(), PARAM_INT_IN(), PARAM_DOUBLE_IN(),
50  * PARAM_STRING_IN(), PARAM_VECTOR_IN(), PARAM_INT_OUT(), PARAM_DOUBLE_OUT(),
51  * PARAM_VECTOR_OUT(), PARAM_INT_IN_REQ(), PARAM_DOUBLE_IN_REQ(),
52  * PARAM_STRING_IN_REQ(), PARAM_VECTOR_IN_REQ(), PARAM_INT_OUT_REQ(),
53  * PARAM_DOUBLE_OUT_REQ(), PARAM_VECTOR_OUT_REQ(), PARAM_STRING_OUT_REQ().
54  *
55  * @param NAME Short string representing the name of the program.
56  */
57 #define BINDING_NAME(NAME) static \
58     mlpack::util::ProgramName \
59     io_programname_dummy_object = mlpack::util::ProgramName(NAME);
60 
61 /**
62  * Specify the short description of a binding.  Only one instance of this macro
63  * should be present in your program!  Therefore, use it in the main.cpp
64  * (or corresponding binding) in your program.
65  *
66  * @see mlpack::IO, PARAM_FLAG(), PARAM_INT_IN(), PARAM_DOUBLE_IN(),
67  * PARAM_STRING_IN(), PARAM_VECTOR_IN(), PARAM_INT_OUT(), PARAM_DOUBLE_OUT(),
68  * PARAM_VECTOR_OUT(), PARAM_INT_IN_REQ(), PARAM_DOUBLE_IN_REQ(),
69  * PARAM_STRING_IN_REQ(), PARAM_VECTOR_IN_REQ(), PARAM_INT_OUT_REQ(),
70  * PARAM_DOUBLE_OUT_REQ(), PARAM_VECTOR_OUT_REQ(), PARAM_STRING_OUT_REQ().
71  *
72  * @param SHORT_DESC Short two-sentence description of the program; it should
73  *     describe what the program implements and does, and a quick overview of
74  *     how it can be used and what it should be used for.
75  */
76 #define BINDING_SHORT_DESC(SHORT_DESC) static \
77     mlpack::util::ShortDescription \
78     io_programshort_desc_dummy_object = mlpack::util::ShortDescription( \
79     SHORT_DESC);
80 
81 /**
82  * Specify the long description of a binding.  Only one instance of this macro
83  * present in your program!  Therefore, use it in the main.cpp
84  * (or corresponding binding) in your program.
85  *
86  * @see mlpack::IO, PARAM_FLAG(), PARAM_INT_IN(), PARAM_DOUBLE_IN(),
87  * PARAM_STRING_IN(), PARAM_VECTOR_IN(), PARAM_INT_OUT(), PARAM_DOUBLE_OUT(),
88  * PARAM_VECTOR_OUT(), PARAM_INT_IN_REQ(), PARAM_DOUBLE_IN_REQ(),
89  * PARAM_STRING_IN_REQ(), PARAM_VECTOR_IN_REQ(), PARAM_INT_OUT_REQ(),
90  * PARAM_DOUBLE_OUT_REQ(), PARAM_VECTOR_OUT_REQ(), PARAM_STRING_OUT_REQ().
91  *
92  * @param LONG_DESC Long string describing what the program does. Newlines
93  *     should not be used here; this is taken care of by IO (however, you
94  *     can explicitly specify newlines to denote new paragraphs).  You can
95  *     also use printing macros like PRINT_PARAM_STRING(), PRINT_DATASET(),
96  *     and others.
97  */
98 #define BINDING_LONG_DESC(LONG_DESC) static \
99     mlpack::util::LongDescription \
100     io_programlong_desc_dummy_object = mlpack::util::LongDescription( \
101     []() { return std::string(LONG_DESC); });
102 
103 /**
104  * Specify the example of a binding.  Mutiple instance of this macro can be
105  * present in your program!  Therefore, use it in the main.cpp
106  * (or corresponding binding) in your program.
107  *
108  * @see mlpack::IO, PARAM_FLAG(), PARAM_INT_IN(), PARAM_DOUBLE_IN(),
109  * PARAM_STRING_IN(), PARAM_VECTOR_IN(), PARAM_INT_OUT(), PARAM_DOUBLE_OUT(),
110  * PARAM_VECTOR_OUT(), PARAM_INT_IN_REQ(), PARAM_DOUBLE_IN_REQ(),
111  * PARAM_STRING_IN_REQ(), PARAM_VECTOR_IN_REQ(), PARAM_INT_OUT_REQ(),
112  * PARAM_DOUBLE_OUT_REQ(), PARAM_VECTOR_OUT_REQ(), PARAM_STRING_OUT_REQ().
113  *
114  * @param EXAMPLE Long string describing a simple usage example.. Newlines
115  *     should not be used here; this is taken care of by IO (however, you
116  *     can explicitly specify newlines to denote new paragraphs).  You can
117  *     also use printing macros like PRINT_CALL(), PRINT_DATASET(),
118  *     and others.
119  */
120 #ifdef __COUNTER__
121   #define BINDING_EXAMPLE(EXAMPLE) static \
122       mlpack::util::Example \
123       JOIN(io_programexample_dummy_object_, __COUNTER__) = \
124       mlpack::util::Example( \
125       []() { return(std::string(EXAMPLE)); });
126 #else
127   #define BINDING_EXAMPLE(EXAMPLE) static \
128       mlpack::util::Example \
129       JOIN(JOIN(io_programexample_dummy_object_, __LINE__), opt) = \
130       mlpack::util::Example( \
131       []() { return(std::string(EXAMPLE)); });
132 #endif
133 
134 /**
135  * Specify the see-also of a binding.  Mutiple instance of this macro can be
136  * present in your program!  Therefore, use it in the main.cpp
137  * (or corresponding binding) in your program.
138  *
139  * @see mlpack::IO, PARAM_FLAG(), PARAM_INT_IN(), PARAM_DOUBLE_IN(),
140  * PARAM_STRING_IN(), PARAM_VECTOR_IN(), PARAM_INT_OUT(), PARAM_DOUBLE_OUT(),
141  * PARAM_VECTOR_OUT(), PARAM_INT_IN_REQ(), PARAM_DOUBLE_IN_REQ(),
142  * PARAM_STRING_IN_REQ(), PARAM_VECTOR_IN_REQ(), PARAM_INT_OUT_REQ(),
143  * PARAM_DOUBLE_OUT_REQ(), PARAM_VECTOR_OUT_REQ(), PARAM_STRING_OUT_REQ().
144  *
145  * Provide a link for a binding's "see also" documentation section, which is
146  * primarily (but not necessarily exclusively) used by the Markdown bindings
147  * This link can be specified by calling SEE_ALSO("description", "link"), where
148  * "description" is the description of the link and "link" may be one of the
149  * following:
150  *
151  * - A direct URL, starting with http:// or https://.
152  * - A page anchor for documentation, referencing another binding by its CMake
153  *      binding name, i.e. "#knn".
154  * - A link to a Doxygen page, using the mangled Doxygen name after a
155  *      '\@doxygen/', i.e., "@doxygen/mlpack1_1_adaboost1_1_AdaBoost".
156  */
157 #ifdef __COUNTER__
158   #define BINDING_SEE_ALSO(DESCRIPTION, LINK) static \
159       mlpack::util::SeeAlso \
160       JOIN(io_programsee_also_dummy_object_, __COUNTER__) = \
161       mlpack::util::SeeAlso(DESCRIPTION, LINK);
162 #else
163   #define BINDING_SEE_ALSO(DESCRIPTION, LINK) static \
164       mlpack::util::SeeAlso \
165       JOIN(JOIN(io_programsee_also_dummy_object_, __LINE__), opt) = \
166       mlpack::util::SeeAlso(DESCRIPTION, LINK);
167 #endif
168 
169 /**
170  * Define a flag parameter.
171  *
172  * @param ID Name of the parameter.
173  * @param DESC Quick description of the parameter (1-2 sentences).  Don't use
174  *      printing macros like PRINT_PARAM_STRING() or PRINT_DATASET() or others
175  *      here---it will cause problems.
176  * @param ALIAS An alias for the parameter (one letter).
177  *
178  * @see mlpack::IO, BINDING_NAME(), BINDING_SHORT_DESC(), BINDING_LONG_DESC(),
179  * BINDING_EXAMPLE() and BINDING_SEE_ALSO().
180  *
181  * @bug
182  * The __COUNTER__ variable is used in most cases to guarantee a unique global
183  * identifier for options declared using the PARAM_*() macros. However, not all
184  * compilers have this support--most notably, gcc < 4.3. In that case, the
185  * __LINE__ macro is used as an attempt to get a unique global identifier, but
186  * collisions are still possible, and they produce bizarre error messages.  See
187  * https://github.com/mlpack/mlpack/issues/100 for more information.
188  */
189 #define PARAM_FLAG(ID, DESC, ALIAS) \
190     PARAM_IN(bool, ID, DESC, ALIAS, false, false);
191 
192 /**
193  * Define an integer input parameter.
194  *
195  * The parameter can then be specified on the command line with
196  * --ID=value.
197  *
198  * @param ID Name of the parameter.
199  * @param DESC Quick description of the parameter (1-2 sentences).  Don't use
200  *      printing macros like PRINT_PARAM_STRING() or PRINT_DATASET() or others
201  *      here---it will cause problems.
202  * @param ALIAS An alias for the parameter (one letter).
203  * @param DEF Default value of the parameter.
204  *
205  * @see mlpack::IO, BINDING_NAME(), BINDING_SHORT_DESC(), BINDING_LONG_DESC(),
206  * BINDING_EXAMPLE() and BINDING_SEE_ALSO().
207  *
208  * @bug
209 // Use a forward declaration of the class.
210  * The __COUNTER__ variable is used in most cases to guarantee a unique global
211  * identifier for options declared using the PARAM_*() macros. However, not all
212  * compilers have this support--most notably, gcc < 4.3. In that case, the
213  * __LINE__ macro is used as an attempt to get a unique global identifier, but
214  * collisions are still possible, and they produce bizarre error messages.  See
215  * https://github.com/mlpack/mlpack/issues/100 for more information.
216  */
217 #define PARAM_INT_IN(ID, DESC, ALIAS, DEF) \
218     PARAM_IN(int, ID, DESC, ALIAS, DEF, false)
219 
220 /**
221  * Define an integer output parameter.  This parameter will be printed on stdout
222  * at the end of the program; for instance, if the parameter name is "number"
223  * and the value is 5, the output on stdout would be of the following form:
224  *
225  * @code
226  * number: 5
227  * @endcode
228  *
229  * If the parameter is not set by the end of the program, a fatal runtime error
230  * will be issued.
231  *
232  * @param ID Name of the parameter.
233  * @param DESC Quick description of the parameter (1-2 sentences).  Don't use
234  *      printing macros like PRINT_PARAM_STRING() or PRINT_DATASET() or others
235  *      here---it will cause problems.
236  *
237  * @see mlpack::IO, BINDING_NAME(), BINDING_SHORT_DESC(), BINDING_LONG_DESC(),
238  * BINDING_EXAMPLE() and BINDING_SEE_ALSO().
239  *
240  * @bug
241  * The __COUNTER__ variable is used in most cases to guarantee a unique global
242  * identifier for options declared using the PARAM_*() macros. However, not all
243  * compilers have this support--most notably, gcc < 4.3. In that case, the
244  * __LINE__ macro is used as an attempt to get a unique global identifier, but
245  * collisions are still possible, and they produce bizarre error messages.  See
246  * https://github.com/mlpack/mlpack/issues/100 for more information.
247  */
248 #define PARAM_INT_OUT(ID, DESC) \
249     PARAM_OUT(int, ID, DESC, "", 0, false)
250 
251 /**
252  * Define a double input parameter.
253  *
254  * The parameter can then be specified on the command line with
255  * --ID=value.
256  *
257  * @param ID Name of the parameter.
258  * @param DESC Quick description of the parameter (1-2 sentences).  Don't use
259  *      printing macros like PRINT_PARAM_STRING() or PRINT_DATASET() or others
260  *      here---it will cause problems.
261  * @param ALIAS An alias for the parameter (one letter).
262  * @param DEF Default value of the parameter.
263  *
264  * @see mlpack::IO, BINDING_NAME(), BINDING_SHORT_DESC(), BINDING_LONG_DESC(),
265  * BINDING_EXAMPLE() and BINDING_SEE_ALSO().
266  *
267  * @bug
268  * The __COUNTER__ variable is used in most cases to guarantee a unique global
269  * identifier for options declared using the PARAM_*() macros. However, not all
270  * compilers have this support--most notably, gcc < 4.3. In that case, the
271  * __LINE__ macro is used as an attempt to get a unique global identifier, but
272  * collisions are still possible, and they produce bizarre error messages.  See
273  * https://github.com/mlpack/mlpack/issues/100 for more information.
274  */
275 #define PARAM_DOUBLE_IN(ID, DESC, ALIAS, DEF) \
276     PARAM_IN(double, ID, DESC, ALIAS, DEF, false)
277 
278 /**
279  * Define a double output parameter.  This parameter will be printed on stdout
280  * at the end of the program; for instance, if the parameter name is "number"
281  * and the value is 5.012, the output on stdout would be of the following form:
282  *
283  * @code
284  * number: 5.012
285  * @endcode
286  *
287  * If the parameter is not set by the end of the program, a fatal runtime error
288  * will be issued.
289  *
290  * @param ID Name of the parameter.
291  * @param DESC Quick description of the parameter (1-2 sentences).  Don't use
292  *      printing macros like PRINT_PARAM_STRING() or PRINT_DATASET() or others
293  *      here---it will cause problems.
294  *
295  * @see mlpack::IO, BINDING_NAME(), BINDING_SHORT_DESC(), BINDING_LONG_DESC(),
296  * BINDING_EXAMPLE() and BINDING_SEE_ALSO().
297  *
298  * @bug
299  * The __COUNTER__ variable is used in most cases to guarantee a unique global
300  * identifier for options declared using the PARAM_*() macros. However, not all
301  * compilers have this support--most notably, gcc < 4.3. In that case, the
302  * __LINE__ macro is used as an attempt to get a unique global identifier, but
303  * collisions are still possible, and they produce bizarre error messages.  See
304  * https://github.com/mlpack/mlpack/issues/100 for more information.
305  */
306 #define PARAM_DOUBLE_OUT(ID, DESC) \
307     PARAM_OUT(double, ID, DESC, "", 0.0, false)
308 
309 /**
310  * Define a string input parameter.
311  *
312  * The parameter can then be specified on the command line with
313  * --ID=value. If ALIAS is equal to DEF_MOD (which is set using the
314  * BINDING_LONG_DESC() macro), the parameter can be specified with just
315  * --ID=value.
316  *
317  * @param ID Name of the parameter.
318  * @param DESC Quick description of the parameter (1-2 sentences).  Don't use
319  *      printing macros like PRINT_PARAM_STRING() or PRINT_DATASET() or others
320  *      here---it will cause problems.
321  * @param ALIAS An alias for the parameter (one letter).
322  * @param DEF Default value of the parameter.
323  *
324  * @see mlpack::IO, BINDING_NAME(), BINDING_SHORT_DESC(), BINDING_LONG_DESC(),
325  * BINDING_EXAMPLE() and BINDING_SEE_ALSO().
326  *
327  * @bug
328  * The __COUNTER__ variable is used in most cases to guarantee a unique global
329  * identifier for options declared using the PARAM_*() macros. However, not all
330  * compilers have this support--most notably, gcc < 4.3. In that case, the
331  * __LINE__ macro is used as an attempt to get a unique global identifier, but
332  * collisions are still possible, and they produce bizarre error messages.  See
333  * https://github.com/mlpack/mlpack/issues/100 for more information.
334  */
335 #define PARAM_STRING_IN(ID, DESC, ALIAS, DEF) \
336     PARAM_IN(std::string, ID, DESC, ALIAS, DEF, false)
337 
338 /**
339  * Define a string output parameter.
340  *
341  * The string will be printed to stdout at the end of the program.  For
342  * instance, if there was a string output parameter called "something" with
343  * value "hello", at the end of the program the output would be of the following
344  * form:
345  *
346  * @code
347  * something: "hello"
348  * @endcode
349  *
350  * @param ID Name of the parameter.
351  * @param DESC Quick description of the parameter (1-2 sentences).  Don't use
352  *      printing macros like PRINT_PARAM_STRING() or PRINT_DATASET() or others
353  *      here---it will cause problems.
354  * @param ALIAS An alias for the parameter (one letter).
355  *
356  * @see mlpack::IO, BINDING_NAME(), BINDING_SHORT_DESC(), BINDING_LONG_DESC(),
357  * BINDING_EXAMPLE() and BINDING_SEE_ALSO().
358  *
359  * @bug
360  * The __COUNTER__ variable is used in most cases to guarantee a unique global
361  * identifier for options declared using the PARAM_*() macros. However, not all
362  * compilers have this support--most notably, gcc < 4.3. In that case, the
363  * __LINE__ macro is used as an attempt to get a unique global identifier, but
364  * collisions are still possible, and they produce bizarre error messages.  See
365  * https://github.com/mlpack/mlpack/issues/100 for more information.
366  */
367 #define PARAM_STRING_OUT(ID, DESC, ALIAS) \
368     PARAM_OUT(std::string, ID, DESC, ALIAS, "", false)
369 
370 /**
371  * Define a matrix input parameter.  From the command line, the user can specify
372  * the file that holds the matrix, using the name of the matrix parameter with
373  * "_file" appended (and the same alias).  So for instance, if the name of the
374  * matrix parameter was "mat", the user could specify that the "mat" matrix was
375  * held in matrix.csv by giving the parameter
376  *
377  * @code
378  * --mat_file matrix.csv
379  * @endcode
380  *
381  * @param ID Name of the parameter.
382  * @param DESC Description of the parameter (1-2 sentences).  Don't use
383  *      printing macros like PRINT_PARAM_STRING() or PRINT_DATASET() or others
384  *      here---it will cause problems.
385  * @param ALIAS An alias for the parameter (one letter).
386  *
387  * @bug
388  * The __COUNTER__ variable is used in most cases to guarantee a unique global
389  * identifier for options declared using the PARAM_*() macros. However, not all
390  * compilers have this support--most notably, gcc < 4.3. In that case, the
391  * __LINE__ macro is used as an attempt to get a unique global identifier, but
392  * collisions are still possible, and they produce bizarre error messages.  See
393  * https://github.com/mlpack/mlpack/issues/100 for more information.
394  */
395 #define PARAM_MATRIX_IN(ID, DESC, ALIAS) \
396     PARAM_MATRIX(ID, DESC, ALIAS, false, true, true)
397 
398 /**
399  * Define a required matrix input parameter.  From the command line, the user
400  * can specify the file that holds the matrix, using the name of the matrix
401  * parameter with "_file" appended (and the same alias).  So for instance, if
402  * the name of the matrix parameter was "mat", the user could specify that the
403  * "mat" matrix was held in matrix.csv by giving the parameter
404  *
405  * @code
406  * --mat_file matrix.csv
407  * @endcode
408  *
409  * @param ID Name of the parameter.
410  * @param DESC Description of the parameter (1-2 sentences).  Don't use
411  *      printing macros like PRINT_PARAM_STRING() or PRINT_DATASET() or others
412  *      here---it will cause problems.
413  * @param ALIAS An alias for the parameter (one letter).
414  *
415  * @bug
416  * The __COUNTER__ variable is used in most cases to guarantee a unique global
417  * identifier for options declared using the PARAM_*() macros. However, not all
418  * compilers have this support--most notably, gcc < 4.3. In that case, the
419  * __LINE__ macro is used as an attempt to get a unique global identifier, but
420  * collisions are still possible, and they produce bizarre error messages.  See
421  * https://github.com/mlpack/mlpack/issues/100 for more information.
422  */
423 #define PARAM_MATRIX_IN_REQ(ID, DESC, ALIAS) \
424     PARAM_MATRIX(ID, DESC, ALIAS, true, true, true)
425 
426 /**
427  * Define a matrix output parameter.  When the program terminates, the matrix
428  * will be saved to whatever it was set to by IO::GetParam<arma::mat>(ID)
429  * during the program.  From the command-line, the user may specify the file in
430  * which to save the output matrix using a string option that is the name of the
431  * matrix parameter with "_file" appended.  So, for instance, if the name of the
432  * output matrix parameter was "mat", the user could speicfy that the "mat"
433  * matrix should be saved in matrix.csv by giving the parameter
434  *
435  * @code
436  * --mat_file matrix.csv
437  * @endcode
438  *
439  * The output matrix will not be printed on stdout, like the other output option
440  * types.
441  *
442  * @param ID Name of the parameter.
443  * @param DESC Description of the parameter (1-2 sentences).  Don't use
444  *      printing macros like PRINT_PARAM_STRING() or PRINT_DATASET() or others
445  *      here---it will cause problems.
446  * @param ALIAS An alias for the parameter (one letter).
447  *
448  * @bug
449  * The __COUNTER__ variable is used in most cases to guarantee a unique global
450  * identifier for options declared using the PARAM_*() macros. However, not all
451  * compilers have this support--most notably, gcc < 4.3. In that case, the
452  * __LINE__ macro is used as an attempt to get a unique global identifier, but
453  * collisions are still possible, and they produce bizarre error messages.  See
454  * https://github.com/mlpack/mlpack/issues/100 for more information.
455  */
456 #define PARAM_MATRIX_OUT(ID, DESC, ALIAS) \
457     PARAM_MATRIX(ID, DESC, ALIAS, false, true, false)
458 
459 /**
460  * Define a transposed matrix input parameter.  This is useful when data is
461  * desired in row-major form instead of the usual column-major form.  From the
462  * command line, the user can specify the file that holds the matrix, using the
463  * name of the matrix parameter with "_file" appended (and the same alias).  So
464  * for instance, if the name of the matrix parameter was "mat", the user could
465  * specify that the "mat" matrix was held in matrix.csv by giving the parameter
466  *
467  * @code
468  * --mat_file matrix.csv
469  * @endcode
470  *
471  * @param ID Name of the parameter.
472  * @param DESC Description of the parameter (1-2 sentences).  Don't use
473  *      printing macros like PRINT_PARAM_STRING() or PRINT_DATASET() or others
474  *      here---it will cause problems.
475  * @param ALIAS An alias for the parameter (one letter).
476  *
477  * @bug
478  * The __COUNTER__ variable is used in most cases to guarantee a unique global
479  * identifier for options declared using the PARAM_*() macros. However, not all
480  * compilers have this support--most notably, gcc < 4.3. In that case, the
481  * __LINE__ macro is used as an attempt to get a unique global identifier, but
482  * collisions are still possible, and they produce bizarre error messages.  See
483  * https://github.com/mlpack/mlpack/issues/100 for more information.
484  */
485 #define PARAM_TMATRIX_IN(ID, DESC, ALIAS) \
486     PARAM_MATRIX(ID, DESC, ALIAS, false, false, true)
487 
488 /**
489  * Define a required transposed matrix input parameter.  This is useful when
490  * data is desired in row-major form instead of the usual column-major form.
491  * From the command line, the user can specify the file that holds the matrix,
492  * using the name of the matrix parameter with "_file" appended (and the same
493  * alias).  So for instance, if the name of the matrix parameter was "mat", the
494  * user could specify that the "mat" matrix was held in matrix.csv by giving the
495  * parameter
496  *
497  * @code
498  * --mat_file matrix.csv
499  * @endcode
500  *
501  * @param ID Name of the parameter.
502  * @param DESC Description of the parameter (1-2 sentences).  Don't use
503  *      printing macros like PRINT_PARAM_STRING() or PRINT_DATASET() or others
504  *      here---it will cause problems.
505  * @param ALIAS An alias for the parameter (one letter).
506  *
507  * @bug
508  * The __COUNTER__ variable is used in most cases to guarantee a unique global
509  * identifier for options declared using the PARAM_*() macros. However, not all
510  * compilers have this support--most notably, gcc < 4.3. In that case, the
511  * __LINE__ macro is used as an attempt to get a unique global identifier, but
512  * collisions are still possible, and they produce bizarre error messages.  See
513  * https://github.com/mlpack/mlpack/issues/100 for more information.
514  */
515 #define PARAM_TMATRIX_IN_REQ(ID, DESC, ALIAS) \
516     PARAM_MATRIX(ID, DESC, ALIAS, true, false, true)
517 
518 /**
519  * Define a transposed matrix output parameter.  This is useful when data is
520  * stored in a row-major form instead of the usual column-major form.  When the
521  * program terminates, the matrix will be saved to whatever it was set to by
522  * IO::GetParam<arma::mat>(ID) during the program.  From the command-line, the
523  * user may specify the file in which to save the output matrix using a string
524  * option that is the name of the matrix parameter with "_file" appended.  So,
525  * for instance, if the name of the output matrix parameter was "mat", the user
526  * could speicfy that the "mat" matrix should be saved in matrix.csv by giving
527  * the parameter
528  *
529  * @code
530  * --mat_file matrix.csv
531  * @endcode
532  *
533  * The output matrix will not be printed on stdout, like the other output option
534  * types.
535  *
536  * @param ID Name of the parameter.
537  * @param DESC Description of the parameter (1-2 sentences).  Don't use
538  *      printing macros like PRINT_PARAM_STRING() or PRINT_DATASET() or others
539  *      here---it will cause problems.
540  * @param ALIAS An alias for the parameter (one letter).
541  *
542  * @bug
543  * The __COUNTER__ variable is used in most cases to guarantee a unique global
544  * identifier for options declared using the PARAM_*() macros. However, not all
545  * compilers have this support--most notably, gcc < 4.3. In that case, the
546  * __LINE__ macro is used as an attempt to get a unique global identifier, but
547  * collisions are still possible, and they produce bizarre error messages.  See
548  * https://github.com/mlpack/mlpack/issues/100 for more information.
549  */
550 #define PARAM_TMATRIX_OUT(ID, DESC, ALIAS) \
551     PARAM_MATRIX(ID, DESC, ALIAS, false, false, false)
552 
553 /**
554  * Define an unsigned matrix input parameter (arma::Mat<size_t>).  From the
555  * command line, the user can specify the file that holds the matrix, using the
556  * name of the matrix parameter with "_file" appended (and the same alias).  So
557  * for instance, if the name of the matrix parameter was "mat", the user could
558  * specify that the "mat" matrix was held in matrix.csv by giving the parameter
559  *
560  * @code
561  * --mat_file matrix.csv
562  * @endcode
563  *
564  * @param ID Name of the parameter.
565  * @param DESC Description of the parameter (1-2 sentences).  Don't use
566  *      printing macros like PRINT_PARAM_STRING() or PRINT_DATASET() or others
567  *      here---it will cause problems.
568  * @param ALIAS An alias for the parameter (one letter).
569  *
570  * @bug
571  * The __COUNTER__ variable is used in most cases to guarantee a unique global
572  * identifier for options declared using the PARAM_*() macros. However, not all
573  * compilers have this support--most notably, gcc < 4.3. In that case, the
574  * __LINE__ macro is used as an attempt to get a unique global identifier, but
575  * collisions are still possible, and they produce bizarre error messages.  See
576  * https://github.com/mlpack/mlpack/issues/100 for more information.
577  */
578 #define PARAM_UMATRIX_IN(ID, DESC, ALIAS) \
579     PARAM_UMATRIX(ID, DESC, ALIAS, false, true, true)
580 
581 /**
582  * Define a required unsigned matrix input parameter (arma::Mat<size_t>).  From
583  * the command line, the user can specify the file that holds the matrix, using
584  * the name of the matrix parameter with "_file" appended (and the same alias).
585  * So for instance, if the name of the matrix parameter was "mat", the user
586  * could specify that the "mat" matrix was held in matrix.csv by giving the
587  * parameter
588  *
589  * @code
590  * --mat_file matrix.csv
591  * @endcode
592  *
593  * @param ID Name of the parameter.
594  * @param DESC Description of the parameter (1-2 sentences).  Don't use
595  *      printing macros like PRINT_PARAM_STRING() or PRINT_DATASET() or others
596  *      here---it will cause problems.
597  * @param ALIAS An alias for the parameter (one letter).
598  *
599  * @bug
600  * The __COUNTER__ variable is used in most cases to guarantee a unique global
601  * identifier for options declared using the PARAM_*() macros. However, not all
602  * compilers have this support--most notably, gcc < 4.3. In that case, the
603  * __LINE__ macro is used as an attempt to get a unique global identifier, but
604  * collisions are still possible, and they produce bizarre error messages.  See
605  * https://github.com/mlpack/mlpack/issues/100 for more information.
606  */
607 #define PARAM_UMATRIX_IN_REQ(ID, DESC, ALIAS) \
608     PARAM_UMATRIX(ID, DESC, ALIAS, true, true, true)
609 
610 /**
611  * Define an unsigned matrix output parameter (arma::Mat<size_t>).  When the
612  * program terminates, the matrix will be saved to whatever it was set to by
613  * IO::GetParam<arma::Mat<size_t>>(ID) during the program.  From the
614  * command-line, the user may specify the file in which to save the output
615  * matrix using a string option that is the name of the matrix parameter with
616  * "_file" appended.  So, for instance, if the name of the output matrix
617  * parameter was "mat", the user could speicfy that the "mat" matrix should be
618  * saved in matrix.csv by giving the parameter
619  *
620  * @code
621  * --mat_file matrix.csv
622  * @endcode
623  *
624  * The output matrix will not be printed on stdout, like the other output option
625  * types.
626  *
627  * @param ID Name of the parameter.
628  * @param DESC Description of the parameter (1-2 sentences).  Don't use
629  *      printing macros like PRINT_PARAM_STRING() or PRINT_DATASET() or others
630  *      here---it will cause problems.
631  * @param ALIAS An alias for the parameter (one letter).
632  *
633  * @bug
634  * The __COUNTER__ variable is used in most cases to guarantee a unique global
635  * identifier for options declared using the PARAM_*() macros. However, not all
636  * compilers have this support--most notably, gcc < 4.3. In that case, the
637  * __LINE__ macro is used as an attempt to get a unique global identifier, but
638  * collisions are still possible, and they produce bizarre error messages.  See
639  * https://github.com/mlpack/mlpack/issues/100 for more information.
640  */
641 #define PARAM_UMATRIX_OUT(ID, DESC, ALIAS) \
642     PARAM_UMATRIX(ID, DESC, ALIAS, false, true, false)
643 
644 
645 /**
646  * Define a vector input parameter (type arma::vec).  From the command line, the
647  * user can specify the file that holds the vector, using the name of the vector
648  * parameter with "_file" appended (and the same alias).  So for instance, if
649  * the name of the vector parameter was "vec", the user could specify that the
650  * "vec" vector was held in vec.csv by giving the parameter:
651  *
652  * @code
653  * --vec_file vector.csv
654  * @endcode
655  *
656  * @param ID Name of the parameter.
657  * @param DESC Description of the parameter (1-2 sentences).  Don't use
658  *      printing macros like PRINT_PARAM_STRING() or PRINT_DATASET() or others
659  *      here---it will cause problems.
660  * @param ALIAS An alias for the parameter (one letter).
661  *
662  * @bug
663  * The __COUNTER__ variable is used in most cases to guarantee a unique global
664  * identifier for options declared using the PARAM_*() macros. However, not all
665  * compilers have this support--most notably, gcc < 4.3. In that case, the
666  * __LINE__ macro is used as an attempt to get a unique global identifier, but
667  * collisions are still possible, and they produce bizarre error messages.  See
668  * https://github.com/mlpack/mlpack/issues/100 for more information.
669  */
670 #define PARAM_COL_IN(ID, DESC, ALIAS) \
671     PARAM_COL(ID, DESC, ALIAS, false, true, true)
672 
673 /**
674  * Define a required vector input parameter (type arma::vec).  From the command
675  * line, the user can specify the file that holds the vector, using the name of
676  * the vector parameter with "_file" appended (and the same alias).  So for
677  * instance, if the name of the vector parameter was "vec", the user could
678  * specify that the "vec" vector was held in vec.csv by giving the parameter:
679  *
680  * @code
681  * --vec_file vector.csv
682  * @endcode
683  *
684  * @param ID Name of the parameter.
685  * @param DESC Description of the parameter (1-2 sentences).  Don't use
686  *      printing macros like PRINT_PARAM_STRING() or PRINT_DATASET() or others
687  *      here---it will cause problems.
688  * @param ALIAS An alias for the parameter (one letter).
689  *
690  * @bug
691  * The __COUNTER__ variable is used in most cases to guarantee a unique global
692  * identifier for options declared using the PARAM_*() macros. However, not all
693  * compilers have this support--most notably, gcc < 4.3. In that case, the
694  * __LINE__ macro is used as an attempt to get a unique global identifier, but
695  * collisions are still possible, and they produce bizarre error messages.  See
696  * https://github.com/mlpack/mlpack/issues/100 for more information.
697  */
698 #define PARAM_COL_IN_REQ(ID, DESC, ALIAS) \
699     PARAM_COL(ID, DESC, ALIAS, true, true, true)
700 
701 /**
702  * Define a row vector input parameter (type arma::rowvec).  From the command
703  * line, the user can specify the file that holds the vector, using the name of
704  * the vector parameter with "_file" appended (and the same alias).  So for
705  * instance, if the name of the vector parameter was "vec", the user could
706  * specify that the "vec" vector was held in vec.csv by giving the parameter:
707  *
708  * @code
709  * --vec_file vector.csv
710  * @endcode
711  *
712  * @param ID Name of the parameter.
713  * @param DESC Description of the parameter (1-2 sentences).  Don't use
714  *      printing macros like PRINT_PARAM_STRING() or PRINT_DATASET() or others
715  *      here---it will cause problems.
716  * @param ALIAS An alias for the parameter (one letter).
717  *
718  * @bug
719  * The __COUNTER__ variable is used in most cases to guarantee a unique global
720  * identifier for options declared using the PARAM_*() macros. However, not all
721  * compilers have this support--most notably, gcc < 4.3. In that case, the
722  * __LINE__ macro is used as an attempt to get a unique global identifier, but
723  * collisions are still possible, and they produce bizarre error messages.  See
724  * https://github.com/mlpack/mlpack/issues/100 for more information.
725  */
726 #define PARAM_ROW_IN(ID, DESC, ALIAS) \
727     PARAM_ROW(ID, DESC, ALIAS, false, true, true)
728 
729 /**
730  * Define an unsigned vector input parameter (type arma::Col<size_t>).  From the
731  * command line, the user can specify the file that holds the vector, using the
732  * name of the vector parameter with "_file" appended (and the same alias).  So
733  * for instance, if the name of the vector parameter was "vec", the user could
734  * specify that the "vec" vector was held in vec.csv by giving the parameter:
735  *
736  * @code
737  * --vec_file vector.csv
738  * @endcode
739  *
740  * @param ID Name of the parameter.
741  * @param DESC Description of the parameter (1-2 sentences).  Don't use
742  *      printing macros like PRINT_PARAM_STRING() or PRINT_DATASET() or others
743  *      here---it will cause problems.
744  * @param ALIAS An alias for the parameter (one letter).
745  *
746  * @bug
747  * The __COUNTER__ variable is used in most cases to guarantee a unique global
748  * identifier for options declared using the PARAM_*() macros. However, not all
749  * compilers have this support--most notably, gcc < 4.3. In that case, the
750  * __LINE__ macro is used as an attempt to get a unique global identifier, but
751  * collisions are still possible, and they produce bizarre error messages.  See
752  * https://github.com/mlpack/mlpack/issues/100 for more information.
753  */
754 #define PARAM_UCOL_IN(ID, DESC, ALIAS) \
755     PARAM_UCOL(ID, DESC, ALIAS, false, true, true)
756 
757 /**
758  * Define an unsigned row vector input parameter (type arma::Row<size_t>).  From
759  * the command line, the user can specify the file that holds the vector, using
760  * the name of the vector parameter with "_file" appended (and the same alias).
761  * So for instance, if the name of the vector parameter was "vec", the user
762  * could specify that the "vec" vector was held in vec.csv by giving the
763  * parameter:
764  *
765  * @code
766  * --vec_file vector.csv
767  * @endcode
768  *
769  * @param ID Name of the parameter.
770  * @param DESC Description of the parameter (1-2 sentences).  Don't use
771  *      printing macros like PRINT_PARAM_STRING() or PRINT_DATASET() or others
772  *      here---it will cause problems.
773  * @param ALIAS An alias for the parameter (one letter).
774  *
775  * @bug
776  * The __COUNTER__ variable is used in most cases to guarantee a unique global
777  * identifier for options declared using the PARAM_*() macros. However, not all
778  * compilers have this support--most notably, gcc < 4.3. In that case, the
779  * __LINE__ macro is used as an attempt to get a unique global identifier, but
780  * collisions are still possible, and they produce bizarre error messages.  See
781  * https://github.com/mlpack/mlpack/issues/100 for more information.
782  */
783 #define PARAM_UROW_IN(ID, DESC, ALIAS) \
784     PARAM_UROW(ID, DESC, ALIAS, false, true, true)
785 
786 /**
787  * Define a vector output parameter (type arma::vec).  When the program
788  * terminates, the vector will be saved to whatever it was set to during the
789  * program.  From the command-line, the user may specify the file in which to
790  * save the output vector using a string option that is the name of the matrix
791  * parameter with "_file" appended.  So, for instance, if the name of the output
792  * vector parameter was "vec", the user could specify that the "vec" vector
793  * should be saved in vector.csv by giving the parameter:
794  *
795  * @code
796  * --vec_file vector.csv
797  * @endcode
798  *
799  * The output vector will not be printed on stdout, like the other output option
800  * types.
801  *
802  * @param ID Name of the parameter.
803  * @param DESC Description of the parameter (1-2 sentences).  Don't use
804  *      printing macros like PRINT_PARAM_STRING() or PRINT_DATASET() or others
805  *      here---it will cause problems.
806  * @param ALIAS An alias for the parameter (one letter).
807  *
808  * @bug
809  * The __COUNTER__ variable is used in most cases to guarantee a unique global
810  * identifier for options declared using the PARAM_*() macros. However, not all
811  * compilers have this support--most notably, gcc < 4.3. In that case, the
812  * __LINE__ macro is used as an attempt to get a unique global identifier, but
813  * collisions are still possible, and they produce bizarre error messages.  See
814  * https://github.com/mlpack/mlpack/issues/100 for more information.
815  */
816 #define PARAM_COL_OUT(ID, DESC, ALIAS) \
817     PARAM_COL(ID, DESC, ALIAS, false, true, false)
818 
819 /**
820  * Define a row vector output parameter (type arma::rowvec).  When the program
821  * terminates, the vector will be saved to whatever it was set to during the
822  * program.  From the command-line, the user may specify the file in which to
823  * save the output vector using a string option that is the name of the matrix
824  * parameter with "_file" appended.  So, for instance, if the name of the output
825  * vector parameter was "vec", the user could specify that the "vec" vector
826  * should be saved in vector.csv by giving the parameter:
827  *
828  * @code
829  * --vec_file vector.csv
830  * @endcode
831  *
832  * The output vector will not be printed on stdout, like the other output option
833  * types.
834  *
835  * @param ID Name of the parameter.
836  * @param DESC Description of the parameter (1-2 sentences).  Don't use
837  *      printing macros like PRINT_PARAM_STRING() or PRINT_DATASET() or others
838  *      here---it will cause problems.
839  * @param ALIAS An alias for the parameter (one letter).
840  *
841  * @bug
842  * The __COUNTER__ variable is used in most cases to guarantee a unique global
843  * identifier for options declared using the PARAM_*() macros. However, not all
844  * compilers have this support--most notably, gcc < 4.3. In that case, the
845  * __LINE__ macro is used as an attempt to get a unique global identifier, but
846  * collisions are still possible, and they produce bizarre error messages.  See
847  * https://github.com/mlpack/mlpack/issues/100 for more information.
848  */
849 #define PARAM_ROW_OUT(ID, DESC, ALIAS) \
850     PARAM_ROW(ID, DESC, ALIAS, false, true, false)
851 
852 /**
853  * Define an unsigned vector output parameter (type arma::Col<size_t>).  When
854  * the program terminates, the vector will be saved to whatever it was set to
855  * during the program.  From the command-line, the user may specify the file in
856  * which to save the output vector using a string option that is the name of the
857  * matrix parameter with "_file" appended.  So, for instance, if the name of the
858  * output vector parameter was "vec", the user could specify that the "vec"
859  * vector should be saved in vector.csv by giving the parameter:
860  *
861  * @code
862  * --vec_file vector.csv
863  * @endcode
864  *
865  * The output vector will not be printed on stdout, like the other output option
866  * types.
867  *
868  * @param ID Name of the parameter.
869  * @param DESC Description of the parameter (1-2 sentences).  Don't use
870  *      printing macros like PRINT_PARAM_STRING() or PRINT_DATASET() or others
871  *      here---it will cause problems.
872  * @param ALIAS An alias for the parameter (one letter).
873  *
874  * @bug
875  * The __COUNTER__ variable is used in most cases to guarantee a unique global
876  * identifier for options declared using the PARAM_*() macros. However, not all
877  * compilers have this support--most notably, gcc < 4.3. In that case, the
878  * __LINE__ macro is used as an attempt to get a unique global identifier, but
879  * collisions are still possible, and they produce bizarre error messages.  See
880  * https://github.com/mlpack/mlpack/issues/100 for more information.
881  */
882 #define PARAM_UCOL_OUT(ID, DESC, ALIAS) \
883     PARAM_UCOL(ID, DESC, ALIAS, false, true, false)
884 
885 /**
886  * Define an unsigned row vector output parameter (type arma::Row<size_t>).
887  * When the program terminates, the vector will be saved to whatever it was set
888  * to during the program.  From the command-line, the user may specify the file
889  * in which to save the output vector using a string option that is the name of
890  * the matrix parameter with "_file" appended.  So, for instance, if the name of
891  * the output vector parameter was "vec", the user could specify that the "vec"
892  * vector should be saved in vector.csv by giving the parameter:
893  *
894  * @code
895  * --vec_file vector.csv
896  * @endcode
897  *
898  * The output vector will not be printed on stdout, like the other output option
899  * types.
900  *
901  * @param ID Name of the parameter.
902  * @param DESC Description of the parameter (1-2 sentences).  Don't use
903  *      printing macros like PRINT_PARAM_STRING() or PRINT_DATASET() or others
904  *      here---it will cause problems.
905  * @param ALIAS An alias for the parameter (one letter).
906  *
907  * @bug
908  * The __COUNTER__ variable is used in most cases to guarantee a unique global
909  * identifier for options declared using the PARAM_*() macros. However, not all
910  * compilers have this support--most notably, gcc < 4.3. In that case, the
911  * __LINE__ macro is used as an attempt to get a unique global identifier, but
912  * collisions are still possible, and they produce bizarre error messages.  See
913  * https://github.com/mlpack/mlpack/issues/100 for more information.
914  */
915 #define PARAM_UROW_OUT(ID, DESC, ALIAS) \
916     PARAM_UROW(ID, DESC, ALIAS, false, true, false)
917 
918 /**
919  * Define a std::vector input parameter.
920  *
921  * The parameter can then be specified on the command line with
922  * --ID=value1,value2,value3.
923  *
924  * @param T Type of the parameter.
925  * @param ID Name of the parameter.
926  * @param DESC Quick description of the parameter (1-2 sentences).  Don't use
927  *      printing macros like PRINT_PARAM_STRING() or PRINT_DATASET() or others
928  *      here---it will cause problems.
929  * @param ALIAS An alias for the parameter (one letter).
930  *
931  * @see mlpack::IO, BINDING_NAME(), BINDING_SHORT_DESC(), BINDING_LONG_DESC(),
932  * BINDING_EXAMPLE() and BINDING_SEE_ALSO().
933  *
934  * @bug
935  * The __COUNTER__ variable is used in most cases to guarantee a unique global
936  * identifier for options declared using the PARAM_*() macros. However, not all
937  * compilers have this support--most notably, gcc < 4.3. In that case, the
938  * __LINE__ macro is used as an attempt to get a unique global identifier, but
939  * collisions are still possible, and they produce bizarre error messages.  See
940  * https://github.com/mlpack/mlpack/issues/100 for more information.
941  */
942 #define PARAM_VECTOR_IN(T, ID, DESC, ALIAS) \
943     PARAM_IN(std::vector<T>, ID, DESC, ALIAS, std::vector<T>(), false)
944 
945 /**
946  * Define a vector output parameter.  This vector will be printed on stdout at
947  * the end of the program; for instance, if the parameter name is "vector" and
948  * the vector holds the array { 1, 2, 3, 4 }, the output on stdout would be of
949  * the following form:
950  *
951  * @code
952  * vector: 1, 2, 3, 4
953  * @endcode
954  *
955  * If the parameter is not set by the end of the program, a fatal runtime error
956  * will be issued.
957  *
958  * @param T Type of the parameter.
959  * @param ID Name of the parameter.
960  * @param DESC Quick description of the parameter (1-2 sentences).  Don't use
961  *      printing macros like PRINT_PARAM_STRING() or PRINT_DATASET() or others
962  *      here---it will cause problems.
963  * @param ALIAS An alias for the parameter (one letter).
964  *
965  * @see mlpack::IO, BINDING_NAME(), BINDING_SHORT_DESC(), BINDING_LONG_DESC(),
966  * BINDING_EXAMPLE() and BINDING_SEE_ALSO().
967  *
968  * @bug
969  * The __COUNTER__ variable is used in most cases to guarantee a unique global
970  * identifier for options declared using the PARAM_*() macros. However, not all
971  * compilers have this support--most notably, gcc < 4.3. In that case, the
972  * __LINE__ macro is used as an attempt to get a unique global identifier, but
973  * collisions are still possible, and they produce bizarre error messages.  See
974  * https://github.com/mlpack/mlpack/issues/100 for more information.
975  */
976 #define PARAM_VECTOR_OUT(T, ID, DESC, ALIAS) \
977     PARAM_OUT(std::vector<T>, ID, DESC, ALIAS, std::vector<T>(), false)
978 
979 /**
980  * Define an input DatasetInfo/matrix parameter.  From the command line, the
981  * user can specify the file that holds the matrix, using the name of the matrix
982  * parameter with "_file" appended (and the same alias).  So for instance, if
983  * the name of the matrix parameter was "matrix", the user could specify that
984  * the "matrix" matrix was held in file.csv by giving the parameter
985  *
986  * @code
987  * --matrix_file file.csv
988  * @endcode
989  *
990  * Then the DatasetInfo and matrix type could be accessed with
991  *
992  * @code
993  * DatasetInfo d = std::move(
994  *     IO::GetParam<std::tuple<DatasetInfo, arma::mat>>("matrix").get<0>());
995  * arma::mat m = std::move(
996  *     IO::GetParam<std::tuple<DatasetInfo, arma::mat>>("matrix").get<1>());
997  * @endcode
998  *
999  * @param ID Name of the parameter.
1000  * @param DESC Quick description of the parameter (1-2 sentences).  Don't use
1001  *      printing macros like PRINT_PARAM_STRING() or PRINT_DATASET() or others
1002  *      here---it will cause problems.
1003  * @param ALIAS One-character string representing the alias of the parameter.
1004  *
1005  * @see mlpack::IO, BINDING_NAME(), BINDING_SHORT_DESC(), BINDING_LONG_DESC(),
1006  * BINDING_EXAMPLE() and BINDING_SEE_ALSO().
1007  *
1008  * @bug
1009  * The __COUNTER__ variable is used in most cases to guarantee a unique global
1010  * identifier for options declared using the PARAM_*() macros. However, not all
1011  * compilers have this support--most notably, gcc < 4.3. In that case, the
1012  * __LINE__ macro is used as an attempt to get a unique global identifier, but
1013  * collisions are still possible, and they produce bizarre error messages.  See
1014  * https://github.com/mlpack/mlpack/issues/100 for more information.
1015  */
1016 #define TUPLE_TYPE std::tuple<mlpack::data::DatasetInfo, arma::mat>
1017 #define PARAM_MATRIX_AND_INFO_IN(ID, DESC, ALIAS) \
1018     PARAM_IN(TUPLE_TYPE, ID, DESC, ALIAS, TUPLE_TYPE(), false)
1019 
1020 /**
1021  * Define an input model.  From the command line, the user can specify the file
1022  * that holds the model, using the name of the model parameter with "_file"
1023  * appended (and the same alias).  So for instance, if the name of the model
1024  * parameter was "model", the user could specify that the "model" model was held
1025  * in model.bin by giving the parameter
1026  *
1027  * @code
1028  * --model_file model.bin
1029  * @endcode
1030  *
1031  * Note that the first parameter of this model is the type (the class name) of
1032  * the model to be loaded.  This model type must have a serialize() function; a
1033  * compilation error (a very long and complex one) will result if the model type
1034  * does not have the following function:
1035  *
1036  * @code
1037  * template<typename Archive>
1038  * void serialize(Archive& ar, const unsigned int version);
1039  * @endcode
1040  *
1041  * @param TYPE Type of the model to be loaded.
1042  * @param ID Name of the parameter.
1043  * @param DESC Description of the parameter.  Don't use
1044  *      printing macros like PRINT_PARAM_STRING() or PRINT_DATASET() or others
1045  *      here---it will cause problems.
1046  * @param ALIAS An alias for the parameter (one letter).
1047  */
1048 #define PARAM_MODEL_IN(TYPE, ID, DESC, ALIAS) \
1049     PARAM_MODEL(TYPE, ID, DESC, ALIAS, false, true)
1050 
1051 /**
1052  * Define a required input model.  From the command line, the user can specify
1053  * the file that holds the model, using the name of the model parameter with
1054  * "_file" appended (and the same alias).  So for instance, if the name of the
1055  * model parameter was "model", the user could specify that the "model" model
1056  * was held in model.bin by giving the parameter
1057  *
1058  * @code
1059  * --model_file model.bin
1060  * @endcode
1061  *
1062  * Note that the first parameter of this model is the type (the class name) of
1063  * the model to be loaded.  This model type must have a serialize() function; a
1064  * compilation error (a very long and complex one) will result if the model type
1065  * does not have the following function:
1066  *
1067  * @code
1068  * template<typename Archive>
1069  * void serialize(Archive& ar, const unsigned int version);
1070  * @endcode
1071  *
1072  * @param TYPE Type of the model to be loaded.
1073  * @param ID Name of the parameter.
1074  * @param DESC Description of the parameter.  Don't use
1075  *      printing macros like PRINT_PARAM_STRING() or PRINT_DATASET() or others
1076  *      here---it will cause problems.
1077  * @param ALIAS An alias for the parameter (one letter).
1078  */
1079 #define PARAM_MODEL_IN_REQ(TYPE, ID, DESC, ALIAS) \
1080     PARAM_MODEL(TYPE, ID, DESC, ALIAS, true, true)
1081 
1082 /**
1083  * Define an output model.  From the command line, the user can specify the file
1084  * that should hold the model, using the name of the model parameter with
1085  * "_file" appended (and the same alias).  So for instance, if the user desires
1086  * to save the model to model.bin and the parameter name is "model", they could
1087  * specify
1088  *
1089  * @code
1090  * --model_file model.bin
1091  * @endcode
1092  *
1093  * The model will be saved at the termination of the program.  If you use a
1094  * parameter of this type, you must call IO::Destroy() at the end of your
1095  * program.
1096  *
1097  * @param TYPE Type of the model to be saved.
1098  * @param ID Name of the parameter.
1099  * @param DESC Description of the parameter.  Don't use
1100  *      printing macros like PRINT_PARAM_STRING() or PRINT_DATASET() or others
1101  *      here---it will cause problems.
1102  * @param ALIAS An alias for the parameter (one letter).
1103  */
1104 #define PARAM_MODEL_OUT(TYPE, ID, DESC, ALIAS) \
1105     PARAM_MODEL(TYPE, ID, DESC, ALIAS, false, false)
1106 
1107 /**
1108  * Define a required integer input parameter.
1109  *
1110  * The parameter must then be specified on the command line with --ID=value.
1111  *
1112  * @param ID Name of the parameter.
1113  * @param DESC Quick description of the parameter (1-2 sentences).  Don't use
1114  *      printing macros like PRINT_PARAM_STRING() or PRINT_DATASET() or others
1115  *      here---it will cause problems.
1116  * @param ALIAS An alias for the parameter (one letter).
1117  *
1118  * @see mlpack::IO, BINDING_NAME(), BINDING_SHORT_DESC(), BINDING_LONG_DESC(),
1119  * BINDING_EXAMPLE() and BINDING_SEE_ALSO().
1120  *
1121  * @bug
1122  * The __COUNTER__ variable is used in most cases to guarantee a unique global
1123  * identifier for options declared using the PARAM_*() macros. However, not all
1124  * compilers have this support--most notably, gcc < 4.3. In that case, the
1125  * __LINE__ macro is used as an attempt to get a unique global identifier, but
1126  * collisions are still possible, and they produce bizarre error messages.  See
1127  * https://github.com/mlpack/mlpack/issues/100 for more information.
1128  */
1129 #define PARAM_INT_IN_REQ(ID, DESC, ALIAS) \
1130     PARAM_IN(int, ID, DESC, ALIAS, 0, true)
1131 
1132 /**
1133  * Define a required double parameter.
1134  *
1135  * The parameter must then be specified on the command line with --ID=value.
1136  *
1137  * @param ID Name of the parameter.
1138  * @param DESC Quick description of the parameter (1-2 sentences).  Don't use
1139  *      printing macros like PRINT_PARAM_STRING() or PRINT_DATASET() or others
1140  *      here---it will cause problems.
1141  * @param ALIAS An alias for the parameter (one letter).
1142  *
1143  * @see mlpack::IO, BINDING_NAME(), BINDING_SHORT_DESC(), BINDING_LONG_DESC(),
1144  * BINDING_EXAMPLE() and BINDING_SEE_ALSO().
1145  *
1146  * @bug
1147  * The __COUNTER__ variable is used in most cases to guarantee a unique global
1148  * identifier for options declared using the PARAM_*() macros. However, not all
1149  * compilers have this support--most notably, gcc < 4.3. In that case, the
1150  * __LINE__ macro is used as an attempt to get a unique global identifier, but
1151  * collisions are still possible, and they produce bizarre error messages.  See
1152  * https://github.com/mlpack/mlpack/issues/100 for more information.
1153  */
1154 #define PARAM_DOUBLE_IN_REQ(ID, DESC, ALIAS) \
1155     PARAM_IN(double, ID, DESC, ALIAS, 0.0, true)
1156 
1157 /**
1158  * Define a required string parameter.
1159  *
1160  * The parameter must then be specified on the command line with --ID=value.
1161  *
1162  * @param ID Name of the parameter.
1163  * @param DESC Quick description of the parameter (1-2 sentences).  Don't use
1164  *      printing macros like PRINT_PARAM_STRING() or PRINT_DATASET() or others
1165  *      here---it will cause problems.
1166  * @param ALIAS An alias for the parameter (one letter).
1167  *
1168  * @see mlpack::IO, BINDING_NAME(), BINDING_SHORT_DESC(), BINDING_LONG_DESC(),
1169  * BINDING_EXAMPLE() and BINDING_SEE_ALSO().
1170  *
1171  * @bug
1172  * The __COUNTER__ variable is used in most cases to guarantee a unique global
1173  * identifier for options declared using the PARAM_*() macros. However, not all
1174  * compilers have this support--most notably, gcc < 4.3. In that case, the
1175  * __LINE__ macro is used as an attempt to get a unique global identifier, but
1176  * collisions are still possible, and they produce bizarre error messages.  See
1177  * https://github.com/mlpack/mlpack/issues/100 for more information.
1178  */
1179 #define PARAM_STRING_IN_REQ(ID, DESC, ALIAS) \
1180     PARAM_IN(std::string, ID, DESC, ALIAS, "", true)
1181 
1182 /**
1183  * Define a required vector parameter.
1184  *
1185  * The parameter must then be specified on the command line with
1186  * --ID=value1,value2,value3.
1187  *
1188  * @param T Type of the parameter.
1189  * @param ID Name of the parameter.
1190  * @param DESC Quick description of the parameter (1-2 sentences).  Don't use
1191  *      printing macros like PRINT_PARAM_STRING() or PRINT_DATASET() or others
1192  *      here---it will cause problems.
1193  * @param ALIAS An alias for the parameter (one letter).
1194  *
1195  * @see mlpack::IO, BINDING_NAME(), BINDING_SHORT_DESC(), BINDING_LONG_DESC(),
1196  * BINDING_EXAMPLE() and BINDING_SEE_ALSO().
1197  *
1198  * @bug
1199  * The __COUNTER__ variable is used in most cases to guarantee a unique global
1200  * identifier for options declared using the PARAM_*() macros. However, not all
1201  * compilers have this support--most notably, gcc < 4.3. In that case, the
1202  * __LINE__ macro is used as an attempt to get a unique global identifier, but
1203  * collisions are still possible, and they produce bizarre error messages.  See
1204  * https://github.com/mlpack/mlpack/issues/100 for more information.
1205  */
1206 #define PARAM_VECTOR_IN_REQ(T, ID, DESC, ALIAS) \
1207     PARAM_IN(std::vector<T>, ID, DESC, ALIAS, std::vector<T>(), true);
1208 
1209 /**
1210  * Define an input parameter.  Don't use this function; use the other ones above
1211  * that call it.  Note that we are using the __LINE__ macro for naming these
1212  * actual parameters when __COUNTER__ does not exist, which is a bit of an ugly
1213  * hack... but this is the preprocessor, after all.  We don't have much choice
1214  * other than ugliness.
1215  *
1216  * @param T Type of the parameter.
1217  * @param ID Name of the parameter.
1218  * @param DESC Description of the parameter (1-2 sentences).  Don't use
1219  *      printing macros like PRINT_PARAM_STRING() or PRINT_DATASET() or others
1220  *      here---it will cause problems.
1221  * @param ALIAS Alias for this parameter (one letter).
1222  * @param DEF Default value of the parameter.
1223  * @param REQ Whether or not parameter is required (boolean value).
1224  */
1225 #ifdef __COUNTER__
1226   #define PARAM_IN(T, ID, DESC, ALIAS, DEF, REQ) \
1227       static mlpack::util::Option<T> \
1228       JOIN(io_option_dummy_object_in_, __COUNTER__) \
1229       (DEF, ID, DESC, ALIAS, #T, REQ, true, false, testName);
1230 
1231   #define PARAM_OUT(T, ID, DESC, ALIAS, DEF, REQ) \
1232       static mlpack::util::Option<T> \
1233       JOIN(io_option_dummy_object_out_, __COUNTER__) \
1234       (DEF, ID, DESC, ALIAS, #T, REQ, false, false, testName);
1235 
1236   #define PARAM_MATRIX(ID, DESC, ALIAS, REQ, TRANS, IN) \
1237       static mlpack::util::Option<arma::mat> \
1238       JOIN(io_option_dummy_matrix_, __COUNTER__) \
1239       (arma::mat(), ID, DESC, ALIAS, "arma::mat", \
1240       REQ, IN, !TRANS, testName);
1241 
1242   #define PARAM_UMATRIX(ID, DESC, ALIAS, REQ, TRANS, IN) \
1243       static mlpack::util::Option<arma::Mat<size_t>> \
1244       JOIN(io_option_dummy_umatrix_, __COUNTER__) \
1245       (arma::Mat<size_t>(), ID, DESC, ALIAS, "arma::Mat<size_t>", \
1246       REQ, IN, !TRANS, testName);
1247 
1248   #define PARAM_COL(ID, DESC, ALIAS, REQ, TRANS, IN) \
1249       static mlpack::util::Option<arma::vec> \
1250       JOIN(io_option_dummy_col_, __COUNTER__) \
1251       (arma::vec(), ID, DESC, ALIAS, "arma::vec", \
1252       REQ, IN, !TRANS, testName);
1253 
1254   #define PARAM_UCOL(ID, DESC, ALIAS, REQ, TRANS, IN) \
1255       static mlpack::util::Option<arma::Col<size_t>> \
1256       JOIN(io_option_dummy_ucol_, __COUNTER__) \
1257       (arma::Col<size_t>(), ID, DESC, ALIAS, "arma::Col<size_t>", \
1258       REQ, IN, !TRANS, testName);
1259 
1260   #define PARAM_ROW(ID, DESC, ALIAS, REQ, TRANS, IN) \
1261       static mlpack::util::Option<arma::rowvec> \
1262       JOIN(io_option_dummy_row_, __COUNTER__) \
1263       (arma::rowvec(), ID, DESC, ALIAS, "arma::rowvec", \
1264       REQ, IN, !TRANS, testName);
1265 
1266   #define PARAM_UROW(ID, DESC, ALIAS, REQ, TRANS, IN) \
1267       static mlpack::util::Option<arma::Row<size_t>> \
1268       JOIN(io_option_dummy_urow_, __COUNTER__) \
1269       (arma::Row<size_t>(), ID, DESC, ALIAS, "arma::Row<size_t>", \
1270       REQ, IN, !TRANS, testName);
1271 
1272   // There are no uses of required models, so that is not an option to this
1273   // macro (it would be easy to add).
1274   #define PARAM_MODEL(TYPE, ID, DESC, ALIAS, REQ, IN) \
1275       static mlpack::util::Option<TYPE*> \
1276       JOIN(io_option_dummy_model_, __COUNTER__) \
1277       (nullptr, ID, DESC, ALIAS, #TYPE, REQ, IN, false, testName);
1278 #else
1279   // We have to do some really bizarre stuff since __COUNTER__ isn't defined. I
1280   // don't think we can absolutely guarantee success, but it should be "good
1281   // enough".  We use the __LINE__ macro and the type of the parameter to try
1282   // and get a good guess at something unique.
1283   #define PARAM_IN(T, ID, DESC, ALIAS, DEF, REQ) \
1284       static mlpack::util::Option<T> \
1285       JOIN(JOIN(io_option_dummy_object_in_, __LINE__), opt) \
1286       (DEF, ID, DESC, ALIAS, #T, REQ, true, false, testName);
1287 
1288   #define PARAM_OUT(T, ID, DESC, ALIAS, DEF, REQ) \
1289       static mlpack::util::Option<T> \
1290       JOIN(JOIN(io_option_dummy_object_out_, __LINE__), opt) \
1291       (DEF, ID, DESC, ALIAS, #T, REQ, false, false, testName);
1292 
1293   #define PARAM_MATRIX(ID, DESC, ALIAS, REQ, TRANS, IN) \
1294       static mlpack::util::Option<arma::mat> \
1295       JOIN(JOIN(io_option_dummy_object_matrix_, __LINE__), opt) \
1296       (arma::mat(), ID, DESC, ALIAS, "arma::mat", REQ, IN, !TRANS, \
1297       testName);
1298 
1299   #define PARAM_UMATRIX(ID, DESC, ALIAS, REQ, TRANS, IN) \
1300       static mlpack::util::Option<arma::Mat<size_t>> \
1301       JOIN(JOIN(io_option_dummy_object_umatrix_, __LINE__), opt) \
1302       (arma::Mat<size_t>(), ID, DESC, ALIAS, "arma::Mat<size_t>", REQ, IN, \
1303       !TRANS, testName);
1304 
1305   #define PARAM_COL(ID, DESC, ALIAS, REQ, TRANS, IN) \
1306       static mlpack::util::Option<arma::vec> \
1307       JOIN(io_option_dummy_object_col_, __LINE__) \
1308       (arma::vec(), ID, DESC, ALIAS, "arma::vec", REQ, IN, !TRANS, \
1309       testName);
1310 
1311   #define PARAM_UCOL(ID, DESC, ALIAS, REQ, TRANS, IN) \
1312       static mlpack::util::Option<arma::Col<size_t>> \
1313       JOIN(io_option_dummy_object_ucol_, __LINE__) \
1314       (arma::Col<size_t>(), ID, DESC, ALIAS, "arma::Col<size_t>", REQ, IN, \
1315       !TRANS, testName);
1316 
1317   #define PARAM_ROW(ID, DESC, ALIAS, REQ, TRANS, IN) \
1318       static mlpack::util::Option<arma::rowvec> \
1319       JOIN(io_option_dummy_object_row_, __LINE__) \
1320       (arma::rowvec(), ID, DESC, ALIAS, "arma::rowvec", REQ, IN, !TRANS, \
1321       testName);
1322 
1323   #define PARAM_UROW(ID, DESC, ALIAS, REQ, TRANS, IN) \
1324       static mlpack::util::Option<arma::Row<size_t>> \
1325       JOIN(io_option_dummy_object_urow_, __LINE__) \
1326       (arma::Row<size_t>(), ID, DESC, ALIAS, "arma::Row<size_t>", REQ, IN, \
1327       !TRANS, testName);
1328 
1329   #define PARAM_MODEL(TYPE, ID, DESC, ALIAS, REQ, IN) \
1330       static mlpack::util::Option<TYPE*> \
1331       JOIN(JOIN(io_option_dummy_object_model_, __LINE__), opt) \
1332       (nullptr, ID, DESC, ALIAS, #TYPE, REQ, IN, false, \
1333       testName);
1334 #endif
1335 
1336 #endif
1337