print_input_processing.hpp
Go to the documentation of this file.
1 
12 #ifndef MLPACK_BINDINGS_R_PRINT_INPUT_PROCESSING_IMPL_HPP
13 #define MLPACK_BINDINGS_R_PRINT_INPUT_PROCESSING_IMPL_HPP
14 
16 #include "get_type.hpp"
17 #include <mlpack/prereqs.hpp>
18 
19 namespace mlpack {
20 namespace bindings {
21 namespace r {
22 
26 template<typename T>
28  util::ParamData& d,
29  const typename std::enable_if<!arma::is_arma_type<T>::value>::type* = 0,
30  const typename std::enable_if<!data::HasSerialize<T>::value>::type* = 0,
31  const typename std::enable_if<!std::is_same<T,
32  std::tuple<data::DatasetInfo, arma::mat>>::value>::type* = 0)
33 {
34  if (!d.required)
35  {
43  MLPACK_COUT_STREAM << " if (!identical(" << d.name;
44  if (d.cppType == "bool")
45  {
46  MLPACK_COUT_STREAM << ", FALSE)) {" << std::endl;
47  }
48  else
49  {
50  MLPACK_COUT_STREAM << ", NA)) {" << std::endl;
51  }
52  MLPACK_COUT_STREAM << " SetParam" << GetType<T>(d) << "(p, \""
53  << d.name << "\", " << d.name << ")" << std::endl;
54  MLPACK_COUT_STREAM << " }" << std::endl; // Closing brace.
55  }
56  else
57  {
63  MLPACK_COUT_STREAM << " SetParam" << GetType<T>(d) << "(p, \""
64  << d.name << "\", " << d.name << ")" << std::endl;
65  }
66  MLPACK_COUT_STREAM << std::endl; // Extra line is to clear up the code a bit.
67 }
68 
72 template<typename T>
74  util::ParamData& d,
75  const typename std::enable_if<arma::is_arma_type<T>::value>::type* = 0)
76 {
77  if (!d.required)
78  {
86  MLPACK_COUT_STREAM << " if (!identical(" << d.name << ", NA)) {"
87  << std::endl;
88  MLPACK_COUT_STREAM << " SetParam" << GetType<T>(d) << "(p, \""
89  << d.name << "\", to_matrix(" << d.name << "))" << std::endl;
90  MLPACK_COUT_STREAM << " }" << std::endl; // Closing brace.
91  }
92  else
93  {
99  MLPACK_COUT_STREAM << " SetParam" << GetType<T>(d) << "(p, \""
100  << d.name << "\", to_matrix(" << d.name << "))" << std::endl;
101  }
102  MLPACK_COUT_STREAM << std::endl; // Extra line is to clear up the code a bit.
103 }
104 
108 template<typename T>
110  util::ParamData& d,
111  const typename std::enable_if<std::is_same<T,
112  std::tuple<data::DatasetInfo, arma::mat>>::value>::type* = 0)
113 {
114  if (!d.required)
115  {
125  MLPACK_COUT_STREAM << " if (!identical(" << d.name << ", NA)) {"
126  << std::endl;
127  MLPACK_COUT_STREAM << " " << d.name << " <- to_matrix_with_info("
128  << d.name << ")" << std::endl;
129  MLPACK_COUT_STREAM << " SetParam" << GetType<T>(d) << "(p, \""
130  << d.name << "\", " << d.name << "$info, " << d.name
131  << "$data)" << std::endl;
132  MLPACK_COUT_STREAM << " }" << std::endl; // Closing brace.
133  }
134  else
135  {
143  MLPACK_COUT_STREAM << " " << d.name << " <- to_matrix_with_info("
144  << d.name << ")" << std::endl;
145  MLPACK_COUT_STREAM << " SetParam" << GetType<T>(d) << "(p, \""
146  << d.name << "\", " << d.name << "$info, " << d.name
147  << "$data)" << std::endl;
148  }
149  MLPACK_COUT_STREAM << std::endl; // Extra line is to clear up the code a bit.
150 }
151 
155 template<typename T>
157  util::ParamData& d,
158  const typename std::enable_if<!arma::is_arma_type<T>::value>::type* = 0,
159  const typename std::enable_if<data::HasSerialize<T>::value>::type* = 0)
160 {
161  if (!d.required)
162  {
170  MLPACK_COUT_STREAM << " if (!identical(" << d.name << ", NA)) {"
171  << std::endl;
172  MLPACK_COUT_STREAM << " SetParam" << util::StripType(d.cppType)
173  << "Ptr(p, \"" << d.name << "\", " << d.name << ")" << std::endl;
174  MLPACK_COUT_STREAM << " }" << std::endl; // Closing brace.
175  }
176  else
177  {
183  MLPACK_COUT_STREAM << " SetParam" << util::StripType(d.cppType)
184  << "Ptr(p, \"" << d.name << "\", " << d.name << ")" << std::endl;
185  }
186  MLPACK_COUT_STREAM << std::endl; // Extra line is to clear up the code a bit.
187 }
188 
194 template<typename T>
196  const void* /* input */,
197  void* /* output */)
198 {
199  PrintInputProcessing<typename std::remove_pointer<T>::type>(d);
200 }
201 
202 } // namespace r
203 } // namespace bindings
204 } // namespace mlpack
205 
206 #endif
Linear algebra utility functions, generally performed on matrices or vectors.
The core includes that mlpack expects; standard C++ includes and Armadillo.
void PrintInputProcessing(util::ParamData &d, const typename std::enable_if<!arma::is_arma_type< T >::value >::type *=0, const typename std::enable_if<!data::HasSerialize< T >::value >::type *=0, const typename std::enable_if<!std::is_same< T, std::tuple< data::DatasetInfo, arma::mat >>::value >::type *=0)
Print input processing for a standard option type.
This structure holds all of the information about a single parameter, including its value (which is s...
Definition: param_data.hpp:52
#define MLPACK_COUT_STREAM
Definition: prereqs.hpp:45
std::string StripType(std::string cppType)
Given a C++ type name, turn it into something that has no special characters that can simply be print...
Definition: strip_type.hpp:27
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
std::string cppType
The true name of the type, as it would be written in C++.
Definition: param_data.hpp:81