1 #ifndef STAN_MATH_PRIM_FUN_QUAD_FORM_DIAG_HPP
2 #define STAN_MATH_PRIM_FUN_QUAD_FORM_DIAG_HPP
3
4 #include <stan/math/prim/err.hpp>
5 #include <stan/math/prim/fun/Eigen.hpp>
6 #include <stan/math/prim/fun/to_ref.hpp>
7
8 namespace stan {
9 namespace math {
10
11 template <typename EigMat, typename EigVec, require_eigen_t<EigMat>* = nullptr,
12 require_eigen_vector_t<EigVec>* = nullptr>
quad_form_diag(const EigMat & mat,const EigVec & vec)13 inline auto quad_form_diag(const EigMat& mat, const EigVec& vec) {
14 check_square("quad_form_diag", "mat", mat);
15 check_size_match("quad_form_diag", "rows of mat", mat.rows(), "size of vec",
16 vec.size());
17 return make_holder(
18 [](const auto& v, const auto& x) {
19 return v.asDiagonal() * x * v.asDiagonal();
20 },
21 to_ref(vec), to_ref(mat));
22 }
23
24 } // namespace math
25 } // namespace stan
26
27 #endif
28