mlpack  3.4.2
add_to_cli11.hpp
Go to the documentation of this file.
1 
12 #ifndef MLPACK_BINDINGS_CLI_ADD_TO_CLI11_HPP
13 #define MLPACK_BINDINGS_CLI_ADD_TO_CLI11_HPP
14 
17 #include "map_parameter_name.hpp"
18 
19 #include "third_party/CLI/CLI11.hpp"
20 
21 namespace mlpack {
22 namespace bindings {
23 namespace cli {
24 
32 template<typename T>
33 void AddToCLI11(const std::string& cliName,
34  util::ParamData& param,
35  CLI::App& app,
36  const typename boost::disable_if<std::is_same<T,
37  bool>>::type* = 0,
38  const typename boost::disable_if<
39  arma::is_arma_type<T>>::type* = 0,
40  const typename boost::disable_if<
41  data::HasSerialize<T>>::type* = 0,
42  const typename boost::enable_if<std::is_same<T,
43  std::tuple<mlpack::data::DatasetInfo,
44  arma::mat>>>::type* = 0)
45 {
46  app.add_option_function<std::string>(cliName.c_str(),
47  [&param](const std::string& value)
48  {
49  using TupleType = std::tuple<T, typename ParameterType<T>::type>;
50  TupleType& tuple = *boost::any_cast<TupleType>(&param.value);
51  std::get<1>(tuple) = boost::any_cast<std::string>(value);
52  param.wasPassed = true;
53  },
54  param.desc.c_str());
55 }
56 
64 template<typename T>
65 void AddToCLI11(const std::string& cliName,
66  util::ParamData& param,
67  CLI::App& app,
68  const typename boost::disable_if<std::is_same<T,
69  bool>>::type* = 0,
70  const typename boost::disable_if<
71  arma::is_arma_type<T>>::type* = 0,
72  const typename boost::enable_if<
73  data::HasSerialize<T>>::type* = 0,
74  const typename boost::disable_if<std::is_same<T,
75  std::tuple<mlpack::data::DatasetInfo,
76  arma::mat>>>::type* = 0)
77 {
78  app.add_option_function<std::string>(cliName.c_str(),
79  [&param](const std::string& value)
80  {
81  using TupleType = std::tuple<T*, typename ParameterType<T>::type>;
82  TupleType& tuple = *boost::any_cast<TupleType>(&param.value);
83  std::get<1>(tuple) = boost::any_cast<std::string>(value);
84  param.wasPassed = true;
85  },
86  param.desc.c_str());
87 }
88 
96 template<typename T>
97 void AddToCLI11(const std::string& cliName,
98  util::ParamData& param,
99  CLI::App& app,
100  const typename boost::disable_if<
101  std::is_same<T, bool>>::type* = 0,
102  const typename boost::enable_if<
103  arma::is_arma_type<T>>::type* = 0,
104  const typename boost::disable_if<std::is_same<T,
105  std::tuple<mlpack::data::DatasetInfo,
106  arma::mat>>>::type* = 0)
107 {
108  app.add_option_function<std::string>(cliName.c_str(),
109  [&param](const std::string& value)
110  {
111  using TupleType = std::tuple<T, typename ParameterType<T>::type>;
112  TupleType& tuple = *boost::any_cast<TupleType>(&param.value);
113  std::get<1>(tuple) = boost::any_cast<std::string>(value);
114  param.wasPassed = true;
115  },
116  param.desc.c_str());
117 }
118 
126 template<typename T>
127 void AddToCLI11(const std::string& cliName,
128  util::ParamData& param,
129  CLI::App& app,
130  const typename boost::disable_if<
131  std::is_same<T, bool>>::type* = 0,
132  const typename boost::disable_if<
133  arma::is_arma_type<T>>::type* = 0,
134  const typename boost::disable_if<
135  data::HasSerialize<T>>::type* = 0,
136  const typename boost::disable_if<std::is_same<T,
137  std::tuple<mlpack::data::DatasetInfo,
138  arma::mat>>>::type* = 0)
139 {
140  app.add_option_function<T>(cliName.c_str(),
141  [&param](const T& value)
142  {
143  param.value = value;
144  param.wasPassed = true;
145  },
146  param.desc.c_str());
147 }
148 
156 template<typename T>
157 void AddToCLI11(const std::string& cliName,
158  util::ParamData& param,
159  CLI::App& app,
160  const typename boost::enable_if<
161  std::is_same<T, bool>>::type* = 0,
162  const typename boost::disable_if<
163  arma::is_arma_type<T>>::type* = 0,
164  const typename boost::disable_if<
165  data::HasSerialize<T>>::type* = 0,
166  const typename boost::disable_if<std::is_same<T,
167  std::tuple<mlpack::data::DatasetInfo,
168  arma::mat>>>::type* = 0)
169 {
170  app.add_flag_function(cliName.c_str(),
171  [&param](const T& value)
172  {
173  param.value = value;
174  param.wasPassed = true;
175  },
176  param.desc.c_str());
177 }
178 
187 template<typename T>
189  const void* /* input */,
190  void* output)
191 {
192  // Cast CLI::App object.
193  CLI::App* app = (CLI::App*) output;
194 
195  // Generate the name to be given to CLI11.
196  const std::string mappedName =
197  MapParameterName<typename std::remove_pointer<T>::type>(param.name);
198  std::string cliName = (param.alias != '\0') ?
199  "-" + std::string(1, param.alias) + ",--" + mappedName :
200  "--" + mappedName;
201 
202  // Note that we have to add the option as type equal to the mapped type, not
203  // the true type of the option.
204  AddToCLI11<typename std::remove_pointer<T>::type>(
205  cliName, param, *app);
206 }
207 
208 } // namespace cli
209 } // namespace bindings
210 } // namespace mlpack
211 
212 #endif
if
if(NOT BUILD_GO_SHLIB) macro(add_go_binding name) endmacro() return() endif() endmacro() macro(post_go_setup) if(BUILD_GO_BINDINGS) file(APPEND "$
Definition: CMakeLists.txt:3
include
include(${CMAKE_SOURCE_DIR}/CMake/FindRModule.cmake) find_package(R 4.0) if(NOT R_FOUND) set(R_NOT_FOUND_MSG "$
Definition: CMakeLists.txt:28
mlpack::data::format
format
Define the formats we can read through boost::serialization.
Definition: format.hpp:21
mlpack::util::ParamData::value
boost::any value
The actual value that is held.
Definition: param_data.hpp:82
mlpack::bindings::cli::AddToCLI11
void AddToCLI11(const std::string &cliName, util::ParamData &param, CLI::App &app, const typename boost::disable_if< std::is_same< T, bool >>::type *=0, const typename boost::disable_if< arma::is_arma_type< T >>::type *=0, const typename boost::disable_if< data::HasSerialize< T >>::type *=0, const typename boost::enable_if< std::is_same< T, std::tuple< mlpack::data::DatasetInfo, arma::mat >>>::type *=0)
Add a tuple option to CLI11.
Definition: add_to_cli11.hpp:33
mlpack::data::Load
bool Load(const std::string &filename, arma::Mat< eT > &matrix, const bool fatal=false, const bool transpose=true, const arma::file_type inputLoadType=arma::auto_detect)
Loads a matrix from file, guessing the filetype from the extension.
mlpack::ann
Artificial Neural Network.
Definition: elish_function.hpp:32
is_std_vector.hpp
mlpack::data::Save
bool Save(const std::string &filename, const arma::Mat< eT > &matrix, const bool fatal=false, bool transpose=true, arma::file_type inputSaveType=arma::auto_detect)
Saves a matrix to file, guessing the filetype from the extension.
available
the following modules are not available
Definition: CMakeLists.txt:86
regularization
f To use this form of regularization
Definition: det.txt:370
boost
Set the serialization version of the adaboost class.
Definition: adaboost.hpp:198
mlpack::rl::OneStepQLearning
AsyncLearning< OneStepQLearningWorker< EnvironmentType, NetworkType, UpdaterType, PolicyType >, EnvironmentType, NetworkType, UpdaterType, PolicyType > OneStepQLearning
Convenient typedef for async one step q-learning.
Definition: async_learning.hpp:197
mlpack::util::ParamData
This structure holds all of the information about a single parameter, including its value (which is s...
Definition: param_data.hpp:53
mlpack
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: add_to_cli11.hpp:21
mlpack::util::ParamData::desc
std::string desc
Description of this parameter, if any.
Definition: param_data.hpp:58
mlpack::data::xml
@ xml
Definition: format.hpp:24
mlpack::util::ParamData::wasPassed
bool wasPassed
True if the option was passed to the program.
Definition: param_data.hpp:66
mlpack::util::ParamData::name
std::string name
Name of this parameter.
Definition: param_data.hpp:56
mlpack::ann::SigmoidLayer
BaseLayer< ActivationFunction, InputDataType, OutputDataType > SigmoidLayer
Standard Sigmoid-Layer using the logistic activation function.
Definition: base_layer.hpp:146
map_parameter_name.hpp
now
this option is not available in DET right now
Definition: det.txt:341
set
set(SOURCES add_to_cli11.hpp cli_option.hpp default_param.hpp default_param_impl.hpp delete_allocated_memory.hpp end_program.hpp get_allocated_memory.hpp get_param.hpp get_raw_param.hpp get_printable_param.hpp get_printable_param_impl.hpp get_printable_param_name.hpp get_printable_param_name_impl.hpp get_printable_param_value.hpp get_printable_param_value_impl.hpp in_place_copy.hpp map_parameter_name.hpp output_param.hpp output_param_impl.hpp parameter_type.hpp parse_command_line.hpp print_doc_functions.hpp print_doc_functions_impl.hpp print_help.hpp print_help.cpp print_type_doc.hpp print_type_doc_impl.hpp set_param.hpp string_type_param.hpp string_type_param_impl.hpp) set(DIR_SRCS) foreach(file $
Definition: CMakeLists.txt:3
mlpack::data::HasSerialize
Definition: has_serialize.hpp:46
mlpack::util::ParamData::alias
char alias
Alias for this parameter.
Definition: param_data.hpp:63
mlpack::ann::LayerTraits
This is a template class that can provide information about various layers.
Definition: layer_traits.hpp:30
param_data.hpp
alpha
see subsection cli_alt_reg_tut Alternate DET regularization The usual regularized error f $R_ alpha(t)\f$ of a node \f $t\f$ is given by
Definition: det.txt:344
go
go
Definition: CMakeLists.txt:6
mlpack::data::DatasetMapper
Auxiliary information for a dataset, including mappings to/from strings (or other types) and the data...
Definition: dataset_mapper.hpp:42