mlpack 3.4.2
print_method_init.hpp
Go to the documentation of this file.
1
13#ifndef MLPACK_BINDINGS_GO_PRINT_METHOD_INIT_HPP
14#define MLPACK_BINDINGS_GO_PRINT_METHOD_INIT_HPP
15
16#include <mlpack/prereqs.hpp>
17#include "get_go_type.hpp"
18#include "strip_type.hpp"
20
21namespace mlpack {
22namespace bindings {
23namespace go {
24
28template<typename T>
31 const size_t indent,
32 const typename boost::disable_if<arma::is_arma_type<T>>::type* = 0,
33 const typename boost::disable_if<data::HasSerialize<T>>::type* = 0,
34 const typename boost::disable_if<std::is_same<T,
35 std::tuple<data::DatasetInfo, arma::mat>>>::type* = 0)
36{
37 const std::string prefix(indent, ' ');
38
39 std::string def = "nil";
40 if (std::is_same<T, bool>::value)
41 def = "false";
42
43 // Capitalize the first letter of parameter name so it is
44 // of exported type in Go.
45 std::string name = d.name;
46 std::string goParamName = name;
47 if (!name.empty())
48 {
49 goParamName = util::CamelCase(goParamName, false);
50 }
51
52 // Only print param that are not required.
53 if (!d.required)
54 {
55 if (d.cppType == "std::string")
56 {
57 std::string value = boost::any_cast<std::string>(d.value);
58 std::cout << prefix << goParamName << ": \""
59 << value << "\"," << std::endl;
60 }
61 else if (d.cppType == "double")
62 {
63 double value = boost::any_cast<double>(d.value);
64 std::cout << prefix << goParamName << ": " << value << "," << std::endl;
65 }
66 else if (d.cppType == "int")
67 {
68 int value = boost::any_cast<int>(d.value);
69 std::cout << prefix << goParamName << ": " << value << "," << std::endl;
70 }
71 else if (d.cppType == "bool")
72 {
73 bool value = boost::any_cast<bool>(d.value);
74 if (value == 0)
75 std::cout << prefix << goParamName << ": false," << std::endl;
76 else
77 std::cout << prefix << goParamName << ": true," << std::endl;
78 }
79 }
80}
81
85template<typename T>
88 const size_t indent,
89 const typename boost::enable_if<arma::is_arma_type<T>>::type* = 0)
90{
91 const std::string prefix(indent, ' ');
92
93 std::string def = "nil";
94 if (std::is_same<T, bool>::value)
95 def = "false";
96
97 // Capitalize the first letter of parameter name so it is
98 // of exported type in Go.
99 std::string name = d.name;
100 std::string goParamName = name;
101 if (!name.empty())
102 {
103 goParamName = util::CamelCase(goParamName, false);
104 }
105
106 // Only print param that are not required.
107 if (!d.required)
108 {
109 std::cout << prefix << goParamName << ": " << def << ","
110 << std::endl;
111 }
112}
113
117template<typename T>
120 const size_t indent,
121 const typename boost::enable_if<std::is_same<T,
122 std::tuple<data::DatasetInfo, arma::mat>>>::type* = 0)
123{
124 const std::string prefix(indent, ' ');
125
126 std::string def = "nil";
127 if (std::is_same<T, bool>::value)
128 def = "false";
129
130 // Capitalize the first letter of parameter name so it is
131 // of exported type in Go.
132 std::string name = d.name;
133 std::string goParamName = name;
134 if (!name.empty())
135 {
136 goParamName = util::CamelCase(goParamName, false);
137 }
138
139 // Only print param that are not required.
140 if (!d.required)
141 {
142 std::cout << prefix << goParamName << ": " << def << ","
143 << std::endl;
144 }
145}
146
150template<typename T>
153 const size_t indent,
154 const typename boost::disable_if<arma::is_arma_type<T>>::type* = 0,
155 const typename boost::enable_if<data::HasSerialize<T>>::type* = 0)
156{
157 const std::string prefix(indent, ' ');
158
159 std::string def = "nil";
160 if (std::is_same<T, bool>::value)
161 def = "false";
162
163 // Capitalize the first letter of parameter name so it is
164 // of exported type in Go.
165 std::string name = d.name;
166 std::string goParamName = name;
167 if (!name.empty())
168 {
169 goParamName = util::CamelCase(goParamName, false);
170 }
171
172 // Only print param that are not required.
173 if (!d.required)
174 {
175 std::cout << prefix << goParamName << ": " << def << ","
176 << std::endl;
177 }
178}
179
191template<typename T>
193 const void* input,
194 void* /* output */)
195{
196 PrintMethodInit<typename std::remove_pointer<T>::type>(d,
197 *((size_t*) input));
198}
199
200} // namespace go
201} // namespace bindings
202} // namespace mlpack
203
204#endif
go
Definition: CMakeLists.txt:6
void PrintMethodInit(util::ParamData &d, const size_t indent, 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::disable_if< std::is_same< T, std::tuple< data::DatasetInfo, arma::mat > > >::type *=0)
Print parameter with it's default value for a standard option type.
std::string CamelCase(std::string s, bool lower)
Given an snake_case like, e.g., "logistic_regression", return CamelCase(e.g.
Definition: camel_case.hpp:26
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: cv.hpp:1
The core includes that mlpack expects; standard C++ includes and Armadillo.
This structure holds all of the information about a single parameter, including its value (which is s...
Definition: param_data.hpp:53
boost::any value
The actual value that is held.
Definition: param_data.hpp:82
bool required
True if this option is required.
Definition: param_data.hpp:71
std::string name
Name of this parameter.
Definition: param_data.hpp:56
std::string cppType
The true name of the type, as it would be written in C++.
Definition: param_data.hpp:84