bool check_positive_ordered(const char* function, const Eigen::Matrix<T_y,Eigen::Dynamic,1>& y, const char* name, T_result* result) { typedef typename Eigen::Matrix<T_y,Eigen::Dynamic,1>::size_type size_type; if (y.size() == 0) { return true; } if (y[0] < 0) { std::ostringstream stream; stream << " is not a valid positive_ordered vector." << " The element at " << stan::error_index::value << " is %1%, but should be postive."; std::string msg(stream.str()); return dom_err(function,y[0],name, msg.c_str(),"", result); } for (size_type n = 1; n < y.size(); n++) { if (!(y[n] > y[n-1])) { std::ostringstream stream; stream << " is not a valid ordered vector." << " The element at " << stan::error_index::value + n << " is %1%, but should be greater than the previous element, " << y[n-1]; std::string msg(stream.str()); return dom_err(function,y[n],name, msg.c_str(),"", result); } } return true; }
bool check_unit_vector(const char* function, const Eigen::Matrix<T_prob,Eigen::Dynamic,1>& theta, const char* name, T_result* result) { typedef typename Eigen::Matrix<T_prob,Eigen::Dynamic,1>::size_type size_t; if (theta.size() == 0) { std::string message(name); message += " is not a valid unit vector. %1% elements in the vector."; return dom_err(function,0,name, message.c_str(),"", result); } T_prob ssq = theta.squaredNorm(); if (fabs(1.0 - ssq) > CONSTRAINT_TOLERANCE) { std::stringstream msg; msg << "in function check_unit_vector(%1%), "; msg << name << " is not a valid unit vector."; msg << " The sum of the squares of the elements should be 1, but is " << ssq; std::string tmp(msg.str()); return dom_err(function,ssq,name, tmp.c_str(),"", result); } return true; }
inline bool check_pos_definite(const char* function, const Eigen::Matrix<T_y,Eigen::Dynamic,Eigen::Dynamic>& y, const char* name, T_result* result) { typedef typename Eigen::Matrix<T_y,Eigen::Dynamic,Eigen::Dynamic>::size_type size_type; if (y.rows() == 1 && y(0,0) <= CONSTRAINT_TOLERANCE) { std::ostringstream message; message << name << " is not positive definite. " << name << "(0,0) is %1%."; std::string msg(message.str()); return dom_err(function,y(0,0),name,msg.c_str(),"",result); } Eigen::LDLT< Eigen::Matrix<T_y,Eigen::Dynamic,Eigen::Dynamic> > cholesky = y.ldlt(); if(cholesky.info() != Eigen::Success || cholesky.isNegative() || (cholesky.vectorD().array() <= CONSTRAINT_TOLERANCE).any()) { std::ostringstream message; message << name << " is not positive definite. " << name << "(0,0) is %1%."; std::string msg(message.str()); return dom_err(function,y(0,0),name,msg.c_str(),"",result); } return true; }
inline bool check_symmetric(const char* function, const Eigen::Matrix<T_y,Eigen::Dynamic,Eigen::Dynamic>& y, const char* name, T_result* result) { typedef typename Eigen::Matrix<T_y,Eigen::Dynamic,Eigen::Dynamic>::size_type size_type; size_type k = y.rows(); if (k == 1) return true; for (size_type m = 0; m < k; ++m) { for (size_type n = m + 1; n < k; ++n) { if (fabs(y(m,n) - y(n,m)) > CONSTRAINT_TOLERANCE) { std::ostringstream message; message << name << " is not symmetric. " << name << "[" << m << "," << n << "] is %1%, but " << name << "[" << n << "," << m << "] element is " << y(n,m); std::string msg(message.str()); return dom_err(function,y(m,n),name, msg.c_str(),"", result); } } } return true; }
inline bool check_vector(const std::string& function, const std::string& name, const Eigen::Matrix<T,R,C>& x) { if (x.rows() == 1 || x.cols() == 1) return true; std::ostringstream msg; msg << ") has " << x.rows() << " rows and " << x.cols() << " columns but it should be a vector so it should " << "either have 1 row or 1 column"; dom_err(function, name, typename scalar_type<T>::type(), "(", msg.str()); return false; }
inline bool check_consistent_size(size_t max_size, const char* function, const T& x, const char* name, T_result* result, const Policy&) { size_t x_size = stan::size_of(x); if (is_vector<T>::value && x_size == max_size) return true; if (!is_vector<T>::value && x_size == 1) return true; return dom_err( function,x_size,name, " (max size) is %1%, but must be consistent, 1 or max=",max_size, result,Policy()); }
inline bool check_row_index(const char* function, size_t i, const Eigen::Matrix<T_y,R,C>& y, const char* name, T_result* result) { if ((i > 0) && (i <= static_cast<size_t>(y.rows()))) return true; std::ostringstream msg; msg << name << " (%1%) must be greater than 0 and less than " << y.rows(); std::string tmp(msg.str()); return dom_err(function,i,name, tmp.c_str(),"", result); }
inline void dom_err(const std::string& function, const std::string& name, const T& y, const std::string& msg1) { dom_err(function, name, y, msg1, ""); }