mlpack
get_printable_param_impl.hpp
Go to the documentation of this file.
1 
12 #ifndef MLPACK_BINDINGS_CLI_GET_PRINTABLE_PARAM_IMPL_HPP
13 #define MLPACK_BINDINGS_CLI_GET_PRINTABLE_PARAM_IMPL_HPP
14 
15 #include "get_printable_param.hpp"
16 #include "get_param.hpp"
17 
18 namespace mlpack {
19 namespace bindings {
20 namespace cli {
21 
23 template<typename T>
24 std::string GetPrintableParam(
26  const typename std::enable_if<!arma::is_arma_type<T>::value>::type* /* junk */,
27  const typename std::enable_if<!util::IsStdVector<T>::value>::type* /* junk */,
28  const typename std::enable_if<!data::HasSerialize<T>::value>::type* /* junk */,
29  const typename std::enable_if<!std::is_same<T,
30  std::tuple<data::DatasetInfo, arma::mat>>::value>::type* /* junk */)
31 {
32  std::ostringstream oss;
33  oss << boost::any_cast<T>(data.value);
34  return oss.str();
35 }
36 
38 template<typename T>
39 std::string GetPrintableParam(
41  const typename std::enable_if<util::IsStdVector<T>::value>::type*
42  /* junk */)
43 {
44  const T& t = boost::any_cast<T>(data.value);
45 
46  std::ostringstream oss;
47  for (size_t i = 0; i < t.size(); ++i)
48  oss << t[i] << " ";
49  return oss.str();
50 }
51 
52 // Return a printed representation of the size of the matrix.
53 template<typename T>
54 std::string GetMatrixSize(
55  T& matrix,
56  const typename std::enable_if<arma::is_arma_type<T>::value>::type* = 0)
57 {
58  std::ostringstream oss;
59  oss << matrix.n_rows << "x" << matrix.n_cols << " matrix";
60  return oss.str();
61 }
62 
63 // Return a printed representation of the size of the matrix.
64 template<typename T>
65 std::string GetMatrixSize(
66  T& matrixAndInfo,
67  const typename std::enable_if<std::is_same<T,
68  std::tuple<data::DatasetInfo, arma::mat>>::value>::type* = 0)
69 {
70  return GetMatrixSize(std::get<1>(matrixAndInfo));
71 }
72 
74 template<typename T>
75 std::string GetPrintableParam(
77  const typename std::enable_if<arma::is_arma_type<T>::value ||
78  std::is_same<T,
79  std::tuple<data::DatasetInfo, arma::mat>>::value>::type* /* junk */)
80 {
81  // Extract the string from the tuple that's being held.
82  typedef std::tuple<T, typename ParameterType<T>::type> TupleType;
83  const TupleType* tuple = boost::any_cast<TupleType>(&data.value);
84 
85  std::ostringstream oss;
86  oss << "'" << std::get<0>(std::get<1>(*tuple)) << "'";
87 
88  if (std::get<0>(std::get<1>(*tuple)) != "")
89  {
90  // Make sure the matrix is loaded so that we can print its size.
91  GetParam<T>(const_cast<util::ParamData&>(data));
92  std::string matDescription =
93  std::to_string(std::get<2>(std::get<1>(*tuple))) + "x" +
94  std::to_string(std::get<1>(std::get<1>(*tuple))) + " matrix";
95 
96  oss << " (" << matDescription << ")";
97  }
98 
99  return oss.str();
100 }
101 
103 template<typename T>
104 std::string GetPrintableParam(
106  const typename std::enable_if<!arma::is_arma_type<T>::value>::type* /* junk */,
107  const typename std::enable_if<data::HasSerialize<T>::value>::type* /* junk */)
108 {
109  // Extract the string from the tuple that's being held.
110  typedef std::tuple<T*, typename ParameterType<T>::type> TupleType;
111  const TupleType* tuple = boost::any_cast<TupleType>(&data.value);
112 
113  std::ostringstream oss;
114  oss << std::get<1>(*tuple);
115  return oss.str();
116 }
117 
118 } // namespace cli
119 } // namespace bindings
120 } // namespace mlpack
121 
122 #endif
Definition: has_serialize.hpp:47
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: cv.hpp:1
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.
Definition: is_std_vector.hpp:23
boost::any value
The actual value that is held.
Definition: param_data.hpp:82
std::string GetPrintableParam(util::ParamData &data, const typename std::enable_if<!arma::is_arma_type< T >::value >::type *=0, 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<!std::is_same< T, std::tuple< data::DatasetInfo, arma::mat >>::value >::type *=0)
Print an option.
Definition: get_printable_param_impl.hpp:24