Stan Math Library  2.15.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 
11 
12 namespace stan {
13  namespace math {
14 
15  template<int RA, int CA, int RB, int CB, typename T>
16  inline Eigen::Matrix<T, CB, CB>
17  quad_form_sym(const Eigen::Matrix<T, RA, CA>& A,
18  const Eigen::Matrix<T, RB, CB>& B) {
19  check_square("quad_form_sym", "A", A);
20  check_multiplicable("quad_form_sym", "A", A, "B", B);
21  check_symmetric("quad_form_sym", "A", A);
22  Eigen::Matrix<T, CB, CB> ret(multiply(transpose(B), multiply(A, B)));
23  return T(0.5) * (ret + transpose(ret));
24  }
25 
26  template<int RA, int CA, int RB, typename T>
27  inline T
28  quad_form_sym(const Eigen::Matrix<T, RA, CA>& A,
29  const Eigen::Matrix<T, RB, 1>& B) {
30  check_square("quad_form_sym", "A", A);
31  check_multiplicable("quad_form_sym", "A", A, "B", B);
32  check_symmetric("quad_form_sym", "A", A);
33  return dot_product(B, multiply(A, B));
34  }
35 
36  }
37 }
38 #endif
Eigen::Matrix< fvar< T >, R1, C1 > multiply(const Eigen::Matrix< fvar< T >, R1, C1 > &m, const fvar< T > &c)
Definition: multiply.hpp:20
void check_symmetric(const char *function, const char *name, const Eigen::Matrix< T_y, Eigen::Dynamic, Eigen::Dynamic > &y)
Check if the specified matrix is symmetric.
fvar< T > dot_product(const Eigen::Matrix< fvar< T >, R1, C1 > &v1, const Eigen::Matrix< fvar< T >, R2, C2 > &v2)
Definition: dot_product.hpp:18
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.
void check_square(const char *function, const char *name, const Eigen::Matrix< T_y, Eigen::Dynamic, Eigen::Dynamic > &y)
Check if the specified matrix is square.
Eigen::Matrix< fvar< T >, CB, CB > quad_form_sym(const Eigen::Matrix< fvar< T >, RA, CA > &A, const Eigen::Matrix< double, RB, CB > &B)
Eigen::Matrix< T, C, R > transpose(const Eigen::Matrix< T, R, C > &m)
Definition: transpose.hpp:12

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