13 #ifndef MLPACK_BINDINGS_PYTHON_PRINT_DOC_FUNCTIONS_IMPL_HPP 14 #define MLPACK_BINDINGS_PYTHON_PRINT_DOC_FUNCTIONS_IMPL_HPP 25 inline std::string GetBindingName(
const std::string& bindingName)
28 return bindingName +
"()";
34 inline std::string PrintImport(
const std::string& bindingName)
36 return "from mlpack import " + bindingName;
42 inline std::string PrintInputOptionInfo()
50 inline std::string PrintOutputOptionInfo()
52 return "Results are returned in a Python dictionary. The keys of the " 53 "dictionary are the names of the output parameters.";
60 inline std::string PrintValue(
const T& value,
bool quotes)
62 std::ostringstream oss;
75 inline std::string PrintValue(
const std::vector<T>& value,
bool quotes)
77 std::ostringstream oss;
84 for (
size_t i = 1; i < value.size(); ++i)
85 oss <<
", " << value[i];
95 inline std::string PrintValue(
const bool& value,
bool quotes)
99 else if (quotes && !value)
101 else if (!quotes && value)
110 inline std::string PrintDefault(
const std::string& paramName)
113 throw std::invalid_argument(
"unknown parameter " + paramName +
"!");
117 std::string defaultValue;
119 (
void*) &defaultValue);
125 std::string PrintInputOptions() {
return ""; }
132 template<
typename T,
typename... Args>
133 std::string PrintInputOptions(
const std::string& paramName,
138 std::string result =
"";
145 std::ostringstream oss;
146 if (paramName !=
"lambda")
147 oss << paramName <<
"=";
149 oss << paramName <<
"_=";
157 throw std::runtime_error(
"Unknown parameter '" + paramName +
"' " +
158 "encountered while assembling documentation! Check BINDING_LONG_DESC()" 159 +
" and BINDING_EXAMPLE() declaration.");
163 std::string rest = PrintInputOptions(args...);
164 if (rest !=
"" && result !=
"")
165 result +=
", " + rest;
166 else if (result ==
"")
173 inline std::string PrintOutputOptions() {
return ""; }
175 template<
typename T,
typename... Args>
176 std::string PrintOutputOptions(
const std::string& paramName,
181 std::string result =
"";
188 std::ostringstream oss;
189 oss <<
">>> " << value <<
" = output['" << paramName <<
"']";
196 throw std::runtime_error(
"Unknown parameter '" + paramName +
"' " +
197 "encountered while assembling documentation! Check BINDING_LONG_DESC()" 198 +
" and BINDING_EXAMPLE() declaration.");
202 std::string rest = PrintOutputOptions(args...);
203 if (rest !=
"" && result !=
"")
215 template<
typename... Args>
216 std::string ProgramCall(
const std::string& programName, Args... args)
218 std::ostringstream oss;
222 std::ostringstream ossOutput;
223 ossOutput << PrintOutputOptions(args...);
224 if (ossOutput.str() !=
"")
226 oss << programName <<
"(";
229 oss << PrintInputOptions(args...);
232 std::string call = oss.str();
236 oss << PrintOutputOptions(args...);
238 return util::HyphenateString(call, 2);
240 return util::HyphenateString(call, 2) +
"\n" + oss.str();
247 inline std::string ProgramCall(
const std::string& programName)
249 std::ostringstream oss;
253 std::map<std::string, util::ParamData>& parameters =
IO::Parameters();
254 bool hasOutput =
false;
255 for (
auto it = parameters.begin(); it != parameters.end(); ++it)
257 if (!it->second.input)
267 oss << programName <<
"(";
271 for (
auto it = parameters.begin(); it != parameters.end(); ++it)
273 if (!it->second.input || (it->second.persistent &&
274 it->second.name !=
"verbose"))
283 if (it->second.name !=
"lambda")
284 oss << it->second.name <<
"=";
286 oss << it->second.name <<
"_=";
290 it->second, NULL, (
void*) &value);
295 std::string result = util::HyphenateString(oss.str(), 8);
301 for (
auto it = parameters.begin(); it != parameters.end(); ++it)
303 if (it->second.input)
307 oss << std::endl <<
">>> " << it->second.name <<
" = d['" 308 << it->second.name <<
"']";
317 inline std::string PrintModel(
const std::string& modelName)
319 return "'" + modelName +
"'";
326 inline std::string PrintDataset(
const std::string& datasetName)
328 return "'" + datasetName +
"'";
335 inline std::string ProgramCallClose()
344 inline std::string ParamString(
const std::string& paramName)
349 if (paramName ==
"lambda")
350 return "'" + paramName +
"_'";
352 return "'" + paramName +
"'";
360 inline std::string ParamString(
const std::string& paramName,
const T& value)
362 std::ostringstream oss;
363 if (paramName ==
"lambda")
364 oss << paramName <<
"_=" << value;
366 oss << paramName <<
"=" << value;
370 inline bool IgnoreCheck(
const std::string& paramName)
375 inline bool IgnoreCheck(
const std::vector<std::string>& constraints)
377 for (
size_t i = 0; i < constraints.size(); ++i)
386 inline bool IgnoreCheck(
387 const std::vector<std::pair<std::string, bool>>& constraints,
388 const std::string& paramName)
390 for (
size_t i = 0; i < constraints.size(); ++i)
std::string tname
Type information of this parameter.
Definition: param_data.hpp:61
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: cv.hpp:1
bool input
True if this option is an input option (otherwise, it is output).
Definition: param_data.hpp:73
static IO & GetSingleton()
Retrieve the singleton.
Definition: io.cpp:147
This structure holds all of the information about a single parameter, including its value (which is s...
Definition: param_data.hpp:52
#define TYPENAME(x)
The TYPENAME macro is used internally to convert a type into a string.
Definition: param_data.hpp:22
static std::map< std::string, util::ParamData > & Parameters()
Return a modifiable list of parameters that IO knows about.
Definition: io.cpp:154