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_MARKDOWN 128
25 #define BINDING_TYPE_UNKNOWN -1
28 #define BINDING_TYPE BINDING_TYPE_UNKNOWN
31 #if (BINDING_TYPE == BINDING_TYPE_CLI) // This is a command-line executable.
34 #define BINDING_MATRIX_TRANSPOSED true
39 #define PRINT_PARAM_STRING mlpack::bindings::cli::ParamString
40 #define PRINT_PARAM_VALUE mlpack::bindings::cli::PrintValue
41 #define PRINT_CALL mlpack::bindings::cli::ProgramCall
42 #define PRINT_DATASET mlpack::bindings::cli::PrintDataset
43 #define PRINT_MODEL mlpack::bindings::cli::PrintModel
44 #define BINDING_IGNORE_CHECK mlpack::bindings::cli::IgnoreCheck
55 static const std::string testName =
"";
60 static void mlpackMain();
62 int main(
int argc,
char** argv)
79 #elif(BINDING_TYPE == BINDING_TYPE_TEST) // This is a unit test.
82 #define BINDING_MATRIX_TRANSPOSED false
89 #define PRINT_PARAM_STRING(A) std::string(" ")
90 #define PRINT_PARAM_VALUE(A, B) std::string(" ")
91 #define PRINT_DATASET(A) std::string(" ")
92 #define PRINT_MODEL(A) std::string(" ")
93 #define PRINT_CALL(...) std::string(" ")
94 #define BINDING_IGNORE_CHECK mlpack::bindings::tests::IgnoreCheck
109 #define PROGRAM_INFO(NAME, SHORT_DESC, DESC, ...) \
110 static mlpack::util::ProgramDoc \
111 cli_programdoc_dummy_object = mlpack::util::ProgramDoc(NAME, SHORT_DESC, \
112 []() { return DESC; }, { __VA_ARGS__ })
114 #elif(BINDING_TYPE == BINDING_TYPE_PYX) // This is a Python binding.
117 #define BINDING_MATRIX_TRANSPOSED true
122 #define PRINT_PARAM_STRING mlpack::bindings::python::ParamString
123 #define PRINT_PARAM_VALUE mlpack::bindings::python::PrintValue
124 #define PRINT_DATASET mlpack::bindings::python::PrintDataset
125 #define PRINT_MODEL mlpack::bindings::python::PrintModel
126 #define PRINT_CALL mlpack::bindings::python::ProgramCall
127 #define BINDING_IGNORE_CHECK mlpack::bindings::python::IgnoreCheck
138 static const std::string testName =
"";
142 #define PROGRAM_INFO(NAME, SHORT_DESC, DESC, ...) \
143 static mlpack::util::ProgramDoc \
144 cli_programdoc_dummy_object = mlpack::util::ProgramDoc(NAME, SHORT_DESC, \
145 []() { return DESC; }, { __VA_ARGS__ }); \
147 namespace bindings { \
149 std::string programName = NAME; \
154 PARAM_FLAG(
"verbose",
"Display informational messages and the full list of "
155 "parameters and timers at the end of execution.",
"v");
156 PARAM_FLAG(
"copy_all_inputs",
"If specified, all input parameters will be deep"
157 " copied before the method is run. This is useful for debugging problems "
158 "where the input parameters are being modified by the algorithm, but can "
159 "slow down the code.",
"");
163 #elif BINDING_TYPE == BINDING_TYPE_MARKDOWN
167 #error "BINDING_NAME must be defined when BINDING_TYPE is Markdown!"
173 #define PRINT_PARAM_STRING mlpack::bindings::markdown::ParamString
174 #define PRINT_PARAM_VALUE mlpack::bindings::markdown::PrintValue
175 #define PRINT_DATASET mlpack::bindings::markdown::PrintDataset
176 #define PRINT_MODEL mlpack::bindings::markdown::PrintModel
177 #define PRINT_CALL mlpack::bindings::markdown::ProgramCall
178 #define BINDING_IGNORE_CHECK mlpack::bindings::markdown::IgnoreCheck
181 #define BINDING_MATRIX_TRANSPOSED true
196 #define PROGRAM_INFO(NAME, SHORT_DESC, DESC, ...) static \
197 mlpack::bindings::markdown::ProgramDocWrapper \
198 cli_programdoc_dummy_object = \
199 mlpack::bindings::markdown::ProgramDocWrapper(BINDING_NAME, NAME, \
200 SHORT_DESC, []() { return DESC; }, { __VA_ARGS__ }); \
202 PARAM_FLAG(
"verbose",
"Display informational messages and the full list of "
203 "parameters and timers at the end of execution.",
"v");
206 PARAM_FLAG(
"help",
"Default help info.",
"h");
208 PARAM_FLAG(
"version",
"Display the version of mlpack.",
"V");
211 PARAM_FLAG(
"copy_all_inputs",
"If specified, all input parameters will be deep"
212 " copied before the method is run. This is useful for debugging problems "
213 "where the input parameters are being modified by the algorithm, but can "
214 "slow down the code.",
"");
218 #error "Unknown binding type! Be sure BINDING_TYPE is defined if you are " \
219 "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.