mlpack_main.hpp
Go to the documentation of this file.
1 
9 #ifndef MLPACK_BINDINGS_CLI_MLPACK_MAIN_HPP
10 #define MLPACK_BINDINGS_CLI_MLPACK_MAIN_HPP
11 
12 #ifndef BINDING_TYPE
13  #error "BINDING_TYPE not defined! Don't include this file directly!"
14 #endif
15 #if BINDING_TYPE != BINDING_TYPE_CLI
16  #error "BINDING_TYPE is not set to BINDING_TYPE_CLI!"
17 #endif
18 
19 // Matrices are transposed on load/save.
20 #define BINDING_MATRIX_TRANSPOSED true
21 
24 
29 #define PRINT_PARAM_STRING(x) mlpack::bindings::cli::ParamString( \
30  STRINGIFY(BINDING_NAME), x)
31 
36 #define PRINT_PARAM_VALUE mlpack::bindings::cli::PrintValue
37 
42 #define PRINT_DATASET mlpack::bindings::cli::PrintDataset
43 
48 #define PRINT_MODEL mlpack::bindings::cli::PrintModel
49 
57 #define PRINT_CALL mlpack::bindings::cli::ProgramCall
58 
63 #define BINDING_IGNORE_CHECK mlpack::bindings::cli::IgnoreCheck
64 
70 #define BINDING_MIN_LABEL 0
71 
72 
73 namespace mlpack {
74 namespace util {
75 
76 template<typename T>
78 
79 }
80 }
81 
86 
87 // Forward definition of the binding function.
89 
90 // Define the main function that will be used by this binding.
91 int main(int argc, char** argv)
92 {
93  // Parse the command-line options; put them into CLI.
94  mlpack::util::Params params =
96  // Create a new timer object for this call.
97  mlpack::util::Timers timers;
98  timers.Enabled() = true;
100 
101  // A "total_time" timer is run by default for each mlpack program.
102  timers.Start("total_time");
103  BINDING_FUNCTION(params, timers);
104  timers.Stop("total_time");
105 
106  // Print output options, print verbose information, save model parameters,
107  // clean up, and so forth.
108  mlpack::bindings::cli::EndProgram(params, timers);
109 }
110 
111 // Add default parameters that are included in every program.
112 PARAM_GLOBAL(bool, "help", "Default help info.", "h", "bool", false, true,
113  false, false);
114 PARAM_GLOBAL(std::string, "info", "Print help on a specific option.", "",
115  "std::string", false, true, false, "");
116 PARAM_GLOBAL(bool, "verbose", "Display informational messages and the full "
117  "list of parameters and timers at the end of execution.", "v", "bool",
118  false, true, false, false);
119 PARAM_GLOBAL(bool, "version", "Display the version of mlpack.", "V", "bool",
120  false, true, false, false);
121 
122 #endif
mlpack::util::Params ParseCommandLine(int argc, char **argv, const char *bindingName="")
Parse the command line, setting all of the options inside of the CLI object to their appropriate give...
Linear algebra utility functions, generally performed on matrices or vectors.
void Stop(const std::string &timerName, const std::thread::id &threadId=std::thread::id())
Halts the timer, and replaces its value with the delta time from its start.
void BINDING_FUNCTION(mlpack::util::Params &, mlpack::util::Timers &)
int main(int argc, char **argv)
Definition: mlpack_main.hpp:91
void Start(const std::string &timerName, const std::thread::id &threadId=std::thread::id())
Initializes a timer, available like a normal value specified on the command line. ...
PARAM_GLOBAL(bool, "help", "Default help info.", "h", "bool", false, true, false, false)
static void EnableTiming()
Enable timing of mlpack programs.
A static object whose constructor registers a parameter with the IO class.
Definition: cli_option.hpp:48
void EndProgram(util::Params &params, util::Timers &timers)
Handle command-line program termination.
Definition: end_program.hpp:26
The Params class holds all information about the parameters passed to a specific binding.
Definition: params.hpp:20
std::atomic< bool > & Enabled()
Modify whether or not timing is enabled.
Definition: timers.hpp:165