get_cython_type.hpp
Go to the documentation of this file.
1 
13 #ifndef MLPACK_BINDINGS_PYTHON_GET_CYTHON_TYPE_HPP
14 #define MLPACK_BINDINGS_PYTHON_GET_CYTHON_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 GetCythonType(
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 {
30  return "unknown";
31 }
32 
33 template<>
34 inline std::string GetCythonType<int>(
35  util::ParamData& /* d */,
36  const typename std::enable_if<!util::IsStdVector<int>::value>::type*,
37  const typename std::enable_if<!data::HasSerialize<int>::value>::type*,
38  const typename std::enable_if<!arma::is_arma_type<int>::value>::type*)
39 {
40  return "int";
41 }
42 
43 template<>
44 inline std::string GetCythonType<double>(
45  util::ParamData& /* d */,
46  const typename std::enable_if<!util::IsStdVector<double>::value>::type*,
47  const typename std::enable_if<!data::HasSerialize<double>::value>::type*,
48  const typename std::enable_if<!arma::is_arma_type<double>::value>::type*)
49 {
50  return "double";
51 }
52 
53 template<>
54 inline std::string GetCythonType<std::string>(
55  util::ParamData& /* d */,
56  const typename std::enable_if<
58  const typename std::enable_if<
60  const typename std::enable_if<
61  !arma::is_arma_type<std::string>::value>::type*)
62 {
63  return "string";
64 }
65 
66 template<>
67 inline std::string GetCythonType<size_t>(
68  util::ParamData& /* d */,
69  const typename std::enable_if<!util::IsStdVector<size_t>::value>::type*,
70  const typename std::enable_if<!data::HasSerialize<size_t>::value>::type*,
71  const typename std::enable_if<!arma::is_arma_type<size_t>::value>::type*)
72 {
73  return "size_t";
74 }
75 
76 template<>
77 inline std::string GetCythonType<bool>(
78  util::ParamData& /* d */,
79  const typename std::enable_if<!util::IsStdVector<bool>::value>::type*,
80  const typename std::enable_if<!data::HasSerialize<bool>::value>::type*,
81  const typename std::enable_if<!arma::is_arma_type<bool>::value>::type*)
82 {
83  return "cbool";
84 }
85 
86 template<typename T>
87 inline std::string GetCythonType(
88  util::ParamData& d,
89  const typename std::enable_if<util::IsStdVector<T>::value>::type* = 0)
90 {
91  return "vector[" + GetCythonType<typename T::value_type>(d) + "]";
92 }
93 
94 template<typename T>
95 inline std::string GetCythonType(
96  util::ParamData& d,
97  const typename std::enable_if<arma::is_arma_type<T>::value>::type* = 0)
98 {
99  std::string type = "Mat";
100  if (T::is_row)
101  type = "Row";
102  else if (T::is_col)
103  type = "Col";
104 
105  return "arma." + type + "[" + GetCythonType<typename T::elem_type>(d) + "]";
106 }
107 
108 template<typename T>
109 inline std::string GetCythonType(
110  util::ParamData& d,
111  const typename std::enable_if<!arma::is_arma_type<T>::value>::type* = 0,
112  const typename std::enable_if<data::HasSerialize<T>::value>::type* = 0)
113 {
114  return d.cppType + "*";
115 }
116 
117 } // namespace python
118 } // namespace bindings
119 } // namespace mlpack
120 
121 #endif
Linear algebra utility functions, generally performed on matrices or vectors.
The core includes that mlpack expects; standard C++ includes and Armadillo.
std::string GetCythonType< 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 *)
python
Definition: CMakeLists.txt:7
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 GetCythonType(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)
std::string GetCythonType< 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 *)
std::string GetCythonType< 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 *)
std::string cppType
The true name of the type, as it would be written in C++.
Definition: param_data.hpp:81
std::string GetCythonType< 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 *)