1 #ifndef STAN_MATH_PRIM_FUN_SIZE_MVT_HPP 2 #define STAN_MATH_PRIM_FUN_SIZE_MVT_HPP 3 4 #include <stan/math/prim/meta.hpp> 5 #include <stan/math/prim/fun/Eigen.hpp> 6 #include <stdexcept> 7 #include <vector> 8 9 namespace stan { 10 namespace math { 11 12 /** \ingroup type_trait 13 * Provides the size of a multivariate argument. 14 * 15 * This is the default template function. For any scalar type, this 16 * will throw an std::invalid_argument exception since a scalar is not 17 * a multivariate structure. 18 * 19 * @tparam T type to take size of. The default template function should 20 * only match scalars. 21 * @throw std::invalid_argument since the type is a scalar. 22 */ 23 template <typename ScalarT, require_stan_scalar_t<ScalarT>* = nullptr> size_mvt(const ScalarT &)24size_t size_mvt(const ScalarT& /* unused */) { 25 throw std::invalid_argument("size_mvt passed to an unrecognized type."); 26 } 27 28 template <typename MatrixT, require_matrix_t<MatrixT>* = nullptr> size_mvt(const MatrixT &)29size_t size_mvt(const MatrixT& /* unused */) { 30 return 1U; 31 } 32 33 template <typename MatrixT, require_matrix_t<MatrixT>* = nullptr> size_mvt(const std::vector<MatrixT> & x)34size_t size_mvt(const std::vector<MatrixT>& x) { 35 return x.size(); 36 } 37 38 } // namespace math 39 } // namespace stan 40 #endif 41