Stan Math Library  2.20.0
reverse mode automatic differentiation
quad_form_sym.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_MAT_FUN_QUAD_FORM_SYM_HPP
2 #define STAN_MATH_PRIM_MAT_FUN_QUAD_FORM_SYM_HPP
3 
8 
9 namespace stan {
10 namespace math {
11 
12 template <int RA, int CA, int RB, int CB, typename T>
13 inline Eigen::Matrix<T, CB, CB> quad_form_sym(
14  const Eigen::Matrix<T, RA, CA>& A, const Eigen::Matrix<T, RB, CB>& B) {
15  check_square("quad_form_sym", "A", A);
16  check_multiplicable("quad_form_sym", "A", A, "B", B);
17  check_symmetric("quad_form_sym", "A", A);
18  Eigen::Matrix<T, CB, CB> ret(B.transpose() * A * B);
19  return T(0.5) * (ret + ret.transpose());
20 }
21 
22 template <int RA, int CA, int RB, typename T>
23 inline T quad_form_sym(const Eigen::Matrix<T, RA, CA>& A,
24  const Eigen::Matrix<T, RB, 1>& B) {
25  check_square("quad_form_sym", "A", A);
26  check_multiplicable("quad_form_sym", "A", A, "B", B);
27  check_symmetric("quad_form_sym", "A", A);
28  return B.dot(A * B);
29 }
30 
31 } // namespace math
32 } // namespace stan
33 #endif
void check_square(const char *function, const char *name, const matrix_cl &y)
Check if the matrix_cl is square.
void check_multiplicable(const char *function, const char *name1, const T1 &y1, const char *name2, const T2 &y2)
Check if the matrices can be multiplied.
Eigen::Matrix< fvar< T >, CB, CB > quad_form_sym(const Eigen::Matrix< fvar< T >, RA, CA > &A, const Eigen::Matrix< double, RB, CB > &B)
void check_symmetric(const char *function, const char *name, const matrix_cl &y)
Check if the matrix_cl is symmetric.

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