18 #ifndef MLPACK_CORE_UTIL_MLPACK_MAIN_HPP
19 #define MLPACK_CORE_UTIL_MLPACK_MAIN_HPP
21 #define BINDING_TYPE_CLI 0
22 #define BINDING_TYPE_TEST 1
23 #define BINDING_TYPE_PYX 2
24 #define BINDING_TYPE_JL 3
25 #define BINDING_TYPE_GO 4
26 #define BINDING_TYPE_R 5
27 #define BINDING_TYPE_MARKDOWN 128
28 #define BINDING_TYPE_UNKNOWN -1
31 #define BINDING_TYPE BINDING_TYPE_UNKNOWN
34 #if (BINDING_TYPE == BINDING_TYPE_CLI) // This is a command-line executable.
37 #define BINDING_MATRIX_TRANSPOSED true
46 #define PRINT_PARAM_STRING mlpack::bindings::cli::ParamString
52 #define PRINT_PARAM_VALUE mlpack::bindings::cli::PrintValue
61 #define PRINT_CALL mlpack::bindings::cli::ProgramCall
67 #define PRINT_DATASET mlpack::bindings::cli::PrintDataset
73 #define PRINT_MODEL mlpack::bindings::cli::PrintModel
79 #define BINDING_IGNORE_CHECK mlpack::bindings::cli::IgnoreCheck
95 static void mlpackMain();
97 int main(
int argc,
char** argv)
114 #elif(BINDING_TYPE == BINDING_TYPE_TEST) // This is a unit test.
117 #define BINDING_MATRIX_TRANSPOSED false
124 #define PRINT_PARAM_STRING(A) std::string(" ")
125 #define PRINT_PARAM_VALUE(A, B) std::string(" ")
126 #define PRINT_DATASET(A) std::string(" ")
127 #define PRINT_MODEL(A) std::string(" ")
136 #define PRINT_CALL(...) std::string(" ")
142 #define BINDING_IGNORE_CHECK mlpack::bindings::tests::IgnoreCheck
156 #elif(BINDING_TYPE == BINDING_TYPE_PYX) // This is a Python binding.
159 #define BINDING_MATRIX_TRANSPOSED true
168 #define PRINT_PARAM_STRING mlpack::bindings::python::ParamString
174 #define PRINT_PARAM_VALUE mlpack::bindings::python::PrintValue
180 #define PRINT_DATASET mlpack::bindings::python::PrintDataset
186 #define PRINT_MODEL mlpack::bindings::python::PrintModel
195 #define PRINT_CALL mlpack::bindings::python::ProgramCall
201 #define BINDING_IGNORE_CHECK mlpack::bindings::python::IgnoreCheck
216 #define BINDING_NAME(NAME) static \
217 mlpack::util::ProgramName \
218 io_programname_dummy_object = mlpack::util::ProgramName(NAME); \
220 namespace bindings { \
222 std::string programName = NAME; \
227 PARAM_FLAG(
"verbose",
"Display informational messages and the full list of "
228 "parameters and timers at the end of execution.",
"v");
229 PARAM_FLAG(
"copy_all_inputs",
"If specified, all input parameters will be deep"
230 " copied before the method is run. This is useful for debugging problems "
231 "where the input parameters are being modified by the algorithm, but can "
232 "slow down the code.",
"");
236 #elif(BINDING_TYPE == BINDING_TYPE_JL) // This is a Julia binding.
239 #define BINDING_MATRIX_TRANSPOSED true
244 #define PRINT_PARAM_STRING mlpack::bindings::julia::ParamString
245 #define PRINT_PARAM_VALUE mlpack::bindings::julia::PrintValue
246 #define PRINT_DATASET mlpack::bindings::julia::PrintDataset
247 #define PRINT_MODEL mlpack::bindings::julia::PrintModel
248 #define PRINT_CALL mlpack::bindings::julia::ProgramCall
249 #define BINDING_IGNORE_CHECK mlpack::bindings::julia::IgnoreCheck
264 #define BINDING_NAME(NAME) static \
265 mlpack::util::ProgramName \
266 io_programname_dummy_object = mlpack::util::ProgramName(NAME); \
268 namespace bindings { \
270 std::string programName = NAME; \
275 PARAM_FLAG(
"verbose",
"Display informational messages and the full list of "
276 "parameters and timers at the end of execution.",
"v");
280 #elif(BINDING_TYPE == BINDING_TYPE_GO) // This is a Go binding.
283 #define BINDING_MATRIX_TRANSPOSED true
288 #define PRINT_PARAM_STRING mlpack::bindings::go::ParamString
289 #define PRINT_PARAM_VALUE mlpack::bindings::go::PrintValue
290 #define PRINT_DATASET mlpack::bindings::go::PrintDataset
291 #define PRINT_MODEL mlpack::bindings::go::PrintModel
292 #define PRINT_CALL mlpack::bindings::go::ProgramCall
293 #define BINDING_IGNORE_CHECK mlpack::bindings::go::IgnoreCheck
308 #define BINDING_NAME(NAME) static \
309 mlpack::util::ProgramName \
310 io_programname_dummy_object = mlpack::util::ProgramName(NAME); \
312 namespace bindings { \
314 std::string programName = NAME; \
319 PARAM_FLAG(
"verbose",
"Display informational messages and the full list of "
320 "parameters and timers at the end of execution.",
"v");
324 #elif(BINDING_TYPE == BINDING_TYPE_R) // This is a R binding.
327 #define BINDING_MATRIX_TRANSPOSED true
332 #define PRINT_PARAM_STRING mlpack::bindings::r::ParamString
333 #define PRINT_PARAM_VALUE mlpack::bindings::r::PrintValue
334 #define PRINT_DATASET mlpack::bindings::r::PrintDataset
335 #define PRINT_MODEL mlpack::bindings::r::PrintModel
336 #define PRINT_CALL(...) mlpack::bindings::r::ProgramCall(false, __VA_ARGS__)
337 #define BINDING_IGNORE_CHECK mlpack::bindings::r::IgnoreCheck
351 PARAM_FLAG(
"verbose",
"Display informational messages and the full list of "
352 "parameters and timers at the end of execution.",
"v");
356 #elif BINDING_TYPE == BINDING_TYPE_MARKDOWN
361 #ifndef MARKDOWN_BINDING_NAME
362 #error "MARKDOWN_BINDING_NAME must be defined when BINDING_TYPE is Markdown!"
366 #define BINDING_MATRIX_TRANSPOSED true
375 #define PRINT_PARAM_STRING mlpack::bindings::markdown::ParamString
381 #define PRINT_PARAM_VALUE mlpack::bindings::markdown::PrintValue
387 #define PRINT_DATASET mlpack::bindings::markdown::PrintDataset
393 #define PRINT_MODEL mlpack::bindings::markdown::PrintModel
402 #define PRINT_CALL mlpack::bindings::markdown::ProgramCall
408 #define BINDING_IGNORE_CHECK mlpack::bindings::markdown::IgnoreCheck
411 #define BINDING_MATRIX_TRANSPOSED true
426 #undef BINDING_SHORT_DESC
427 #undef BINDING_LONG_DESC
428 #undef BINDING_EXAMPLE
429 #undef BINDING_SEE_ALSO
431 #define BINDING_NAME(NAME) static \
432 mlpack::bindings::markdown::ProgramNameWrapper \
433 io_programname_dummy_object = \
434 mlpack::bindings::markdown::ProgramNameWrapper( \
435 MARKDOWN_BINDING_NAME, NAME);
437 #define BINDING_SHORT_DESC(SHORT_DESC) static \
438 mlpack::bindings::markdown::ShortDescriptionWrapper \
439 io_programshort_desc_dummy_object = \
440 mlpack::bindings::markdown::ShortDescriptionWrapper( \
441 MARKDOWN_BINDING_NAME, SHORT_DESC);
443 #define BINDING_LONG_DESC(LONG_DESC) static \
444 mlpack::bindings::markdown::LongDescriptionWrapper \
445 io_programlong_desc_dummy_object = \
446 mlpack::bindings::markdown::LongDescriptionWrapper( \
447 MARKDOWN_BINDING_NAME, []() { return std::string(LONG_DESC); });
450 #define BINDING_EXAMPLE(EXAMPLE) static \
451 mlpack::bindings::markdown::ExampleWrapper \
452 JOIN(io_programexample_dummy_object_, __COUNTER__) = \
453 mlpack::bindings::markdown::ExampleWrapper(MARKDOWN_BINDING_NAME, \
454 []() { return(std::string(EXAMPLE)); });
456 #define BINDING_SEE_ALSO(DESCRIPTION, LINK) static \
457 mlpack::bindings::markdown::SeeAlsoWrapper \
458 JOIN(io_programsee_also_dummy_object_, __COUNTER__) = \
459 mlpack::bindings::markdown::SeeAlsoWrapper(MARKDOWN_BINDING_NAME, \
462 #define BINDING_EXAMPLE(EXAMPLE) static \
463 mlpack::bindings::markdown::ExampleWrapper \
464 JOIN(JOIN(io_programexample_dummy_object_, __LINE__), opt) = \
465 mlpack::bindings::markdown::ExampleWrapper(MARKDOWN_BINDING_NAME, \
466 []() { return(std::string(EXAMPLE)); });
468 #define BINDING_SEE_ALSO(DESCRIPTION, LINK) static \
469 mlpack::bindings::markdown::SeeAlsoWrapper \
470 JOIN(JOIN(io_programsee_also_dummy_object_, __LINE__), opt) = \
471 mlpack::bindings::markdown::SeeAlsoWrapper(MARKDOWN_BINDING_NAME, \
475 PARAM_FLAG(
"verbose",
"Display informational messages and the full list of "
476 "parameters and timers at the end of execution.",
"v");
479 PARAM_FLAG(
"help",
"Default help info.",
"h");
481 PARAM_FLAG(
"version",
"Display the version of mlpack.",
"V");
484 PARAM_FLAG(
"copy_all_inputs",
"If specified, all input parameters will be deep"
485 " copied before the method is run. This is useful for debugging problems "
486 "where the input parameters are being modified by the algorithm, but can "
487 "slow down the code.",
"");
491 #error "Unknown binding type! Be sure BINDING_TYPE is defined if you are " \
492 "including <mlpack/core/util/mlpack_main.hpp>.";
void EndProgram()
Handle command-line program termination.
The Markdown option class.
void ParseCommandLine(int argc, char **argv)
Parse the command line, setting all of the options inside of the CLI object to their appropriate give...
static void EnableTiming()
Enable timing of mlpack programs.
#define PARAM_STRING_IN(ID, DESC, ALIAS, DEF)
Define a string input parameter.
#define PARAM_FLAG(ID, DESC, ALIAS)
Define a flag parameter.
A static object whose constructor registers a parameter with the IO class.
A static object whose constructor registers a parameter with the IO class.
static void Start(const std::string &name)
Start the given timer.
src mlpack core util version hpp VERSION_HPP_CONTENTS string(REGEX REPLACE".*#define MLPACK_VERSION_MAJOR ([0-9]+).*""\\1"MLPACK_VERSION_MAJOR"${VERSION_HPP_CONTENTS}") string(REGEX REPLACE".* MLPACK_VERSION_MINOR "$