get_type.hpp
Go to the documentation of this file.
1 
13 #ifndef MLPACK_BINDINGS_R_GET_TYPE_HPP
14 #define MLPACK_BINDINGS_R_GET_TYPE_HPP
15 
16 #include <mlpack/prereqs.hpp>
19 
20 namespace mlpack {
21 namespace bindings {
22 namespace r {
23 
24 template<typename T>
25 inline std::string GetType(
26  util::ParamData& /* d */,
27  const typename std::enable_if<!util::IsStdVector<T>::value>::type* = 0,
28  const typename std::enable_if<!data::HasSerialize<T>::value>::type* = 0,
29  const typename std::enable_if<!arma::is_arma_type<T>::value>::type* = 0,
30  const typename std::enable_if<!std::is_same<T,
31  std::tuple<data::DatasetInfo, arma::mat>>::value>::type* = 0)
32 {
33  return "unknown";
34 }
35 
36 template<>
37 inline std::string GetType<int>(
38  util::ParamData& /* d */,
39  const typename std::enable_if<!util::IsStdVector<int>::value>::type*,
40  const typename std::enable_if<!data::HasSerialize<int>::value>::type*,
41  const typename std::enable_if<!arma::is_arma_type<int>::value>::type*,
42  const typename std::enable_if<!std::is_same<int,
43  std::tuple<data::DatasetInfo, arma::mat>>::value>::type*)
44 {
45  return "Int";
46 }
47 
48 template<>
49 inline std::string GetType<float>(
50  util::ParamData& /* d */,
51  const typename std::enable_if<!util::IsStdVector<float>::value>::type*,
52  const typename std::enable_if<!data::HasSerialize<float>::value>::type*,
53  const typename std::enable_if<!arma::is_arma_type<float>::value>::type*,
54  const typename std::enable_if<!std::is_same<float,
55  std::tuple<data::DatasetInfo, arma::mat>>::value>::type*)
56 {
57  return "Float";
58 }
59 
60 template<>
61 inline std::string GetType<double>(
62  util::ParamData& /* d */,
63  const typename std::enable_if<!util::IsStdVector<double>::value>::type*,
64  const typename std::enable_if<!data::HasSerialize<double>::value>::type*,
65  const typename std::enable_if<!arma::is_arma_type<double>::value>::type*,
66  const typename std::enable_if<!std::is_same<double,
67  std::tuple<data::DatasetInfo, arma::mat>>::value>::type*)
68 {
69  return "Double";
70 }
71 
72 template<>
73 inline std::string GetType<std::string>(
74  util::ParamData& /* d */,
75  const typename std::enable_if<
77  const typename std::enable_if<
79  const typename std::enable_if<
80  !arma::is_arma_type<std::string>::value>::type*,
81  const typename std::enable_if<!std::is_same<std::string,
82  std::tuple<data::DatasetInfo, arma::mat>>::value>::type*)
83 {
84  return "String";
85 }
86 
87 template<>
88 inline std::string GetType<bool>(
89  util::ParamData& /* d */,
90  const typename std::enable_if<!util::IsStdVector<bool>::value>::type*,
91  const typename std::enable_if<!data::HasSerialize<bool>::value>::type*,
92  const typename std::enable_if<!arma::is_arma_type<bool>::value>::type*,
93  const typename std::enable_if<!std::is_same<bool,
94  std::tuple<data::DatasetInfo, arma::mat>>::value>::type*)
95 {
96  return "Bool";
97 }
98 
99 template<typename T>
100 inline std::string GetType(
101  util::ParamData& d,
102  const typename std::enable_if<util::IsStdVector<T>::value>::type* = 0,
103  const typename std::enable_if<!std::is_same<T,
104  std::tuple<data::DatasetInfo, arma::mat>>::value>::type* = 0)
105 {
106  return "Vec" + GetType<typename T::value_type>(d);
107 }
108 
109 template<typename T>
110 inline std::string GetType(
111  util::ParamData& /* d */,
112  const typename std::enable_if<arma::is_arma_type<T>::value>::type* = 0,
113  const typename std::enable_if<!std::is_same<T,
114  std::tuple<data::DatasetInfo, arma::mat>>::value>::type* = 0)
115 {
116  std::string type = "";
117  if (std::is_same<typename T::elem_type, double>::value)
118  {
119  if (T::is_row)
120  type = "Row";
121  else if (T::is_col)
122  type = "Col";
123  else
124  type = "Mat";
125  }
126  else if (std::is_same<typename T::elem_type, size_t>::value)
127  {
128  if (T::is_row)
129  type = "URow";
130  else if (T::is_col)
131  type = "UCol";
132  else
133  type = "UMat";
134  }
135 
136  return type;
137 }
138 
139 template<typename T>
140 inline std::string GetType(
141  util::ParamData& /* d */,
142  const typename std::enable_if<std::is_same<T,
143  std::tuple<data::DatasetInfo, arma::mat>>::value>::type* = 0)
144 {
145  return "MatWithInfo";
146 }
147 
148 template<typename T>
149 inline std::string GetType(
150  util::ParamData& d,
151  const typename std::enable_if<!arma::is_arma_type<T>::value>::type* = 0,
152  const typename std::enable_if<data::HasSerialize<T>::value>::type* = 0)
153 {
154  return d.cppType;
155 }
156 
167 template<typename T>
168 void GetType(util::ParamData& d,
169  const void* /* input */,
170  void* output)
171 {
172  *((std::string*) output) =
173  GetType<typename std::remove_pointer<T>::type>(d);
174 }
175 
176 } // namespace r
177 } // namespace bindings
178 } // namespace mlpack
179 
180 #endif
Linear algebra utility functions, generally performed on matrices or vectors.
std::string GetType< float >(util::ParamData &, const typename std::enable_if<!util::IsStdVector< float >::value >::type *, const typename std::enable_if<!data::HasSerialize< float >::value >::type *, const typename std::enable_if<!arma::is_arma_type< float >::value >::type *, const typename std::enable_if<!std::is_same< float, std::tuple< data::DatasetInfo, arma::mat >>::value >::type *)
Definition: get_type.hpp:49
The core includes that mlpack expects; standard C++ includes and Armadillo.
std::string GetType< double >(util::ParamData &, const typename std::enable_if<!util::IsStdVector< double >::value >::type *, const typename std::enable_if<!data::HasSerialize< double >::value >::type *, const typename std::enable_if<!arma::is_arma_type< double >::value >::type *, const typename std::enable_if<!std::is_same< double, std::tuple< data::DatasetInfo, arma::mat >>::value >::type *)
Definition: get_type.hpp:61
std::string GetType(util::ParamData &, const typename std::enable_if<!util::IsStdVector< T >::value >::type *=0, const typename std::enable_if<!data::HasSerialize< T >::value >::type *=0, const typename std::enable_if<!arma::is_arma_type< T >::value >::type *=0, const typename std::enable_if<!std::is_same< T, std::tuple< data::DatasetInfo, arma::mat >>::value >::type *=0)
Definition: get_type.hpp:25
This structure holds all of the information about a single parameter, including its value (which is s...
Definition: param_data.hpp:51
Metaprogramming structure for vector detection.
std::string GetType< bool >(util::ParamData &, const typename std::enable_if<!util::IsStdVector< bool >::value >::type *, const typename std::enable_if<!data::HasSerialize< bool >::value >::type *, const typename std::enable_if<!arma::is_arma_type< bool >::value >::type *, const typename std::enable_if<!std::is_same< bool, std::tuple< data::DatasetInfo, arma::mat >>::value >::type *)
Definition: get_type.hpp:88
std::string cppType
The true name of the type, as it would be written in C++.
Definition: param_data.hpp:80
std::string GetType< int >(util::ParamData &, const typename std::enable_if<!util::IsStdVector< int >::value >::type *, const typename std::enable_if<!data::HasSerialize< int >::value >::type *, const typename std::enable_if<!arma::is_arma_type< int >::value >::type *, const typename std::enable_if<!std::is_same< int, std::tuple< data::DatasetInfo, arma::mat >>::value >::type *)
Definition: get_type.hpp:37