get_julia_type.hpp
Go to the documentation of this file.
1 
12 #ifndef MLPACK_BINDINGS_JULIA_GET_JULIA_TYPE_HPP
13 #define MLPACK_BINDINGS_JULIA_GET_JULIA_TYPE_HPP
14 
15 #include <mlpack/prereqs.hpp>
16 
17 namespace mlpack {
18 namespace bindings {
19 namespace julia {
20 
21 template<typename T>
22 inline std::string GetJuliaType(
23  util::ParamData& /* d */,
24  const typename std::enable_if<!util::IsStdVector<T>::value>::type* = 0,
25  const typename std::enable_if<!arma::is_arma_type<T>::value>::type* = 0,
26  const typename std::enable_if<!std::is_same<T,
27  std::tuple<data::DatasetInfo, arma::mat>>::value>::type* = 0,
28  const typename std::enable_if<!data::HasSerialize<T>::value>::type* = 0)
29 {
30  return "unknown_"; // This will cause an error most likely...
31 }
32 
33 template<>
34 inline std::string GetJuliaType<bool>(
35  util::ParamData& /* d */,
36  const typename std::enable_if<!util::IsStdVector<bool>::value>::type*,
37  const typename std::enable_if<!arma::is_arma_type<bool>::value>::type*,
38  const typename std::enable_if<!std::is_same<bool,
39  std::tuple<data::DatasetInfo, arma::mat>>::value>::type*,
40  const typename std::enable_if<!data::HasSerialize<bool>::value>::type*)
41 {
42  return "Bool";
43 }
44 
45 template<>
46 inline std::string GetJuliaType<int>(
47  util::ParamData& /* d */,
48  const typename std::enable_if<!util::IsStdVector<int>::value>::type*,
49  const typename std::enable_if<!arma::is_arma_type<int>::value>::type*,
50  const typename std::enable_if<!std::is_same<int,
51  std::tuple<data::DatasetInfo, arma::mat>>::value>::type*,
52  const typename std::enable_if<!data::HasSerialize<int>::value>::type*)
53 {
54  return "Int";
55 }
56 
57 template<>
58 inline std::string GetJuliaType<size_t>(
59  util::ParamData& /* d */,
60  const typename std::enable_if<!util::IsStdVector<size_t>::value>::type*,
61  const typename std::enable_if<!arma::is_arma_type<size_t>::value>::type*,
62  const typename std::enable_if<!std::is_same<size_t,
63  std::tuple<data::DatasetInfo, arma::mat>>::value>::type*,
64  const typename std::enable_if<!data::HasSerialize<size_t>::value>::type*)
65 {
66  return "UInt";
67 }
68 
69 template<>
70 inline std::string GetJuliaType<double>(
71  util::ParamData& /* d */,
72  const typename std::enable_if<!util::IsStdVector<double>::value>::type*,
73  const typename std::enable_if<!arma::is_arma_type<double>::value>::type*,
74  const typename std::enable_if<!std::is_same<double,
75  std::tuple<data::DatasetInfo, arma::mat>>::value>::type*,
76  const typename std::enable_if<!data::HasSerialize<double>::value>::type*)
77 {
78  // I suppose on some systems this may not be 64 bit.
79  return "Float64";
80 }
81 
82 template<>
83 inline std::string GetJuliaType<std::string>(
84  util::ParamData& /* d */,
85  const typename std::enable_if<
87  const typename std::enable_if<
88  !arma::is_arma_type<std::string>::value>::type*,
89  const typename std::enable_if<!std::is_same<std::string,
90  std::tuple<data::DatasetInfo, arma::mat>>::value>::type*,
91  const typename std::enable_if<
93 {
94  return "String";
95 }
96 
97 template<typename T>
98 inline std::string GetJuliaType(
99  util::ParamData& d,
100  const typename std::enable_if<util::IsStdVector<T>::value>::type* = 0,
101  const typename std::enable_if<!std::is_same<T,
102  std::tuple<data::DatasetInfo, arma::mat>>::value>::type* = 0,
103  const typename std::enable_if<!arma::is_arma_type<T>::value>::type* = 0)
104 {
105  return "Vector{" + GetJuliaType<typename T::value_type>(d) + "}";
106 }
107 
108 template<typename T>
109 inline std::string GetJuliaType(
110  util::ParamData& d,
111  const typename std::enable_if<!util::IsStdVector<T>::value>::type* = 0,
112  const typename std::enable_if<!std::is_same<T,
113  std::tuple<data::DatasetInfo, arma::mat>>::value>::type* = 0,
114  const typename std::enable_if<arma::is_arma_type<T>::value>::type* = 0)
115 {
116  // size_t matrices are special: we want to represent them in Julia as
117  // Array{Int, X} not UInt because Julia displays UInts strangely.
118  if (std::is_same<typename T::elem_type, size_t>::value)
119  return std::string("Array{Int, ") + (T::is_col || T::is_row ? "1" : "2")
120  + "}";
121  else
122  return "Array{" + GetJuliaType<typename T::elem_type>(d) + ", "
123  + (T::is_col || T::is_row ? "1" : "2") + "}";
124 }
125 
126 template<typename T>
127 inline std::string GetJuliaType(
128  util::ParamData& /* d */,
129  const typename std::enable_if<std::is_same<T,
130  std::tuple<data::DatasetInfo, arma::mat>>::value>::type* = 0)
131 {
132  return "Tuple{Array{Bool, 1}, Array{Float64, 2}}";
133 }
134 
135 // for serializable types
136 template<typename T>
137 inline std::string GetJuliaType(
138  util::ParamData& d,
139  const typename std::enable_if<!util::IsStdVector<T>::value>::type* = 0,
140  const typename std::enable_if<!arma::is_arma_type<T>::value>::type* = 0,
141  const typename std::enable_if<data::HasSerialize<T>::value>::type* = 0)
142 {
143  // Serializable types are just held as a pointer to nothing, but they're
144  // wrapped in a struct.
145  std::string type = util::StripType(d.cppType);
146  std::ostringstream oss;
147  oss << type;
148  return oss.str();
149 }
150 
151 } // namespace julia
152 } // namespace bindings
153 } // namespace mlpack
154 
155 #endif
Linear algebra utility functions, generally performed on matrices or vectors.
The core includes that mlpack expects; standard C++ includes and Armadillo.
std::string GetJuliaType< bool >(util::ParamData &, const typename std::enable_if<!util::IsStdVector< bool >::value >::type *, const typename std::enable_if<!arma::is_arma_type< bool >::value >::type *, const typename std::enable_if<!std::is_same< bool, std::tuple< data::DatasetInfo, arma::mat >>::value >::type *, const typename std::enable_if<!data::HasSerialize< bool >::value >::type *)
std::string GetJuliaType< size_t >(util::ParamData &, const typename std::enable_if<!util::IsStdVector< size_t >::value >::type *, const typename std::enable_if<!arma::is_arma_type< size_t >::value >::type *, const typename std::enable_if<!std::is_same< size_t, std::tuple< data::DatasetInfo, arma::mat >>::value >::type *, const typename std::enable_if<!data::HasSerialize< size_t >::value >::type *)
std::string GetJuliaType< int >(util::ParamData &, const typename std::enable_if<!util::IsStdVector< int >::value >::type *, const typename std::enable_if<!arma::is_arma_type< int >::value >::type *, const typename std::enable_if<!std::is_same< int, std::tuple< data::DatasetInfo, arma::mat >>::value >::type *, const typename std::enable_if<!data::HasSerialize< int >::value >::type *)
julia
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
std::string GetJuliaType< double >(util::ParamData &, const typename std::enable_if<!util::IsStdVector< double >::value >::type *, const typename std::enable_if<!arma::is_arma_type< double >::value >::type *, const typename std::enable_if<!std::is_same< double, std::tuple< data::DatasetInfo, arma::mat >>::value >::type *, const typename std::enable_if<!data::HasSerialize< double >::value >::type *)
Metaprogramming structure for vector detection.
std::string StripType(std::string cppType)
Given a C++ type name, turn it into something that has no special characters that can simply be print...
Definition: strip_type.hpp:27
std::string cppType
The true name of the type, as it would be written in C++.
Definition: param_data.hpp:81
std::string GetJuliaType(util::ParamData &, const typename std::enable_if<!util::IsStdVector< T >::value >::type *=0, const typename std::enable_if<!arma::is_arma_type< T >::value >::type *=0, const typename std::enable_if<!std::is_same< T, std::tuple< data::DatasetInfo, arma::mat >>::value >::type *=0, const typename std::enable_if<!data::HasSerialize< T >::value >::type *=0)