mlpack
default_param_impl.hpp
Go to the documentation of this file.
1 
12 #ifndef MLPACK_BINDINGS_PYTHON_DEFAULT_PARAM_IMPL_HPP
13 #define MLPACK_BINDINGS_PYTHON_DEFAULT_PARAM_IMPL_HPP
14 
15 #include "default_param.hpp"
16 
17 namespace mlpack {
18 namespace bindings {
19 namespace python {
20 
24 template<typename T>
25 std::string DefaultParamImpl(
27  const typename std::enable_if<!arma::is_arma_type<T>::value>::type* /* junk */,
28  const typename std::enable_if<!util::IsStdVector<T>::value>::type* /* junk */,
29  const typename std::enable_if<!data::HasSerialize<T>::value>::type* /* junk */,
30  const typename std::enable_if<!std::is_same<T,
31  std::string>::value>::type*,
32  const typename std::enable_if<!std::is_same<T,
33  std::tuple<mlpack::data::DatasetInfo, arma::mat>>::value>::type* /* junk */)
34 {
35  std::ostringstream oss;
36  if (std::is_same<T, bool>::value)
37  oss << "False";
38  else
39  oss << boost::any_cast<T>(data.value);
40 
41  return oss.str();
42 }
43 
47 template<typename T>
48 std::string DefaultParamImpl(
50  const typename std::enable_if<util::IsStdVector<T>::value>::type* /* junk */)
51 {
52  // Print each element in an array delimited by square brackets.
53  std::ostringstream oss;
54  const T& vector = boost::any_cast<T>(data.value);
55  oss << "[";
56  if (std::is_same<T, std::vector<std::string>>::value)
57  {
58  if (vector.size() > 0)
59  {
60  for (size_t i = 0; i < vector.size() - 1; ++i)
61  {
62  oss << "'" << vector[i] << "', ";
63  }
64 
65  oss << "'" << vector[vector.size() - 1] << "'";
66  }
67 
68  oss << "]";
69  }
70  else
71  {
72  if (vector.size() > 0)
73  {
74  for (size_t i = 0; i < vector.size() - 1; ++i)
75  {
76  oss << vector[i] << ", ";
77  }
78 
79  oss << vector[vector.size() - 1];
80  }
81 
82  oss << "]";
83  }
84  return oss.str();
85 }
86 
90 template<typename T>
91 std::string DefaultParamImpl(
93  const typename std::enable_if<std::is_same<T, std::string>::value>::type*)
94 {
95  const std::string& s = *boost::any_cast<std::string>(&data.value);
96  return "'" + s + "'";
97 }
98 
103 template<typename T>
104 std::string DefaultParamImpl(
105  util::ParamData& /* data */,
106  const typename std::enable_if<
107  arma::is_arma_type<T>::value ||
108  std::is_same<T, std::tuple<mlpack::data::DatasetInfo,
109  arma::mat>>::value>::type* /* junk */)
110 {
111  // Get the filename and return it, or return an empty string.
112  if (std::is_same<T, arma::rowvec>::value ||
113  std::is_same<T, arma::vec>::value)
114  {
115  return "np.empty([0])";
116  }
117  else if (std::is_same<T, arma::Col<size_t>>::value ||
118  std::is_same<T, arma::Row<size_t>>::value)
119  {
120  return "np.empty([0], dtype=np.uint64)";
121  }
122  else if (std::is_same<T, arma::Mat<size_t>>::value)
123  {
124  return "np.empty([0, 0], dtype=np.uint64)";
125  }
126  else
127  {
128  return "np.empty([0, 0])";
129  }
130 }
131 
135 template<typename T>
136 std::string DefaultParamImpl(
137  util::ParamData& /* data */,
138  const typename std::enable_if<!arma::is_arma_type<T>::value>::type* /* junk */,
139  const typename std::enable_if<data::HasSerialize<T>::value>::type* /* junk */)
140 {
141  return "None";
142 }
143 
144 } // namespace python
145 } // namespace bindings
146 } // namespace mlpack
147 
148 #endif
Auxiliary information for a dataset, including mappings to/from strings (or other types) and the data...
Definition: dataset_mapper.hpp:41
Definition: has_serialize.hpp:47
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: cv.hpp:1
This structure holds all of the information about a single parameter, including its value (which is s...
Definition: param_data.hpp:52
Metaprogramming structure for vector detection.
Definition: is_std_vector.hpp:23
boost::any value
The actual value that is held.
Definition: param_data.hpp:82