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