check_consistent_sizes.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_SCAL_ERR_CHECK_CONSISTENT_SIZES_HPP
2 #define STAN_MATH_PRIM_SCAL_ERR_CHECK_CONSISTENT_SIZES_HPP
3 
5 #include <algorithm>
6 
7 namespace stan {
8 namespace math {
9 
10 /**
11  * Check if the dimension of x1 is consistent
12  * with x2.
13  *
14  * Consistent size is defined as having the same size if vector-like or
15  * being a scalar.
16  *
17  * @tparam T1 Type of x1
18  * @tparam T2 Type of x2
19  *
20  * @param function Function name (for error messages)
21  * @param name1 Variable name (for error messages)
22  * @param x1 Variable to check for consistent size
23  * @param name2 Variable name (for error messages)
24  * @param x2 Variable to check for consistent size
25  *
26  * @throw <code>invalid_argument</code> if sizes are inconsistent
27  */
28 template <typename T1, typename T2>
29 inline void check_consistent_sizes(const char* function, const char* name1,
30  const T1& x1, const char* name2,
31  const T2& x2) {
32  using stan::is_vector;
35  check_consistent_size(function, name1, x1, max_size);
36  check_consistent_size(function, name2, x2, max_size);
37 }
38 
39 /**
40  * Check if the dimension of x1, x2, and x3 are
41  * consistent.
42  *
43  * Consistent size is defined as having the same size if vector-like or
44  * being a scalar.
45  *
46  * @tparam T1 Type of x1
47  * @tparam T2 Type of x2
48  * @tparam T3 Type of x3
49  *
50  * @param function Function name (for error messages)
51  * @param name1 Variable name (for error messages)
52  * @param x1 Variable to check for consistent size
53  * @param name2 Variable name (for error messages)
54  * @param x2 Variable to check for consistent size
55  * @param name3 Variable name (for error messages)
56  * @param x3 Variable to check for consistent size
57  *
58  * @throw <code>invalid_argument</code> if sizes are inconsistent
59  */
60 template <typename T1, typename T2, typename T3>
61 inline void check_consistent_sizes(const char* function, const char* name1,
62  const T1& x1, const char* name2,
63  const T2& x2, const char* name3,
64  const T3& x3) {
68  check_consistent_size(function, name1, x1, max_size);
69  check_consistent_size(function, name2, x2, max_size);
70  check_consistent_size(function, name3, x3, max_size);
71 }
72 
73 /**
74  * Check if the dimension of x1, x2, x3, and x4
75  * are consistent.
76  *
77  * Consistent size is defined as having the same size if
78  * vector-like or being a scalar.
79  *
80  * @tparam T1 Type of x1
81  * @tparam T2 Type of x2
82  * @tparam T3 Type of x3
83  * @tparam T4 Type of x4
84  *
85  * @param function Function name (for error messages)
86  * @param name1 Variable name (for error messages)
87  * @param x1 Variable to check for consistent size
88  * @param name2 Variable name (for error messages)
89  * @param x2 Variable to check for consistent size
90  * @param name3 Variable name (for error messages)
91  * @param x3 Variable to check for consistent size
92  * @param name4 Variable name (for error messages)
93  * @param x4 Variable to check for consistent size
94  *
95  * @throw <code>invalid_argument</code> if sizes are inconsistent
96  */
97 template <typename T1, typename T2, typename T3, typename T4>
98 inline void check_consistent_sizes(const char* function, const char* name1,
99  const T1& x1, const char* name2,
100  const T2& x2, const char* name3,
101  const T3& x3, const char* name4,
102  const T4& x4) {
103  size_t max_size
107  is_vector<T4>::value * size_of(x4))));
108  check_consistent_size(function, name1, x1, max_size);
109  check_consistent_size(function, name2, x2, max_size);
110  check_consistent_size(function, name3, x3, max_size);
111  check_consistent_size(function, name4, x4, max_size);
112 }
113 template <typename T1, typename T2, typename T3, typename T4, typename T5>
114 inline void check_consistent_sizes(const char* function, const char* name1,
115  const T1& x1, const char* name2,
116  const T2& x2, const char* name3,
117  const T3& x3, const char* name4,
118  const T4& x4, const char* name5,
119  const T5& x5) {
120  size_t max_size = std::max(
121  size_of(x1),
122  std::max(size_of(x2),
123  std::max(size_of(x3), std::max(size_of(x4), size_of(x5)))));
124  check_consistent_size(function, name1, x1, max_size);
125  check_consistent_size(function, name2, x2, max_size);
126  check_consistent_size(function, name3, x3, max_size);
127  check_consistent_size(function, name4, x4, max_size);
128  check_consistent_size(function, name5, x5, max_size);
129 }
130 
131 } // namespace math
132 } // namespace stan
133 #endif
T max(const caf::Proxy< T > &a, T b)
Float_t x1[n_points_granero]
Definition: compare.C:5
def is_vector(type)
void check_consistent_size(const char *function, const char *name, const T &x, size_t expected_size)
size_t size_of(const T &x)
Definition: size_of.hpp:20
size_t max_size(const T1 &x1, const T2 &x2)
Definition: max_size.hpp:9
void check_consistent_sizes(const char *function, const char *name1, const T1 &x1, const char *name2, const T2 &x2)