mlpack 3.4.2
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
19namespace mlpack {
20namespace bindings {
21namespace python {
22
23template<typename T>
24inline std::string GetCythonType(
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{
30 return "unknown";
31}
32
33template<>
34inline std::string GetCythonType<int>(
35 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
43template<>
44inline std::string GetCythonType<double>(
45 util::ParamData& /* d */,
46 const typename boost::disable_if<util::IsStdVector<double>>::type*,
47 const typename boost::disable_if<data::HasSerialize<double>>::type*,
48 const typename boost::disable_if<arma::is_arma_type<double>>::type*)
49{
50 return "double";
51}
52
53template<>
54inline std::string GetCythonType<std::string>(
55 util::ParamData& /* d */,
56 const typename boost::disable_if<util::IsStdVector<std::string>>::type*,
57 const typename boost::disable_if<data::HasSerialize<std::string>>::type*,
58 const typename boost::disable_if<arma::is_arma_type<std::string>>::type*)
59{
60 return "string";
61}
62
63template<>
64inline std::string GetCythonType<size_t>(
65 util::ParamData& /* d */,
66 const typename boost::disable_if<util::IsStdVector<size_t>>::type*,
67 const typename boost::disable_if<data::HasSerialize<size_t>>::type*,
68 const typename boost::disable_if<arma::is_arma_type<size_t>>::type*)
69{
70 return "size_t";
71}
72
73template<>
74inline std::string GetCythonType<bool>(
75 util::ParamData& /* d */,
76 const typename boost::disable_if<util::IsStdVector<bool>>::type*,
77 const typename boost::disable_if<data::HasSerialize<bool>>::type*,
78 const typename boost::disable_if<arma::is_arma_type<bool>>::type*)
79{
80 return "cbool";
81}
82
83template<typename T>
84inline std::string GetCythonType(
86 const typename boost::enable_if<util::IsStdVector<T>>::type* = 0)
87{
88 return "vector[" + GetCythonType<typename T::value_type>(d) + "]";
89}
90
91template<typename T>
92inline std::string GetCythonType(
94 const typename boost::enable_if<arma::is_arma_type<T>>::type* = 0)
95{
96 std::string type = "Mat";
97 if (T::is_row)
98 type = "Row";
99 else if (T::is_col)
100 type = "Col";
101
102 return "arma." + type + "[" + GetCythonType<typename T::elem_type>(d) + "]";
103}
104
105template<typename T>
106inline std::string GetCythonType(
108 const typename boost::disable_if<arma::is_arma_type<T>>::type* = 0,
109 const typename boost::enable_if<data::HasSerialize<T>>::type* = 0)
110{
111 return d.cppType + "*";
112}
113
114} // namespace python
115} // namespace bindings
116} // namespace mlpack
117
118#endif
python
Definition: CMakeLists.txt:6
std::string GetCythonType< 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 *)
std::string GetCythonType< 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 *)
std::string GetCythonType(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 GetCythonType< 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 *)
std::string GetCythonType< 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 *)
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