13 #ifndef MLPACK_BINDINGS_PYTHON_PRINT_OUTPUT_PROCESSING_HPP 14 #define MLPACK_BINDINGS_PYTHON_PRINT_OUTPUT_PROCESSING_HPP 29 void PrintOutputProcessing(
32 const bool onlyOutput,
33 const typename std::enable_if<!arma::is_arma_type<T>::value>::type* = 0,
35 const typename std::enable_if<!std::is_same<T,
36 std::tuple<data::DatasetInfo, arma::mat>>::value>::type* = 0)
38 const std::string prefix(indent,
' ');
47 std::cout << prefix <<
"result = " <<
"IO.GetParam[" << GetCythonType<T>(d)
48 <<
"](\"" << d.
name <<
"\")";
49 if (GetCythonType<T>(d) ==
"string")
51 std::cout << std::endl << prefix <<
"result = result.decode(\"UTF-8\")";
53 else if (GetCythonType<T>(d) ==
"vector[string]")
55 std::cout << std::endl << prefix
56 <<
"result = [x.decode(\"UTF-8\") for x in result]";
66 std::cout << prefix <<
"result['" << d.
name <<
"'] = IO.GetParam[" 67 << GetCythonType<T>(d) <<
"](\"" << d.
name <<
"\")" << std::endl;
68 if (GetCythonType<T>(d) ==
"string")
70 std::cout << prefix <<
"result['" << d.
name <<
"'] = result['" << d.
name 71 <<
"'].decode(\"UTF-8\")" << std::endl;
73 else if (GetCythonType<T>(d) ==
"vector[string]")
75 std::cout << prefix <<
"result['" << d.
name <<
"'] = [x.decode(\"UTF-8\")" 76 <<
" for x in result['" << d.
name <<
"']]" << std::endl;
85 void PrintOutputProcessing(
88 const bool onlyOutput,
89 const typename std::enable_if<arma::is_arma_type<T>::value>::type* = 0)
91 const std::string prefix(indent,
' ');
102 std::cout << prefix <<
"result = arma_numpy." << GetArmaType<T>()
103 <<
"_to_numpy_" << GetNumpyTypeChar<T>() <<
"(IO.GetParam[" 104 << GetCythonType<T>(d) <<
"](\"" << d.
name <<
"\"))" << std::endl;
116 std::cout << prefix <<
"result['" << d.
name 117 <<
"'] = arma_numpy." << GetArmaType<T>() <<
"_to_numpy_" 118 << GetNumpyTypeChar<T>() <<
"(IO.GetParam[" << GetCythonType<T>(d)
119 <<
"]('" << d.
name <<
"'))" << std::endl;
127 void PrintOutputProcessing(
130 const bool onlyOutput,
131 const typename std::enable_if<std::is_same<T,
132 std::tuple<data::DatasetInfo, arma::mat>>::value>::type* = 0)
134 const std::string prefix(indent,
' ');
145 std::cout << prefix <<
"result = arma_numpy.mat_to_numpy_" 146 << GetNumpyTypeChar<arma::mat>()
147 <<
"(GetParamWithInfo[arma.Mat[double]]('" << d.
name <<
"'))" 158 std::cout << prefix <<
"result['" << d.
name 159 <<
"'] = arma_numpy.mat_to_numpy_" << GetNumpyTypeChar<arma::mat>()
160 <<
"(GetParamWithInfo[arma.Mat[double]]('" << d.
name <<
"'))" 169 void PrintOutputProcessing(
172 const bool onlyOutput,
173 const typename std::enable_if<!arma::is_arma_type<T>::value>::type* = 0,
177 std::string strippedType, printedType, defaultsType;
178 StripType(d.
cppType, strippedType, printedType, defaultsType);
180 const std::string prefix(indent,
' ');
190 std::cout << prefix <<
"result = " << strippedType <<
"Type()" << std::endl;
191 std::cout << prefix <<
"(<" << strippedType <<
"Type?> result).modelptr = " 192 <<
"GetParamPtr[" << strippedType <<
"]('" << d.
name <<
"')" 201 std::map<std::string, util::ParamData>& parameters =
IO::Parameters();
202 for (
auto it = parameters.begin(); it != parameters.end(); ++it)
208 std::cout << prefix <<
"if (<" << strippedType
209 <<
"Type> result).modelptr" << d.
name <<
" == (<" << strippedType
210 <<
"Type> " << data.
name <<
").modelptr:" << std::endl;
211 std::cout << prefix <<
" (<" << strippedType
212 <<
"Type> result).modelptr = <" << strippedType <<
"*> 0" 214 std::cout << prefix <<
" result = " << data.
name << std::endl;
218 std::cout << prefix <<
"if " << data.
name <<
" is not None:" 220 std::cout << prefix <<
" if (<" << strippedType
221 <<
"Type> result).modelptr" << d.
name <<
" == (<" << strippedType
222 <<
"Type> " << data.
name <<
").modelptr:" << std::endl;
223 std::cout << prefix <<
" (<" << strippedType
224 <<
"Type> result).modelptr = <" << strippedType <<
"*> 0" 226 std::cout << prefix <<
" result = " << data.
name << std::endl;
238 std::cout << prefix <<
"result['" << d.
name <<
"'] = " << strippedType
239 <<
"Type()" << std::endl;
240 std::cout << prefix <<
"(<" << strippedType <<
"Type?> result['" << d.
name 241 <<
"']).modelptr = GetParamPtr[" << strippedType <<
"]('" << d.
name 242 <<
"')" << std::endl;
250 std::map<std::string, util::ParamData>& parameters =
IO::Parameters();
251 for (
auto it = parameters.begin(); it != parameters.end(); ++it)
257 std::cout << prefix <<
"if (<" << strippedType <<
"Type> result['" 258 << d.
name <<
"']).modelptr == (<" << strippedType <<
"Type> " 259 << data.
name <<
").modelptr:" << std::endl;
260 std::cout << prefix <<
" (<" << strippedType <<
"Type> result['" 261 << d.
name <<
"']).modelptr = <" << strippedType <<
"*> 0" 263 std::cout << prefix <<
" result['" << d.
name <<
"'] = " << data.
name 268 std::cout << prefix <<
"if " << data.
name <<
" is not None:" 270 std::cout << prefix <<
" if (<" << strippedType <<
"Type> result['" 271 << d.
name <<
"']).modelptr == (<" << strippedType <<
"Type> " 272 << data.
name <<
").modelptr:" << std::endl;
273 std::cout << prefix <<
" (<" << strippedType <<
"Type> result['" 274 << d.
name <<
"']).modelptr = <" << strippedType <<
"*> 0" 276 std::cout << prefix <<
" result['" << d.
name <<
"'] = " << data.
name 302 std::tuple<size_t, bool>* tuple = (std::tuple<size_t, bool>*) input;
304 PrintOutputProcessing<typename std::remove_pointer<T>::type>(d,
305 std::get<0>(*tuple), std::get<1>(*tuple));
Definition: has_serialize.hpp:47
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
The core includes that mlpack expects; standard C++ includes and Armadillo.
std::string cppType
The true name of the type, as it would be written in C++.
Definition: param_data.hpp:84
This structure holds all of the information about a single parameter, including its value (which is s...
Definition: param_data.hpp:52
static std::map< std::string, util::ParamData > & Parameters()
Return a modifiable list of parameters that IO knows about.
Definition: io.cpp:154
std::string name
Name of this parameter.
Definition: param_data.hpp:56
bool required
True if this option is required.
Definition: param_data.hpp:71