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
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
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
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
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
336 #error "BINDING_NAME must be defined when BINDING_TYPE is Markdown!"
340 #define BINDING_MATRIX_TRANSPOSED true
349 #define PRINT_PARAM_STRING mlpack::bindings::markdown::ParamString
355 #define PRINT_PARAM_VALUE mlpack::bindings::markdown::PrintValue
361 #define PRINT_DATASET mlpack::bindings::markdown::PrintDataset
367 #define PRINT_MODEL mlpack::bindings::markdown::PrintModel
376 #define PRINT_CALL mlpack::bindings::markdown::ProgramCall
382 #define BINDING_IGNORE_CHECK mlpack::bindings::markdown::IgnoreCheck
385 #define BINDING_MATRIX_TRANSPOSED true
400 #define PROGRAM_INFO(NAME, SHORT_DESC, DESC, ...) static \
401 mlpack::bindings::markdown::ProgramDocWrapper \
402 cli_programdoc_dummy_object = \
403 mlpack::bindings::markdown::ProgramDocWrapper(BINDING_NAME, NAME, \
404 SHORT_DESC, []() { return DESC; }, { __VA_ARGS__ }); \
406 PARAM_FLAG(
"verbose",
"Display informational messages and the full list of "
407 "parameters and timers at the end of execution.",
"v");
410 PARAM_FLAG(
"help",
"Default help info.",
"h");
412 PARAM_FLAG(
"version",
"Display the version of mlpack.",
"V");
415 PARAM_FLAG(
"copy_all_inputs",
"If specified, all input parameters will be deep"
416 " copied before the method is run. This is useful for debugging problems "
417 "where the input parameters are being modified by the algorithm, but can "
418 "slow down the code.",
"");
422 #error "Unknown binding type! Be sure BINDING_TYPE is defined if you are " \
423 "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.
string(REGEX REPLACE".*#define MLPACK_VERSION_MINOR ([0-9]+).*""\\1"MLPACK_VERSION_MINOR"${VERSION_HPP_CONTENTS}") string(REGEX REPLACE".* "\\1" MLPACK_VERSION_PATCH "$