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 
65 
66 namespace mlpack {
67 namespace util {
68 
69 template<typename T>
71 
72 }
73 }
74 
79 
80 // Forward definition of the binding function.
82 
83 // Define the main function that will be used by this binding.
84 int main(int argc, char** argv)
85 {
86  // Parse the command-line options; put them into CLI.
87  mlpack::util::Params params =
89  // Create a new timer object for this call.
90  mlpack::util::Timers timers;
91  timers.Enabled() = true;
93 
94  // A "total_time" timer is run by default for each mlpack program.
95  timers.Start("total_time");
96  BINDING_FUNCTION(params, timers);
97  timers.Stop("total_time");
98 
99  // Print output options, print verbose information, save model parameters,
100  // clean up, and so forth.
101  mlpack::bindings::cli::EndProgram(params, timers);
102 }
103 
104 // Add default parameters that are included in every program.
105 PARAM_GLOBAL(bool, "help", "Default help info.", "h", "bool", false, true,
106  false, false);
107 PARAM_GLOBAL(std::string, "info", "Print help on a specific option.", "",
108  "std::string", false, true, false, "");
109 PARAM_GLOBAL(bool, "verbose", "Display informational messages and the full "
110  "list of parameters and timers at the end of execution.", "v", "bool",
111  false, true, false, false);
112 PARAM_GLOBAL(bool, "version", "Display the version of mlpack.", "V", "bool",
113  false, true, false, false);
114 
115 #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:84
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