get_go_type.hpp
Go to the documentation of this file.
1 
14 #ifndef MLPACK_BINDINGS_GO_GET_GO_TYPE_HPP
15 #define MLPACK_BINDINGS_GO_GET_GO_TYPE_HPP
16 
17 #include <mlpack/prereqs.hpp>
19 #include "strip_type.hpp"
20 
21 namespace mlpack {
22 namespace bindings {
23 namespace go {
24 
25 template<typename T>
26 inline std::string GetGoType(
27  util::ParamData& /* d */,
28  const typename boost::disable_if<util::IsStdVector<T>>::type* = 0,
29  const typename boost::disable_if<data::HasSerialize<T>>::type* = 0,
30  const typename boost::disable_if<arma::is_arma_type<T>>::type* = 0,
31  const typename boost::disable_if<std::is_same<T,
32  std::tuple<data::DatasetInfo, arma::mat>>>::type* = 0)
33 {
34  return "unknown";
35 }
36 
37 template<>
38 inline std::string GetGoType<int>(
39  util::ParamData& /* d */,
40  const typename boost::disable_if<util::IsStdVector<int>>::type*,
41  const typename boost::disable_if<data::HasSerialize<int>>::type*,
42  const typename boost::disable_if<arma::is_arma_type<int>>::type*,
43  const typename boost::disable_if<std::is_same<int,
44  std::tuple<data::DatasetInfo, arma::mat>>>::type*)
45 {
46  return "int";
47 }
48 
49 template<>
50 inline std::string GetGoType<float>(
51  util::ParamData& /* d */,
52  const typename boost::disable_if<util::IsStdVector<float>>::type*,
53  const typename boost::disable_if<data::HasSerialize<float>>::type*,
54  const typename boost::disable_if<arma::is_arma_type<float>>::type*,
55  const typename boost::disable_if<std::is_same<float,
56  std::tuple<data::DatasetInfo, arma::mat>>>::type*)
57 {
58  return "float32";
59 }
60 
61 template<>
62 inline std::string GetGoType<double>(
63  util::ParamData& /* d */,
64  const typename boost::disable_if<util::IsStdVector<double>>::type*,
65  const typename boost::disable_if<data::HasSerialize<double>>::type*,
66  const typename boost::disable_if<arma::is_arma_type<double>>::type*,
67  const typename boost::disable_if<std::is_same<double,
68  std::tuple<data::DatasetInfo, arma::mat>>>::type*)
69 {
70  return "float64";
71 }
72 
73 template<>
74 inline std::string GetGoType<std::string>(
75  util::ParamData& /* d */,
76  const typename boost::disable_if<util::IsStdVector<std::string>>::type*,
77  const typename boost::disable_if<data::HasSerialize<std::string>>::type*,
78  const typename boost::disable_if<arma::is_arma_type<std::string>>::type*,
79  const typename boost::disable_if<std::is_same<std::string,
80  std::tuple<data::DatasetInfo, arma::mat>>>::type*)
81 {
82  return "string";
83 }
84 
85 template<>
86 inline std::string GetGoType<bool>(
87  util::ParamData& /* d */,
88  const typename boost::disable_if<util::IsStdVector<bool>>::type*,
89  const typename boost::disable_if<data::HasSerialize<bool>>::type*,
90  const typename boost::disable_if<arma::is_arma_type<bool>>::type*,
91  const typename boost::disable_if<std::is_same<bool,
92  std::tuple<data::DatasetInfo, arma::mat>>>::type*)
93 {
94  return "bool";
95 }
96 
97 template<typename T>
98 inline std::string GetGoType(
99  util::ParamData& d,
100  const typename boost::enable_if<util::IsStdVector<T>>::type* = 0)
101 {
102  return "[]" + GetGoType<typename T::value_type>(d);
103 }
104 
105 template<typename T>
106 inline std::string GetGoType(
107  util::ParamData& /* d */,
108  const typename boost::disable_if<std::is_same<T,
109  std::tuple<data::DatasetInfo, arma::mat>>>::type* = 0,
110  const typename boost::enable_if<arma::is_arma_type<T>>::type* = 0)
111 {
112  return "mat.Dense";
113 }
114 
115 template<typename T>
116 inline std::string GetGoType(
117  util::ParamData& /* d */,
118  const typename boost::enable_if<std::is_same<T,
119  std::tuple<data::DatasetInfo, arma::mat>>>::type* = 0)
120 {
121  return "matrixWithInfo";
122 }
123 
124 template<typename T>
125 inline std::string GetGoType(
126  util::ParamData& d,
127  const typename boost::disable_if<arma::is_arma_type<T>>::type* = 0,
128  const typename boost::enable_if<data::HasSerialize<T>>::type* = 0)
129 {
130  std::string goStrippedType, strippedType, printedType, defaultsType;
131  StripType(d.cppType, goStrippedType, strippedType, printedType, defaultsType);
132  return goStrippedType;
133 }
134 
135 } // namespace go
136 } // namespace bindings
137 } // namespace mlpack
138 
139 #endif
void StripType(const std::string &inputType, std::string &goStrippedType, std::string &strippedType, std::string &printedType, std::string &defaultsType)
Given an input type like, e.g., "LogisticRegression<>", return four types that can be used in Go code...
Definition: strip_type.hpp:30
Linear algebra utility functions, generally performed on matrices or vectors.
The core includes that mlpack expects; standard C++ includes and Armadillo.
go
Definition: CMakeLists.txt:6
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 GetGoType< 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_go_type.hpp:50
std::string GetGoType< 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_go_type.hpp:38
std::string GetGoType(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_go_type.hpp:26
std::string GetGoType< 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_go_type.hpp:62
std::string cppType
The true name of the type, as it would be written in C++.
Definition: param_data.hpp:84
std::string GetGoType< 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_go_type.hpp:86