Stan  1.3
probability, sampling & optimization
 All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros Pages
validate_matching_sizes.hpp
Go to the documentation of this file.
1 #ifndef __STAN__MATH__MATRIX__VALIDATE_MATCHING_SIZES_HPP__
2 #define __STAN__MATH__MATRIX__VALIDATE_MATCHING_SIZES_HPP__
3 
4 #include <sstream>
5 #include <stdexcept>
6 #include <vector>
8 
9 namespace stan {
10  namespace math {
11 
12  template <typename T1, typename T2>
13  inline void validate_matching_sizes(const std::vector<T1>& x1,
14  const std::vector<T2>& x2,
15  const char* msg) {
16  if (x1.size() == x2.size()) return;
17  std::stringstream ss;
18  ss << "error in call to " << msg
19  << "; require matching sizes, but found"
20  << " arg1(size=" << x1.size() << ");"
21  << " arg2(size=" << x2.size() << ");";
22  throw std::domain_error(ss.str());
23  }
24 
25  template <typename T1, int R1, int C1, typename T2, int R2, int C2>
26  inline void validate_matching_sizes(const Eigen::Matrix<T1,R1,C1>& x1,
27  const Eigen::Matrix<T2,R2,C2>& x2,
28  const char* msg) {
29  if (x1.size() == x2.size()) return;
30  std::stringstream ss;
31  ss << "error in call to " << msg
32  << "; require matching sizes, but found"
33  << " arg1(rows=" << x1.rows() << ",cols=" << x1.cols()
34  << ",size=" << (x1.rows() * x1.cols()) << ");"
35  << " arg2(rows=" << x2.rows() << ",cols=" << x2.cols()
36  << ",size=" << (x2.rows() * x2.cols()) << ")";
37  throw std::domain_error(ss.str());
38  }
39 
40  template <typename Derived, typename T2, int R2, int C2>
41  inline void validate_matching_sizes(const Eigen::Block<Derived>& x1,
42  const Eigen::Matrix<T2,R2,C2>& x2,
43  const char* msg) {
44  if (x1.size() == x2.size()) return;
45  std::stringstream ss;
46  ss << "error in call to " << msg
47  << "; require matching sizes, but found"
48  << " arg1(rows=" << x1.rows() << ",cols=" << x1.cols()
49  << ",size=" << (x1.rows() * x1.cols()) << ");"
50  << " arg2(rows=" << x2.rows() << ",cols=" << x2.cols()
51  << ",size=" << (x2.rows() * x2.cols()) << ")";
52  throw std::domain_error(ss.str());
53  }
54 
55  template <typename T1, int R1, int C1, typename Derived>
56  inline void validate_matching_sizes(const Eigen::Matrix<T1,R1,C1>& x1,
57  const Eigen::Block<Derived>& x2,
58  const char* msg) {
59  if (x1.size() == x2.size()) return;
60  std::stringstream ss;
61  ss << "error in call to " << msg
62  << "; require matching sizes, but found"
63  << " arg1(rows=" << x1.rows() << ",cols=" << x1.cols()
64  << ",size=" << (x1.rows() * x1.cols()) << ");"
65  << " arg2(rows=" << x2.rows() << ",cols=" << x2.cols()
66  << ",size=" << (x2.rows() * x2.cols()) << ")";
67  throw std::domain_error(ss.str());
68  }
69 
70  template <typename Derived1, typename Derived2>
71  inline void validate_matching_sizes(const Eigen::Block<Derived1>& x1,
72  const Eigen::Block<Derived2>& x2,
73  const char* msg) {
74  if (x1.size() == x2.size()) return;
75  std::stringstream ss;
76  ss << "error in call to " << msg
77  << "; require matching sizes, but found"
78  << " arg1(rows=" << x1.rows() << ",cols=" << x1.cols()
79  << ",size=" << (x1.rows() * x1.cols()) << ");"
80  << " arg2(rows=" << x2.rows() << ",cols=" << x2.cols()
81  << ",size=" << (x2.rows() * x2.cols()) << ")";
82  throw std::domain_error(ss.str());
83  }
84 
85  }
86 }
87 #endif

     [ Stan Home Page ] © 2011–2013, Stan Development Team.