Automatic Differentiation
 
Loading...
Searching...
No Matches
trace_inv_quad_form_ldlt.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_PRIM_FUN_TRACE_INV_QUAD_FORM_LDLT_HPP
2#define STAN_MATH_PRIM_FUN_TRACE_INV_QUAD_FORM_LDLT_HPP
3
12
13namespace stan {
14namespace math {
15
26template <typename T, typename EigMat2,
27 typename = require_all_not_st_var<T, EigMat2>>
29 const EigMat2& B) {
30 check_multiplicable("trace_inv_quad_form_ldlt", "A", A.matrix(), "B", B);
31
32 if (A.matrix().size() == 0) {
33 return 0;
34 }
35
36 return B.cwiseProduct(mdivide_left_ldlt(A, B)).sum();
37}
38
39} // namespace math
40} // namespace stan
41
42#endif
LDLT_factor is a structure that holds a matrix of type T and the LDLT of its values.
typename return_type< Ts... >::type return_type_t
Convenience type for the return type of the specified template parameters.
return_type_t< T, EigMat2 > trace_inv_quad_form_ldlt(LDLT_factor< T > &A, const EigMat2 &B)
Compute the trace of an inverse quadratic form.
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< value_type_t< EigMat >, Eigen::Dynamic, EigMat::ColsAtCompileTime > mdivide_left_ldlt(LDLT_factor< T > &A, const EigMat &b)
Returns the solution of the system Ax=b given an LDLT_factor of A.
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...
Definition fvar.hpp:9