import_decl.hpp
Go to the documentation of this file.
1 
12 #ifndef MLPACK_BINDINGS_PYTHON_IMPORT_DECL_HPP
13 #define MLPACK_BINDINGS_PYTHON_IMPORT_DECL_HPP
14 
15 #include <mlpack/prereqs.hpp>
16 #include "strip_type.hpp"
17 
18 namespace mlpack {
19 namespace bindings {
20 namespace python {
21 
25 template<typename T>
27  const util::ParamData& d,
28  const size_t indent,
29  const typename boost::disable_if<arma::is_arma_type<T>>::type* = 0,
30  const typename boost::enable_if<data::HasSerialize<T>>::type* = 0)
31 {
32  // First, we have to parse the type. If we have something like, e.g.,
33  // 'LogisticRegression<>', we must convert this to 'LogisticRegression[T=*].'
34  std::string strippedType, printedType, defaultsType;
35  StripType(d.cppType, strippedType, printedType, defaultsType);
36 
43  const std::string prefix = std::string(indent, ' ');
44  std::cout << prefix << "cdef cppclass " << defaultsType << ":" << std::endl;
45  std::cout << prefix << " " << strippedType << "() nogil" << std::endl;
46  std::cout << prefix << std::endl;
47 }
48 
52 template<typename T>
54  const util::ParamData& /* d */,
55  const size_t /* indent */,
56  const typename boost::disable_if<arma::is_arma_type<T>>::type* = 0,
57  const typename boost::disable_if<data::HasSerialize<T>>::type* = 0)
58 {
59  // Print nothing.
60 }
61 
65 template<typename T>
67  const util::ParamData& /* d */,
68  const size_t /* indent */,
69  const typename boost::enable_if<arma::is_arma_type<T>>::type* = 0)
70 {
71  // Print nothing.
72 }
73 
82 template<typename T>
84  const void* indent,
85  void* /* output */)
86 {
87  ImportDecl<typename std::remove_pointer<T>::type>(d, *((size_t*) indent));
88 }
89 
90 } // namespace python
91 } // namespace bindings
92 } // namespace mlpack
93 
94 #endif
strip_type.hpp
Definition: add_to_po.hpp:21
The core includes that mlpack expects; standard C++ includes and Armadillo.
python
Definition: CMakeLists.txt:4
This structure holds all of the information about a single parameter, including its value (which is s...
Definition: param_data.hpp:52
void ImportDecl(const util::ParamData &d, const size_t indent, const typename boost::disable_if< arma::is_arma_type< T >>::type *=0, const typename boost::enable_if< data::HasSerialize< T >>::type *=0)
For a serializable type, print a cppclass definition.
Definition: import_decl.hpp:26
void StripType(const std::string &inputType, std::string &strippedType, std::string &printedType, std::string &defaultsType)
Given an input type like, e.g., "LogisticRegression<>", return three types that can be used in Python...
Definition: strip_type.hpp:28
std::string cppType
The true name of the type, as it would be written in C++.
Definition: param_data.hpp:84