Stan Math Library  2.9.0
reverse mode automatic differentiation
trace_gen_inv_quad_form_ldlt.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_MAT_FUN_TRACE_GEN_INV_QUAD_FORM_LDLT_HPP
2 #define STAN_MATH_PRIM_MAT_FUN_TRACE_GEN_INV_QUAD_FORM_LDLT_HPP
3 
13 
14 namespace stan {
15  namespace math {
16 
17  /*
18  * Compute the trace of an inverse quadratic form. I.E., this computes
19  * trace(D B^T A^-1 B)
20  * where D is a square matrix and the LDLT_factor of A is provided.
21  */
22  template <typename T1, typename T2, typename T3,
23  int R1, int C1, int R2, int C2, int R3, int C3>
24  inline typename
25  boost::enable_if_c<!stan::is_var<T1>::value &&
28  typename
29  boost::math::tools::promote_args<T1, T2, T3>::type>::type
30  trace_gen_inv_quad_form_ldlt(const Eigen::Matrix<T1, R1, C1> &D,
32  const Eigen::Matrix<T3, R3, C3> &B) {
33  stan::math::check_square("trace_gen_inv_quad_form_ldlt", "D", D);
34  stan::math::check_multiplicable("trace_gen_inv_quad_form_ldlt",
35  "A", A,
36  "B", B);
37  stan::math::check_multiplicable("trace_gen_inv_quad_form_ldlt",
38  "B", B,
39  "D", D);
40 
41  return trace(multiply(multiply(D, transpose(B)),
42  mdivide_left_ldlt(A, B)));
43  }
44 
45  }
46 }
47 #endif
Eigen::Matrix< fvar< T >, R1, C1 > multiply(const Eigen::Matrix< fvar< T >, R1, C1 > &m, const fvar< T > &c)
Definition: multiply.hpp:20
boost::enable_if_c<!stan::is_var< T1 >::value &&!stan::is_var< T2 >::value &&!stan::is_var< T3 >::value, typename boost::math::tools::promote_args< T1, T2, T3 >::type >::type trace_gen_inv_quad_form_ldlt(const Eigen::Matrix< T1, R1, C1 > &D, const stan::math::LDLT_factor< T2, R2, C2 > &A, const Eigen::Matrix< T3, R3, C3 > &B)
Eigen::Matrix< fvar< T2 >, R1, C2 > mdivide_left_ldlt(const stan::math::LDLT_factor< double, R1, C1 > &A, const Eigen::Matrix< fvar< T2 >, R2, C2 > &b)
Returns the solution of the system Ax=b given an LDLT_factor of A.
bool check_multiplicable(const char *function, const char *name1, const T1 &y1, const char *name2, const T2 &y2)
Return true if the matrices can be multiplied.
T trace(const Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > &m)
Returns the trace of the specified matrix.
Definition: trace.hpp:20
Eigen::Matrix< T, C, R > transpose(const Eigen::Matrix< T, R, C > &m)
Definition: transpose.hpp:12
bool check_square(const char *function, const char *name, const Eigen::Matrix< T_y, Eigen::Dynamic, Eigen::Dynamic > &y)
Return true if the specified matrix is square.

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