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 90 static const std::string testName =
"";
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 212 static const std::string testName =
"";
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.",
"");
233 PARAM_FLAG(
"check_input_matrices",
"If specified, the input matrix is checked for" 234 " NaN and inf values; an exception is thrown if any are found.",
"");
238 #elif(BINDING_TYPE == BINDING_TYPE_JL) // This is a Julia binding. 241 #define BINDING_MATRIX_TRANSPOSED true 246 #define PRINT_PARAM_STRING mlpack::bindings::julia::ParamString 247 #define PRINT_PARAM_VALUE mlpack::bindings::julia::PrintValue 248 #define PRINT_DATASET mlpack::bindings::julia::PrintDataset 249 #define PRINT_MODEL mlpack::bindings::julia::PrintModel 250 #define PRINT_CALL mlpack::bindings::julia::ProgramCall 251 #define BINDING_IGNORE_CHECK mlpack::bindings::julia::IgnoreCheck 262 static const std::string testName =
"";
266 #define BINDING_NAME(NAME) static \ 267 mlpack::util::ProgramName \ 268 io_programname_dummy_object = mlpack::util::ProgramName(NAME); \ 270 namespace bindings { \ 272 std::string programName = NAME; \ 277 PARAM_FLAG(
"verbose",
"Display informational messages and the full list of " 278 "parameters and timers at the end of execution.",
"v");
282 #elif(BINDING_TYPE == BINDING_TYPE_GO) // This is a Go binding. 285 #define BINDING_MATRIX_TRANSPOSED true 290 #define PRINT_PARAM_STRING mlpack::bindings::go::ParamString 291 #define PRINT_PARAM_VALUE mlpack::bindings::go::PrintValue 292 #define PRINT_DATASET mlpack::bindings::go::PrintDataset 293 #define PRINT_MODEL mlpack::bindings::go::PrintModel 294 #define PRINT_CALL mlpack::bindings::go::ProgramCall 295 #define BINDING_IGNORE_CHECK mlpack::bindings::go::IgnoreCheck 306 static const std::string testName =
"";
310 #define BINDING_NAME(NAME) static \ 311 mlpack::util::ProgramName \ 312 io_programname_dummy_object = mlpack::util::ProgramName(NAME); \ 314 namespace bindings { \ 316 std::string programName = NAME; \ 321 PARAM_FLAG(
"verbose",
"Display informational messages and the full list of " 322 "parameters and timers at the end of execution.",
"v");
326 #elif(BINDING_TYPE == BINDING_TYPE_R) // This is a R binding. 329 #define BINDING_MATRIX_TRANSPOSED true 334 #define PRINT_PARAM_STRING mlpack::bindings::r::ParamString 335 #define PRINT_PARAM_VALUE mlpack::bindings::r::PrintValue 336 #define PRINT_DATASET mlpack::bindings::r::PrintDataset 337 #define PRINT_MODEL mlpack::bindings::r::PrintModel 338 #define PRINT_CALL(...) mlpack::bindings::r::ProgramCall(false, __VA_ARGS__) 339 #define BINDING_IGNORE_CHECK mlpack::bindings::r::IgnoreCheck 350 static const std::string testName =
"";
353 PARAM_FLAG(
"verbose",
"Display informational messages and the full list of " 354 "parameters and timers at the end of execution.",
"v");
358 #elif BINDING_TYPE == BINDING_TYPE_MARKDOWN 363 #ifndef MARKDOWN_BINDING_NAME 364 #error "MARKDOWN_BINDING_NAME must be defined when BINDING_TYPE is Markdown!" 368 #define BINDING_MATRIX_TRANSPOSED true 377 #define PRINT_PARAM_STRING mlpack::bindings::markdown::ParamString 383 #define PRINT_PARAM_VALUE mlpack::bindings::markdown::PrintValue 389 #define PRINT_DATASET mlpack::bindings::markdown::PrintDataset 395 #define PRINT_MODEL mlpack::bindings::markdown::PrintModel 404 #define PRINT_CALL mlpack::bindings::markdown::ProgramCall 410 #define BINDING_IGNORE_CHECK mlpack::bindings::markdown::IgnoreCheck 413 #define BINDING_MATRIX_TRANSPOSED true 428 #undef BINDING_SHORT_DESC 429 #undef BINDING_LONG_DESC 430 #undef BINDING_EXAMPLE 431 #undef BINDING_SEE_ALSO 433 #define BINDING_NAME(NAME) static \ 434 mlpack::bindings::markdown::ProgramNameWrapper \ 435 io_programname_dummy_object = \ 436 mlpack::bindings::markdown::ProgramNameWrapper( \ 437 MARKDOWN_BINDING_NAME, NAME); 439 #define BINDING_SHORT_DESC(SHORT_DESC) static \ 440 mlpack::bindings::markdown::ShortDescriptionWrapper \ 441 io_programshort_desc_dummy_object = \ 442 mlpack::bindings::markdown::ShortDescriptionWrapper( \ 443 MARKDOWN_BINDING_NAME, SHORT_DESC); 445 #define BINDING_LONG_DESC(LONG_DESC) static \ 446 mlpack::bindings::markdown::LongDescriptionWrapper \ 447 io_programlong_desc_dummy_object = \ 448 mlpack::bindings::markdown::LongDescriptionWrapper( \ 449 MARKDOWN_BINDING_NAME, []() { return std::string(LONG_DESC); }); 452 #define BINDING_EXAMPLE(EXAMPLE) static \ 453 mlpack::bindings::markdown::ExampleWrapper \ 454 JOIN(io_programexample_dummy_object_, __COUNTER__) = \ 455 mlpack::bindings::markdown::ExampleWrapper(MARKDOWN_BINDING_NAME, \ 456 []() { return(std::string(EXAMPLE)); }); 458 #define BINDING_SEE_ALSO(DESCRIPTION, LINK) static \ 459 mlpack::bindings::markdown::SeeAlsoWrapper \ 460 JOIN(io_programsee_also_dummy_object_, __COUNTER__) = \ 461 mlpack::bindings::markdown::SeeAlsoWrapper(MARKDOWN_BINDING_NAME, \ 464 #define BINDING_EXAMPLE(EXAMPLE) static \ 465 mlpack::bindings::markdown::ExampleWrapper \ 466 JOIN(JOIN(io_programexample_dummy_object_, __LINE__), opt) = \ 467 mlpack::bindings::markdown::ExampleWrapper(MARKDOWN_BINDING_NAME, \ 468 []() { return(std::string(EXAMPLE)); }); 470 #define BINDING_SEE_ALSO(DESCRIPTION, LINK) static \ 471 mlpack::bindings::markdown::SeeAlsoWrapper \ 472 JOIN(JOIN(io_programsee_also_dummy_object_, __LINE__), opt) = \ 473 mlpack::bindings::markdown::SeeAlsoWrapper(MARKDOWN_BINDING_NAME, \ 477 PARAM_FLAG(
"verbose",
"Display informational messages and the full list of " 478 "parameters and timers at the end of execution.",
"v");
481 PARAM_FLAG(
"help",
"Default help info.",
"h");
483 PARAM_FLAG(
"version",
"Display the version of mlpack.",
"V");
486 PARAM_FLAG(
"copy_all_inputs",
"If specified, all input parameters will be deep" 487 " copied before the method is run. This is useful for debugging problems " 488 "where the input parameters are being modified by the algorithm, but can " 489 "slow down the code.",
"");
493 #error "Unknown binding type! Be sure BINDING_TYPE is defined if you are " \ 494 "including <mlpack/core/util/mlpack_main.hpp>."; void EndProgram()
Handle command-line program termination.
Linear algebra utility functions, generally performed on matrices or vectors.
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.