1 #ifndef STAN_MATH_PRIM_MAT_ERR_CHECK_VECTOR_HPP
2 #define STAN_MATH_PRIM_MAT_ERR_CHECK_VECTOR_HPP
3 
4 #include <stan/math/prim/scal/meta/scalar_type.hpp>
5 #include <stan/math/prim/scal/err/invalid_argument.hpp>
6 #include <stan/math/prim/mat/fun/Eigen.hpp>
7 #include <sstream>
8 #include <string>
9 
10 namespace stan {
11 namespace math {
12 
13 /**
14  * Check if the matrix is either a
15  * row vector or column vector.
16  *
17  * This function checks the runtime size of the matrix to check
18  * whether it is a row or column vector.
19  *
20  * @tparam T Scalar type of the matrix
21  * @tparam R Compile time rows of the matrix
22  * @tparam C Compile time columns of the matrix
23  *
24  * @param function Function name (for error messages)
25  * @param name Variable name (for error messages)
26  * @param x Matrix
27  *
28  * @throw <code>std::invalid_argument</code> if x is not a row or column
29  *   vector.
30  */
31 template <typename T, int R, int C>
check_vector(const char * function,const char * name,const Eigen::Matrix<T,R,C> & x)32 inline void check_vector(const char* function, const char* name,
33                          const Eigen::Matrix<T, R, C>& x) {
34   if (R == 1)
35     return;
36   if (C == 1)
37     return;
38   if (x.rows() == 1 || x.cols() == 1)
39     return;
40 
41   std::ostringstream msg;
42   msg << ") has " << x.rows() << " rows and " << x.cols()
43       << " columns but it should be a vector so it should "
44       << "either have 1 row or 1 column";
45   std::string msg_str(msg.str());
46   invalid_argument(function, name, typename scalar_type<T>::type(), "(",
47                    msg_str.c_str());
48 }
49 
50 }  // namespace math
51 }  // namespace stan
52 #endif
53