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  {
172  MLPACK_COUT_STREAM << " if (!identical(" << d.name << ", NA)) {"
173  << std::endl;
174  MLPACK_COUT_STREAM << " SetParam" << util::StripType(d.cppType)
175  << "Ptr(p, \"" << d.name << "\", " << d.name << ")" << std::endl;
176  MLPACK_COUT_STREAM << " # Add to the list of input models we received."
177  << std::endl;
178  MLPACK_COUT_STREAM << " inputModels <- append(inputModels, " << d.name
179  << ")" << std::endl;
180  MLPACK_COUT_STREAM << " }" << std::endl; // Closing brace.
181  }
182  else
183  {
189  MLPACK_COUT_STREAM << " SetParam" << util::StripType(d.cppType)
190  << "Ptr(p, \"" << d.name << "\", " << d.name << ")" << std::endl;
191  }
192  MLPACK_COUT_STREAM << std::endl; // Extra line is to clear up the code a bit.
193 }
194 
200 template<typename T>
202  const void* /* input */,
203  void* /* output */)
204 {
205  PrintInputProcessing<typename std::remove_pointer<T>::type>(d);
206 }
207 
208 } // namespace r
209 } // namespace bindings
210 } // namespace mlpack
211 
212 #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:51
#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:55
bool required
True if this option is required.
Definition: param_data.hpp:70
std::string cppType
The true name of the type, as it would be written in C++.
Definition: param_data.hpp:80