get_r_type.hpp
Go to the documentation of this file.
1 
12 #ifndef MLPACK_BINDINGS_R_GET_R_TYPE_HPP
13 #define MLPACK_BINDINGS_R_GET_R_TYPE_HPP
14 
15 #include <mlpack/prereqs.hpp>
18 
19 namespace mlpack {
20 namespace bindings {
21 namespace r {
22 
23 template<typename T>
24 inline std::string GetRType(
25  util::ParamData& /* d */,
26  const typename std::enable_if<!util::IsStdVector<T>::value>::type* = 0,
27  const typename std::enable_if<!data::HasSerialize<T>::value>::type* = 0,
28  const typename std::enable_if<!arma::is_arma_type<T>::value>::type* = 0,
29  const typename std::enable_if<!std::is_same<T,
30  std::tuple<data::DatasetInfo, arma::mat>>::value>::type* = 0)
31 {
32  return "unknown";
33 }
34 
35 template<>
36 inline std::string GetRType<bool>(
37  util::ParamData& /* d */,
38  const typename std::enable_if<!util::IsStdVector<bool>::value>::type*,
39  const typename std::enable_if<!data::HasSerialize<bool>::value>::type*,
40  const typename std::enable_if<!arma::is_arma_type<bool>::value>::type*,
41  const typename std::enable_if<!std::is_same<bool,
42  std::tuple<data::DatasetInfo, arma::mat>>::value>::type*)
43 {
44  return "logical";
45 }
46 
47 template<>
48 inline std::string GetRType<int>(
49  util::ParamData& /* d */,
50  const typename std::enable_if<!util::IsStdVector<int>::value>::type*,
51  const typename std::enable_if<!data::HasSerialize<int>::value>::type*,
52  const typename std::enable_if<!arma::is_arma_type<int>::value>::type*,
53  const typename std::enable_if<!std::is_same<int,
54  std::tuple<data::DatasetInfo, arma::mat>>::value>::type*)
55 {
56  return "integer";
57 }
58 
59 template<>
60 inline std::string GetRType<size_t>(
61  util::ParamData& /* d */,
62  const typename std::enable_if<!util::IsStdVector<size_t>::value>::type*,
63  const typename std::enable_if<!data::HasSerialize<size_t>::value>::type*,
64  const typename std::enable_if<!arma::is_arma_type<size_t>::value>::type*,
65  const typename std::enable_if<!std::is_same<size_t,
66  std::tuple<data::DatasetInfo, arma::mat>>::value>::type*)
67 {
68  return "integer";
69 }
70 
71 template<>
72 inline std::string GetRType<double>(
73  util::ParamData& /* d */,
74  const typename std::enable_if<!util::IsStdVector<double>::value>::type*,
75  const typename std::enable_if<!data::HasSerialize<double>::value>::type*,
76  const typename std::enable_if<!arma::is_arma_type<double>::value>::type*,
77  const typename std::enable_if<!std::is_same<double,
78  std::tuple<data::DatasetInfo, arma::mat>>::value>::type*)
79 {
80  return "numeric";
81 }
82 
83 template<>
84 inline std::string GetRType<std::string>(
85  util::ParamData& /* d */,
86  const typename std::enable_if<
88  const typename std::enable_if<
90  const typename std::enable_if<
91  !arma::is_arma_type<std::string>::value>::type*,
92  const typename std::enable_if<
93  !std::is_same<std::string,
94  std::tuple<data::DatasetInfo, arma::mat>>::value>::type*)
95 {
96  return "character";
97 }
98 
99 template<typename T>
100 inline std::string GetRType(
101  util::ParamData& d,
102  const typename std::enable_if<util::IsStdVector<T>::value>::type* = 0)
103 {
104  return GetRType<typename T::value_type>(d) + " vector";
105 }
106 
107 template<typename T>
108 inline std::string GetRType(
109  util::ParamData& d,
110  const typename std::enable_if<!std::is_same<T,
111  std::tuple<data::DatasetInfo, arma::mat>>::value>::type* = 0,
112  const typename std::enable_if<arma::is_arma_type<T>::value>::type* = 0)
113 {
114  std::string elemType = GetRType<typename T::elem_type>(d);
115  std::string type = "matrix";
116  if (T::is_row)
117  type = "row";
118  else if (T::is_col)
119  type = "column";
120 
121  return elemType + " " + type;
122 }
123 
124 template<typename T>
125 inline std::string GetRType(
126  util::ParamData& /* d */,
127  const typename std::enable_if<std::is_same<T,
128  std::tuple<data::DatasetInfo, arma::mat>>::value>::type* = 0)
129 {
130  return "numeric matrix/data.frame with info";
131 }
132 
133 template<typename T>
134 inline std::string GetRType(
135  util::ParamData& d,
136  const typename std::enable_if<!arma::is_arma_type<T>::value>::type* = 0,
137  const typename std::enable_if<data::HasSerialize<T>::value>::type* = 0)
138 {
139  return util::StripType(d.cppType);
140 }
141 
142 } // namespace r
143 } // namespace bindings
144 } // namespace mlpack
145 
146 #endif
Linear algebra utility functions, generally performed on matrices or vectors.
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:52
std::string GetRType< 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_r_type.hpp:36
std::string GetRType< 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_r_type.hpp:48
Metaprogramming structure for vector detection.
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 GetRType< 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_r_type.hpp:72
std::string cppType
The true name of the type, as it would be written in C++.
Definition: param_data.hpp:81
std::string GetRType< size_t >(util::ParamData &, const typename std::enable_if<!util::IsStdVector< size_t >::value >::type *, const typename std::enable_if<!data::HasSerialize< size_t >::value >::type *, const typename std::enable_if<!arma::is_arma_type< size_t >::value >::type *, const typename std::enable_if<!std::is_same< size_t, std::tuple< data::DatasetInfo, arma::mat >>::value >::type *)
Definition: get_r_type.hpp:60
std::string GetRType(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_r_type.hpp:24