Stan Math Library  2.20.0
reverse mode automatic differentiation
quad_form_diag.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_MAT_FUN_QUAD_FORM_DIAG_HPP
2 #define STAN_MATH_PRIM_MAT_FUN_QUAD_FORM_DIAG_HPP
3 
5 #include <boost/math/tools/promotion.hpp>
9 
10 namespace stan {
11 namespace math {
12 
13 template <typename T1, typename T2, int R, int C>
14 inline Eigen::Matrix<typename boost::math::tools::promote_args<T1, T2>::type,
15  Eigen::Dynamic, Eigen::Dynamic>
16 quad_form_diag(const Eigen::Matrix<T1, Eigen::Dynamic, Eigen::Dynamic>& mat,
17  const Eigen::Matrix<T2, R, C>& vec) {
18  check_vector("quad_form_diag", "vec", vec);
19  check_square("quad_form_diag", "mat", mat);
20  check_size_match("quad_form_diag", "rows of mat", mat.rows(), "size of vec",
21  vec.size());
22  return vec.asDiagonal() * mat * vec.asDiagonal();
23 }
24 
25 } // namespace math
26 } // namespace stan
27 #endif
void check_square(const char *function, const char *name, const matrix_cl &y)
Check if the matrix_cl is square.
void check_vector(const char *function, const char *name, const Eigen::Matrix< T, R, C > &x)
Check if the matrix is either a row vector or column vector.
void check_size_match(const char *function, const char *name_i, T_size1 i, const char *name_j, T_size2 j)
Check if the provided sizes match.
Eigen::Matrix< typename boost::math::tools::promote_args< T1, T2 >::type, Eigen::Dynamic, Eigen::Dynamic > quad_form_diag(const Eigen::Matrix< T1, Eigen::Dynamic, Eigen::Dynamic > &mat, const Eigen::Matrix< T2, R, C > &vec)

     [ Stan Home Page ] © 2011–2018, Stan Development Team.