1 #ifndef __STAN__MATH__ERROR_HANDLING__MATRIX__CHECK_SIMPLEX_HPP__
2 #define __STAN__MATH__ERROR_HANDLING__MATRIX__CHECK_SIMPLEX_HPP__
31 template <
typename T_prob,
typename T_result>
33 const Eigen::Matrix<T_prob,Eigen::Dynamic,1>& theta,
40 if (theta.size() == 0) {
41 std::stringstream msg;
42 msg <<
" is not a valid simplex. "
43 <<
"length(" << name <<
") = %1%";
44 std::string tmp(msg.str());
50 std::stringstream msg;
51 T_prob
sum = theta.sum();
52 msg <<
" is not a valid simplex.";
54 msg <<
" sum(" << name <<
") = " << sum
55 <<
", but should be %1%";
56 std::string tmp(msg.str());
57 return dom_err(
function,1.0,name,
61 for (
size_t n = 0; n < theta.size(); n++) {
62 if (!(theta[n] >= 0)) {
63 std::ostringstream stream;
64 stream <<
" is not a valid simplex. "
66 <<
" = %1%, but should be greater than or equal to 0";
67 std::string tmp(stream.str());
68 return dom_err(
function,theta[n],name,
fvar< T > fabs(const fvar< T > &x)
bool dom_err(const char *function, const T &y, const char *name, const char *error_msg, const T_msg error_msg2, T_result *result)
bool check_simplex(const char *function, const Eigen::Matrix< T_prob, Eigen::Dynamic, 1 > &theta, const char *name, T_result *result)
Return true if the specified vector is simplex.
const double CONSTRAINT_TOLERANCE
The tolerance for checking arithmetic bounds In rank and in simplexes.
Primary template class for the metaprogram to compute the index type of a container.
double sum(std::vector< double > &x)