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_MARKDOWN 128 27 #define BINDING_TYPE_UNKNOWN -1 30 #define BINDING_TYPE BINDING_TYPE_UNKNOWN 33 #if (BINDING_TYPE == BINDING_TYPE_CLI) // This is a command-line executable. 36 #define BINDING_MATRIX_TRANSPOSED true 45 #define PRINT_PARAM_STRING mlpack::bindings::cli::ParamString 51 #define PRINT_PARAM_VALUE mlpack::bindings::cli::PrintValue 60 #define PRINT_CALL mlpack::bindings::cli::ProgramCall 66 #define PRINT_DATASET mlpack::bindings::cli::PrintDataset 72 #define PRINT_MODEL mlpack::bindings::cli::PrintModel 78 #define BINDING_IGNORE_CHECK mlpack::bindings::cli::IgnoreCheck 89 static const std::string testName =
"";
94 static void mlpackMain();
96 int main(
int argc,
char** argv)
113 #elif(BINDING_TYPE == BINDING_TYPE_TEST) // This is a unit test. 116 #define BINDING_MATRIX_TRANSPOSED false 123 #define PRINT_PARAM_STRING(A) std::string(" ") 124 #define PRINT_PARAM_VALUE(A, B) std::string(" ") 125 #define PRINT_DATASET(A) std::string(" ") 126 #define PRINT_MODEL(A) std::string(" ") 135 #define PRINT_CALL(...) std::string(" ") 141 #define BINDING_IGNORE_CHECK mlpack::bindings::tests::IgnoreCheck 156 #define PROGRAM_INFO(NAME, SHORT_DESC, DESC, ...) \ 157 static mlpack::util::ProgramDoc \ 158 cli_programdoc_dummy_object = mlpack::util::ProgramDoc(NAME, SHORT_DESC, \ 159 []() { return DESC; }, { __VA_ARGS__ }) 161 #elif(BINDING_TYPE == BINDING_TYPE_PYX) // This is a Python binding. 164 #define BINDING_MATRIX_TRANSPOSED true 173 #define PRINT_PARAM_STRING mlpack::bindings::python::ParamString 179 #define PRINT_PARAM_VALUE mlpack::bindings::python::PrintValue 185 #define PRINT_DATASET mlpack::bindings::python::PrintDataset 191 #define PRINT_MODEL mlpack::bindings::python::PrintModel 200 #define PRINT_CALL mlpack::bindings::python::ProgramCall 206 #define BINDING_IGNORE_CHECK mlpack::bindings::python::IgnoreCheck 217 static const std::string testName =
"";
221 #define PROGRAM_INFO(NAME, SHORT_DESC, DESC, ...) \ 222 static mlpack::util::ProgramDoc \ 223 cli_programdoc_dummy_object = mlpack::util::ProgramDoc(NAME, SHORT_DESC, \ 224 []() { return DESC; }, { __VA_ARGS__ }); \ 226 namespace bindings { \ 228 std::string programName = NAME; \ 233 PARAM_FLAG(
"verbose",
"Display informational messages and the full list of " 234 "parameters and timers at the end of execution.",
"v");
235 PARAM_FLAG(
"copy_all_inputs",
"If specified, all input parameters will be deep" 236 " copied before the method is run. This is useful for debugging problems " 237 "where the input parameters are being modified by the algorithm, but can " 238 "slow down the code.",
"");
242 #elif(BINDING_TYPE == BINDING_TYPE_JL) // This is a Julia binding. 245 #define BINDING_MATRIX_TRANSPOSED true 250 #define PRINT_PARAM_STRING mlpack::bindings::julia::ParamString 251 #define PRINT_PARAM_VALUE mlpack::bindings::julia::PrintValue 252 #define PRINT_DATASET mlpack::bindings::julia::PrintDataset 253 #define PRINT_MODEL mlpack::bindings::julia::PrintModel 254 #define PRINT_CALL mlpack::bindings::julia::ProgramCall 255 #define BINDING_IGNORE_CHECK mlpack::bindings::julia::IgnoreCheck 266 static const std::string testName =
"";
270 #define PROGRAM_INFO(NAME, SHORT_DESC, DESC, ...) static \ 271 mlpack::util::ProgramDoc \ 272 cli_programdoc_dummy_object = mlpack::util::ProgramDoc(NAME, SHORT_DESC, \ 273 []() { return DESC; }, { __VA_ARGS__ }); \ 275 namespace bindings { \ 277 std::string programName = NAME; \ 282 PARAM_FLAG(
"verbose",
"Display informational messages and the full list of " 283 "parameters and timers at the end of execution.",
"v");
287 #elif(BINDING_TYPE == BINDING_TYPE_GO) // This is a Go binding. 290 #define BINDING_MATRIX_TRANSPOSED true 295 #define PRINT_PARAM_STRING mlpack::bindings::go::ParamString 296 #define PRINT_PARAM_VALUE mlpack::bindings::go::PrintValue 297 #define PRINT_DATASET mlpack::bindings::go::PrintDataset 298 #define PRINT_MODEL mlpack::bindings::go::PrintModel 299 #define PRINT_CALL mlpack::bindings::go::ProgramCall 300 #define BINDING_IGNORE_CHECK mlpack::bindings::go::IgnoreCheck 311 static const std::string testName =
"";
315 #define PROGRAM_INFO(NAME, SHORT_DESC, DESC, ...) \ 316 static mlpack::util::ProgramDoc \ 317 cli_programdoc_dummy_object = mlpack::util::ProgramDoc(NAME, SHORT_DESC, \ 318 []() { return DESC; }, { __VA_ARGS__ }); \ 320 namespace bindings { \ 322 std::string programName = NAME; \ 327 PARAM_FLAG(
"verbose",
"Display informational messages and the full list of " 328 "parameters and timers at the end of execution.",
"v");
332 #elif BINDING_TYPE == BINDING_TYPE_MARKDOWN 335 #define BINDING_MATRIX_TRANSPOSED true 339 #error "BINDING_NAME must be defined when BINDING_TYPE is Markdown!" 343 #define BINDING_MATRIX_TRANSPOSED true 352 #define PRINT_PARAM_STRING mlpack::bindings::markdown::ParamString 358 #define PRINT_PARAM_VALUE mlpack::bindings::markdown::PrintValue 364 #define PRINT_DATASET mlpack::bindings::markdown::PrintDataset 370 #define PRINT_MODEL mlpack::bindings::markdown::PrintModel 379 #define PRINT_CALL mlpack::bindings::markdown::ProgramCall 385 #define BINDING_IGNORE_CHECK mlpack::bindings::markdown::IgnoreCheck 388 #define BINDING_MATRIX_TRANSPOSED true 403 #define PROGRAM_INFO(NAME, SHORT_DESC, DESC, ...) static \ 404 mlpack::bindings::markdown::ProgramDocWrapper \ 405 cli_programdoc_dummy_object = \ 406 mlpack::bindings::markdown::ProgramDocWrapper(BINDING_NAME, NAME, \ 407 SHORT_DESC, []() { return DESC; }, { __VA_ARGS__ }); \ 409 PARAM_FLAG(
"verbose",
"Display informational messages and the full list of " 410 "parameters and timers at the end of execution.",
"v");
413 PARAM_FLAG(
"help",
"Default help info.",
"h");
415 PARAM_FLAG(
"version",
"Display the version of mlpack.",
"V");
418 PARAM_FLAG(
"copy_all_inputs",
"If specified, all input parameters will be deep" 419 " copied before the method is run. This is useful for debugging problems " 420 "where the input parameters are being modified by the algorithm, but can " 421 "slow down the code.",
"");
425 #error "Unknown binding type! Be sure BINDING_TYPE is defined if you are " \ 426 "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 CLI class.
A static object whose constructor registers a parameter with the CLI class.
static void Start(const std::string &name)
Start the given timer.