1#ifndef STAN_MATH_PRIM_ERR_CHECK_MATCHING_DIMS_HPP
2#define STAN_MATH_PRIM_ERR_CHECK_MATCHING_DIMS_HPP
26template <
typename T1,
typename T2, require_all_not_matrix_t<T1, T2>* =
nullptr,
27 require_all_not_nonscalar_prim_or_rev_kernel_expression_t<
30 const T1& y1,
const char* name2,
const T2& y2) {
31 std::vector<int> y1_d =
dims(y1);
32 std::vector<int> y2_d =
dims(y2);
34 std::ostringstream y1s;
35 if (y1_d.size() > 0) {
37 for (
int i = 1; i < y1_d.size(); i++) {
38 y1s <<
", " << y1_d[i];
41 std::ostringstream msg;
42 msg <<
") and " << name2 <<
" (";
43 if (y2_d.size() > 0) {
45 for (
int i = 1; i < y2_d.size(); i++) {
46 msg <<
", " << y2_d[i];
49 msg <<
") must match in size";
50 std::string msg_str(msg.str());
53 if (y1_d.size() != y2_d.size()) {
56 for (
int i = 0; i < y1_d.size(); i++) {
57 if (y1_d[i] != y2_d[i]) {
77 typename T1,
typename T2,
79 conjunction<is_prim_or_rev_kernel_expression<T1>,
83 const T1& y1,
const char* name2,
const T2& y2) {
84 if (y1.rows() != y2.rows() || y1.cols() != y2.cols()) {
86 std::ostringstream y1_err;
87 std::ostringstream msg_str;
88 y1_err <<
"(" << y1.rows() <<
", " << y1.cols() <<
") and ";
89 msg_str <<
" (" << y2.rows() <<
", " << y2.cols()
90 <<
") must match in size";
92 std::string(y1_err.str()).c_str(),
93 std::string(msg_str.str()).c_str());
112template <
typename T1,
typename T2, require_any_matrix_t<T1, T2>* =
nullptr,
113 require_any_stan_scalar_t<T1, T2>* =
nullptr>
115 const T1& y1,
const char* name2,
const T2& y2) {
116 std::string y1_err(
"");
117 std::string msg_str(
"Tried Checking the dimensions of a matrix vs a scalar");
137template <
bool check_compile,
typename Mat1,
typename Mat2,
138 typename = require_all_eigen_t<Mat1, Mat2>>
140 const Mat1& y1,
const char* name2,
143 && (
static_cast<int>(Mat1::RowsAtCompileTime)
144 !=
static_cast<int>(Mat2::RowsAtCompileTime)
145 ||
static_cast<int>(Mat1::ColsAtCompileTime)
146 !=
static_cast<int>(Mat2::ColsAtCompileTime))) {
148 std::ostringstream msg;
149 msg <<
"Static rows and cols of " << name1 <<
" and " << name2
150 <<
" must match in size.";
151 std::string msg_str(msg.str());
void dims(const T_x &x, std::vector< int > &result)
matrix_cl overload of the dims helper function in prim/fun/dims.hpp.
require_any_not_t< is_stan_scalar< std::decay_t< Types > >... > require_any_not_stan_scalar_t
Require at least one of the types do not satisfy is_stan_scalar.
void check_matching_dims(const char *function, const char *name1, const T1 &y1, const char *name2, const T2 &y2)
Check if the two containers have the same dimensions.
void invalid_argument(const char *function, const char *name, const T &y, const char *msg1, const char *msg2)
Throw an invalid_argument exception with a consistently formatted message.
std::enable_if_t< math::disjunction< Checks... >::value > require_any_t
If any condition is true, template is enabled.
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...
Check if a type is derived from Eigen::EigenBase or is a var_value whose value_type is derived from E...
Determines whether a type is either a kernel generator expression or a var containing a kernel genera...