size_checks.hpp
Go to the documentation of this file.
1 
13 #ifndef MLPACK_UTIL_SIZE_CHECKS_HPP
14 #define MLPACK_UTIL_SIZE_CHECKS_HPP
15 
16 
17 namespace mlpack {
18 namespace util {
19 
30 template<typename DataType, typename LabelsType>
31 inline void CheckSameSizes(const DataType& data,
32  const LabelsType& label,
33  const std::string& callerDescription,
34  const std::string& addInfo = "labels")
35 {
36  if (data.n_cols != label.n_cols)
37  {
38  std::ostringstream oss;
39  oss << callerDescription << ": number of points (" << data.n_cols << ") "
40  << "does not match number of " << addInfo << " (" << label.n_cols
41  << ")!" << std::endl;
42  throw std::invalid_argument(oss.str());
43  }
44 }
45 
50 template<typename DataType>
51 inline void CheckSameSizes(const DataType& data,
52  const size_t& size,
53  const std::string& callerDescription,
54  const std::string& addInfo = "labels")
55 {
56  if (data.n_cols != size)
57  {
58  std::ostringstream oss;
59  oss << callerDescription << ": number of points (" << data.n_cols << ") "
60  << "does not match number of " << addInfo << " (" << size << ")!"
61  << std::endl;
62  throw std::invalid_argument(oss.str());
63  }
64 }
65 
66 
77 template<typename DataType, typename DimType>
78 inline void CheckSameDimensionality(const DataType& data,
79  const DimType& dimension,
80  const std::string& callerDescription,
81  const std::string& addInfo = "dataset")
82 {
83  if (data.n_rows != dimension.n_rows)
84  {
85  std::ostringstream oss;
86  oss << callerDescription << ": dimensionality of " << addInfo << " ("
87  << data.n_rows << ") is not equal to the dimensionality of the model"
88  " (" << dimension.n_rows << ")!";
89 
90  throw std::invalid_argument(oss.str());
91  }
92 }
93 
98 template<typename DataType>
99 inline void CheckSameDimensionality(const DataType& data,
100  const size_t& dimension,
101  const std::string& callerDescription,
102  const std::string& addInfo = "dataset")
103 {
104  if (data.n_rows != dimension)
105  {
106  std::ostringstream oss;
107  oss << callerDescription << ": dimensionality of " << addInfo << " ("
108  << data.n_rows << ") is not equal to the dimensionality of the model"
109  " (" << dimension << ")!";
110  throw std::invalid_argument(oss.str());
111  }
112 }
113 
114 } // namespace util
115 } // namespace mlpack
116 
117 #endif
Linear algebra utility functions, generally performed on matrices or vectors.
void CheckSameSizes(const DataType &data, const LabelsType &label, const std::string &callerDescription, const std::string &addInfo="labels")
Check for if the given data points & labels have same size.
Definition: size_checks.hpp:31
void CheckSameDimensionality(const DataType &data, const DimType &dimension, const std::string &callerDescription, const std::string &addInfo="dataset")
Check for if the given dataset dimension matches with the model&#39;s.
Definition: size_checks.hpp:78