1#ifndef STAN_MATH_PRIM_ERR_CHECK_STOCHASTIC_ROW_HPP
2#define STAN_MATH_PRIM_ERR_CHECK_STOCHASTIC_ROW_HPP
34template <
typename T, require_matrix_t<T>* =
nullptr>
40 for (Eigen::Index i = 0; i < theta_ref.rows(); ++i) {
42 for (Eigen::Index j = 0; j < theta_ref.cols(); ++j) {
43 if (!(theta_ref.coeff(i, j) >= 0)) {
45 std::ostringstream msg;
46 msg <<
"is not a valid row stochastic matrix. " << name <<
"["
50 std::string msg_str(msg.str());
53 ", but should be greater than or equal to 0");
56 vec_sum += theta_ref.coeff(i, j);
60 std::stringstream msg;
61 msg <<
"is not a valid row stochastic matrix.";
63 msg <<
" sum(" << name <<
"[" << std::to_string(i + 1)
64 <<
",:]) = " << vec_sum <<
", but should be ";
65 std::string msg_str(msg.str());
88template <
typename T, require_std_vector_t<T>* =
nullptr>
91 for (
size_t i = 0; i < theta.size(); ++i) {
typename value_type< T >::type value_type_t
Helper function for accessing underlying type.
auto make_iter_name(const char *name)
double value_of_rec(const fvar< T > &v)
Return the value of the specified variable.
void throw_domain_error(const char *function, const char *name, const T &y, const char *msg1, const char *msg2)
Throw a domain error with a consistently formatted message.
void check_stochastic_row(const char *function, const char *name, const T &theta)
Throw an exception if the specified matrix is not a row stochastic matrix.
ref_type_t< T && > to_ref(T &&a)
This evaluates expensive Eigen expressions.
void check_nonzero_size(const char *function, const char *name, const T_y &y)
Check if the specified matrix/vector is of non-zero size.
const double CONSTRAINT_TOLERANCE
The tolerance for checking arithmetic bounds in rank and in simplexes.
fvar< T > fabs(const fvar< T > &x)
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...