Stan Math Library  2.20.0
reverse mode automatic differentiation
trace_inv_quad_form_ldlt.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_MAT_FUN_TRACE_INV_QUAD_FORM_LDLT_HPP
2 #define STAN_MATH_PRIM_MAT_FUN_TRACE_INV_QUAD_FORM_LDLT_HPP
3 
12 
13 namespace stan {
14 namespace math {
15 
16 /*
17  * Compute the trace of an inverse quadratic form. I.E., this computes
18  * trace(B^T A^-1 B)
19  * where the LDLT_factor of A is provided.
20  */
21 template <typename T1, typename T2, int R2, int C2, int R3, int C3>
22 inline typename std::enable_if<
24  typename boost::math::tools::promote_args<T1, T2>::type>::type
26  const Eigen::Matrix<T2, R3, C3> &B) {
27  check_multiplicable("trace_inv_quad_form_ldlt", "A", A, "B", B);
28 
29  return trace(multiply(transpose(B), mdivide_left_ldlt(A, B)));
30 }
31 
32 } // namespace math
33 } // namespace stan
34 #endif
Defines a public enum named value which is defined to be false as the primitive scalar types cannot b...
Definition: is_var.hpp:10
Eigen::Matrix< fvar< T2 >, R1, C2 > mdivide_left_ldlt(const 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.
Eigen::Matrix< fvar< T >, R1, C1 > multiply(const Eigen::Matrix< fvar< T >, R1, C1 > &m, const fvar< T > &c)
Definition: multiply.hpp:14
LDLT_factor is a thin wrapper on Eigen::LDLT to allow for reusing factorizations and efficient autodi...
Definition: LDLT_factor.hpp:63
std::enable_if< !stan::is_var< T1 >::value &&!stan::is_var< T2 >::value, typename boost::math::tools::promote_args< T1, T2 >::type >::type trace_inv_quad_form_ldlt(const LDLT_factor< T1, R2, C2 > &A, const Eigen::Matrix< T2, R3, C3 > &B)
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.
matrix_cl transpose(const matrix_cl &src)
Takes the transpose of the matrix on the OpenCL device.
Definition: transpose.hpp:20
T trace(const Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > &m)
Returns the trace of the specified matrix.
Definition: trace.hpp:19

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