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