1 #ifndef STAN_MATH_PRIM_SCAL_ERR_CHECK_NONZERO_SIZE_HPP
2 #define STAN_MATH_PRIM_SCAL_ERR_CHECK_NONZERO_SIZE_HPP
3 
4 #include <stan/math/prim/scal/err/invalid_argument.hpp>
5 
6 namespace stan {
7 namespace math {
8 
9 /**
10  * Check if the specified matrix/vector is of non-zero size.
11  * Throws a std:invalid_argument otherwise. The message
12  * will indicate that the variable name "has size 0".
13  * @tparam T_y Type of container
14  * @param function Function name (for error messages)
15  * @param name Variable name (for error messages)
16  * @param y Container to test. This will accept matrices and vectors
17  * @throw <code>std::invalid_argument</code> if the specified matrix/vector
18  *   has zero size
19  */
20 template <typename T_y>
check_nonzero_size(const char * function,const char * name,const T_y & y)21 inline void check_nonzero_size(const char* function, const char* name,
22                                const T_y& y) {
23   if (y.size() > 0)
24     return;
25   invalid_argument(function, name, 0, "has size ",
26                    ", but must have a non-zero size");
27 }
28 
29 }  // namespace math
30 }  // namespace stan
31 #endif
32