get_python_type.hpp
Go to the documentation of this file.
1 
13 #ifndef MLPACK_BINDINGS_PYTHON_GET_PYTHON_TYPE_HPP
14 #define MLPACK_BINDINGS_PYTHON_GET_PYTHON_TYPE_HPP
15 
16 #include <mlpack/prereqs.hpp>
18 
19 namespace mlpack {
20 namespace bindings {
21 namespace python {
22 
23 template<typename T>
24 inline std::string GetPythonType(
25  const 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 {
30  return "unknown";
31 }
32 
33 template<>
34 inline std::string GetPythonType<int>(
35  const util::ParamData& /* d */,
36  const typename boost::disable_if<util::IsStdVector<int>>::type*,
37  const typename boost::disable_if<data::HasSerialize<int>>::type*,
38  const typename boost::disable_if<arma::is_arma_type<int>>::type*)
39 {
40  return "int";
41 }
42 
43 template<>
44 inline std::string GetPythonType<float>(
45  const util::ParamData& /* d */,
46  const typename boost::disable_if<util::IsStdVector<float>>::type*,
47  const typename boost::disable_if<data::HasSerialize<float>>::type*,
48  const typename boost::disable_if<arma::is_arma_type<float>>::type*)
49 {
50  return "float";
51 }
52 
53 template<>
54 inline std::string GetPythonType<double>(
55  const util::ParamData& /* d */,
56  const typename boost::disable_if<util::IsStdVector<double>>::type*,
57  const typename boost::disable_if<data::HasSerialize<double>>::type*,
58  const typename boost::disable_if<arma::is_arma_type<double>>::type*)
59 {
60  return "double";
61 }
62 
63 template<>
64 inline std::string GetPythonType<std::string>(
65  const util::ParamData& /* d */,
66  const typename boost::disable_if<util::IsStdVector<std::string>>::type*,
67  const typename boost::disable_if<data::HasSerialize<std::string>>::type*,
68  const typename boost::disable_if<arma::is_arma_type<std::string>>::type*)
69 {
70  return "string";
71 }
72 
73 template<>
74 inline std::string GetPythonType<size_t>(
75  const util::ParamData& /* d */,
76  const typename boost::disable_if<util::IsStdVector<size_t>>::type*,
77  const typename boost::disable_if<data::HasSerialize<size_t>>::type*,
78  const typename boost::disable_if<arma::is_arma_type<size_t>>::type*)
79 {
80  return "size_t";
81 }
82 
83 template<>
84 inline std::string GetPythonType<bool>(
85  const util::ParamData& /* d */,
86  const typename boost::disable_if<util::IsStdVector<bool>>::type*,
87  const typename boost::disable_if<data::HasSerialize<bool>>::type*,
88  const typename boost::disable_if<arma::is_arma_type<bool>>::type*)
89 {
90  return "bool";
91 }
92 
93 template<typename T>
94 inline std::string GetPythonType(
95  const util::ParamData& d,
96  const typename boost::enable_if<util::IsStdVector<T>>::type* = 0)
97 {
98  return "list of " + GetPythonType<typename T::value_type>(d) + "s";
99 }
100 
101 template<typename T>
102 inline std::string GetPythonType(
103  const util::ParamData& /* d */,
104  const typename boost::enable_if<arma::is_arma_type<T>>::type* = 0)
105 {
106  std::string type = "matrix";
107  if (T::is_row)
108  type = "row vector";
109  else if (T::is_col)
110  type = "column vector";
111 
112  return type;
113 }
114 
115 template<typename T>
116 inline std::string GetPythonType(
117  const util::ParamData& d,
118  const typename boost::disable_if<arma::is_arma_type<T>>::type* = 0,
119  const typename boost::enable_if<data::HasSerialize<T>>::type* = 0)
120 {
121  return d.cppType + "Type";
122 }
123 
124 } // namespace python
125 } // namespace bindings
126 } // namespace mlpack
127 
128 #endif
std::string GetPythonType< float >(const 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 *)
std::string GetPythonType< bool >(const 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 *)
std::string GetPythonType< size_t >(const 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 *)
.hpp
Definition: add_to_po.hpp:21
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
Metaprogramming structure for vector detection.
std::string cppType
The true name of the type, as it would be written in C++.
Definition: param_data.hpp:84
std::string GetPythonType(const 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)
std::string GetPythonType< double >(const 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 *)
std::string GetPythonType< int >(const 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 *)