Skip to content

Commit d26fd6a

Browse files
committed
Merge commit '46a31337d1534a1a5d5368311d7f32aef5ecc957' into HEAD
2 parents 4cb6dff + 46a3133 commit d26fd6a

9 files changed

Lines changed: 990 additions & 0 deletions

File tree

stan/math/prim/err/check_consistent_sizes.hpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
#ifndef STAN_MATH_PRIM_ERR_CHECK_CONSISTENT_SIZES_HPP
22
#define STAN_MATH_PRIM_ERR_CHECK_CONSISTENT_SIZES_HPP
33

4+
#include <stan/math/prim/err/check_matching_sizes.hpp>
45
#include <stan/math/prim/err/invalid_argument.hpp>
56
#include <stan/math/prim/fun/size.hpp>
7+
#include <stan/math/prim/meta/is_container.hpp>
68
#include <stan/math/prim/meta/require_generics.hpp>
79
#include <algorithm>
810
#include <sstream>
@@ -66,6 +68,34 @@ inline void check_consistent_sizes(const char* function, const char* name1,
6668
}
6769
}
6870

71+
/**
72+
* Check that the unnamed container inputs have the same size. Inputs are
73+
* labeled `arg1`, `arg2`, and so on in error messages.
74+
*
75+
* @tparam T type of the first input
76+
* @tparam Types types of the remaining inputs
77+
* @param function function name (for error messages)
78+
* @param x first input
79+
* @param xs remaining inputs
80+
* @throw `invalid_argument` if sizes are inconsistent
81+
*/
82+
template <typename T, typename... Types,
83+
require_all_container_t<T, Types...>* = nullptr>
84+
inline void check_consistent_sizes(const char* function, T&& x, Types&&... xs) {
85+
std::size_t arg_idx = 2;
86+
(
87+
[&](const auto& y) {
88+
if (x.size() != y.size()) {
89+
[&]() STAN_COLD_PATH {
90+
const std::string name = "arg" + std::to_string(arg_idx);
91+
check_matching_sizes(function, "arg1", x, name.c_str(), y);
92+
}();
93+
}
94+
++arg_idx;
95+
}(xs),
96+
...);
97+
}
98+
6999
} // namespace math
70100
} // namespace stan
71101
#endif

stan/math/prim/err/check_matching_dims.hpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,35 @@ inline void check_matching_dims(const char* function, const char* name1,
155155
check_matching_dims(function, name1, y1, name2, y2);
156156
}
157157

158+
/**
159+
* Check that the unnamed Eigen inputs have the same dimensions. Inputs are
160+
* labeled `arg1`, `arg2`, and so on in error messages.
161+
*
162+
* @tparam T type of the first input
163+
* @tparam Types types of the remaining inputs
164+
* @param function function name (for error messages)
165+
* @param x first input
166+
* @param xs remaining inputs
167+
* @throw `invalid_argument` if dimensions do not match
168+
*/
169+
template <typename T, typename... Types,
170+
require_all_eigen_t<T, Types...>* = nullptr>
171+
inline void check_matching_dims(const char* function, const T& x,
172+
const Types&... xs) {
173+
std::size_t arg_idx = 2;
174+
(
175+
[&](const auto& y) {
176+
if (x.rows() != y.rows() || x.cols() != y.cols()) {
177+
[&]() STAN_COLD_PATH {
178+
const std::string name = "arg" + std::to_string(arg_idx);
179+
check_matching_dims(function, "arg1", x, name.c_str(), y);
180+
}();
181+
}
182+
++arg_idx;
183+
}(xs),
184+
...);
185+
}
186+
158187
} // namespace math
159188
} // namespace stan
160189
#endif

stan/math/prim/functor.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <stan/math/prim/functor/ode_ckrk.hpp>
2424
#include <stan/math/prim/functor/ode_rk45.hpp>
2525
#include <stan/math/prim/functor/ode_store_sensitivities.hpp>
26+
#include <stan/math/prim/functor/map.hpp>
2627
#include <stan/math/prim/functor/map_if.hpp>
2728
#include <stan/math/prim/functor/map_rect.hpp>
2829
#include <stan/math/prim/functor/map_rect_combine.hpp>

0 commit comments

Comments
 (0)