mlpack  3.0.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
mlpack_main.hpp
Go to the documentation of this file.
1 
18 #ifndef MLPACK_CORE_UTIL_MLPACK_MAIN_HPP
19 #define MLPACK_CORE_UTIL_MLPACK_MAIN_HPP
20 
21 #define BINDING_TYPE_CLI 0
22 #define BINDING_TYPE_TEST 1
23 #define BINDING_TYPE_PYX 2
24 #define BINDING_TYPE_UNKNOWN -1
25 
26 #ifndef BINDING_TYPE
27 #define BINDING_TYPE BINDING_TYPE_UNKNOWN
28 #endif
29 
30 #if (BINDING_TYPE == BINDING_TYPE_CLI) // This is a command-line executable.
31 
34 
35 #define PRINT_PARAM_STRING mlpack::bindings::cli::ParamString
36 #define PRINT_PARAM_VALUE mlpack::bindings::cli::PrintValue
37 #define PRINT_CALL mlpack::bindings::cli::ProgramCall
38 #define PRINT_DATASET mlpack::bindings::cli::PrintDataset
39 #define PRINT_MODEL mlpack::bindings::cli::PrintModel
40 #define BINDING_IGNORE_CHECK mlpack::bindings::cli::IgnoreCheck
41 
42 namespace mlpack {
43 namespace util {
44 
45 template<typename T>
47 
48 }
49 }
50 
51 static const std::string testName = "";
55 
56 static void mlpackMain(); // This is typically defined after this include.
57 
58 int main(int argc, char** argv)
59 {
60  // Parse the command-line options; put them into CLI.
62  // Enable timing.
64 
65  // A "total_time" timer is run by default for each mlpack program.
66  mlpack::Timer::Start("total_time");
67 
68  mlpackMain();
69 
70  // Print output options, print verbose information, save model parameters,
71  // clean up, and so forth.
73 }
74 
75 #elif(BINDING_TYPE == BINDING_TYPE_TEST) // This is a unit test.
76 
80 
81 // These functions will do nothing.
82 #define PRINT_PARAM_STRING(A) std::string(" ")
83 #define PRINT_PARAM_VALUE(A, B) std::string(" ")
84 #define PRINT_DATASET(A) std::string(" ")
85 #define PRINT_MODEL(A) std::string(" ")
86 #define PRINT_CALL(...) std::string(" ")
87 #define BINDING_IGNORE_CHECK mlpack::bindings::tests::IgnoreCheck
88 
89 namespace mlpack {
90 namespace util {
91 
92 template<typename T>
94 
95 }
96 }
97 
98 // testName symbol should be defined in each binding test file
100 
101 #undef PROGRAM_INFO
102 #define PROGRAM_INFO(NAME, DESC) static mlpack::util::ProgramDoc \
103  cli_programdoc_dummy_object = mlpack::util::ProgramDoc(NAME, \
104  []() { return DESC; });
105 
106 #elif(BINDING_TYPE == BINDING_TYPE_PYX) // This is a Python binding.
107 
110 
111 #define PRINT_PARAM_STRING mlpack::bindings::python::ParamString
112 #define PRINT_PARAM_VALUE mlpack::bindings::python::PrintValue
113 #define PRINT_DATASET mlpack::bindings::python::PrintDataset
114 #define PRINT_MODEL mlpack::bindings::python::PrintModel
115 #define PRINT_CALL mlpack::bindings::python::ProgramCall
116 #define BINDING_IGNORE_CHECK mlpack::bindings::python::IgnoreCheck
117 
118 namespace mlpack {
119 namespace util {
120 
121 template<typename T>
123 
124 }
125 }
126 
127 static const std::string testName = "";
129 
130 #undef PROGRAM_INFO
131 #define PROGRAM_INFO(NAME, DESC) static mlpack::util::ProgramDoc \
132  cli_programdoc_dummy_object = mlpack::util::ProgramDoc(NAME, \
133  []() { return DESC; }); \
134  namespace mlpack { \
135  namespace bindings { \
136  namespace python { \
137  std::string programName = NAME; \
138  } \
139  } \
140  }
141 
142 PARAM_FLAG("verbose", "Display informational messages and the full list of "
143  "parameters and timers at the end of execution.", "v");
144 PARAM_FLAG("copy_all_inputs", "If specified, all input parameters will be deep"
145  " copied before the method is run. This is useful for debugging problems "
146  "where the input parameters are being modified by the algorithm, but can "
147  "slow down the code.", "");
148 
149 // Nothing else needs to be defined---the binding will use mlpackMain() as-is.
150 
151 #else
152 
153 #error "Unknown binding type! Be sure BINDING_TYPE is defined if you are " \
154  "including <mlpack/core/util/mlpack_main.hpp>.";
155 
156 #endif
157 
158 #include "param_checks.hpp"
159 
160 #endif
void EndProgram()
Handle command-line program termination.
Definition: end_program.hpp:26
void ParseCommandLine(int argc, char **argv)
Parse the command line, setting all of the options inside of the CLI object to their appropriate give...
The Python option class.
Definition: py_option.hpp:36
static void EnableTiming()
Enable timing of mlpack programs.
#define PARAM_FLAG(ID, DESC, ALIAS)
Define a flag parameter.
Definition: param.hpp:70
A static object whose constructor registers a parameter with the CLI class.
Definition: cli_option.hpp:47
A static object whose constructor registers a parameter with the CLI class.
Definition: test_option.hpp:40
static void Start(const std::string &name)
Start the given timer.