1 #ifndef STAN_MATH_PRIM_FUN_ROWS_DOT_PRODUCT_HPP
2 #define STAN_MATH_PRIM_FUN_ROWS_DOT_PRODUCT_HPP
3 
4 #include <stan/math/prim/err.hpp>
5 #include <stan/math/prim/fun/Eigen.hpp>
6 
7 namespace stan {
8 namespace math {
9 
10 /**
11  * Returns the dot product of rows of the specified matrices.
12  *
13  * @tparam Mat1 type of the first matrix (must be derived from \c
14  * Eigen::MatrixBase)
15  * @tparam Mat2 type of the second matrix (must be derived from \c
16  * Eigen::MatrixBase)
17  *
18  * @param v1 Matrix of first vectors.
19  * @param v2 Matrix of second vectors.
20  * @return Dot product of the vectors.
21  * @throw std::domain_error If the matrices are not the same
22  * size
23  */
24 template <typename Mat1, typename Mat2,
25           require_all_eigen_t<Mat1, Mat2>* = nullptr,
26           require_all_not_eigen_vt<is_var, Mat1, Mat2>* = nullptr>
27 inline Eigen::Matrix<return_type_t<Mat1, Mat2>, Mat1::RowsAtCompileTime, 1>
rows_dot_product(const Mat1 & v1,const Mat2 & v2)28 rows_dot_product(const Mat1& v1, const Mat2& v2) {
29   check_matching_sizes("rows_dot_product", "v1", v1, "v2", v2);
30   return (v1.cwiseProduct(v2)).rowwise().sum();
31 }
32 
33 }  // namespace math
34 }  // namespace stan
35 
36 #endif
37