1#ifndef STAN_MATH_REV_FUN_TRACE_INV_QUAD_FORM_LDLT_HPP
2#define STAN_MATH_REV_FUN_TRACE_INV_QUAD_FORM_LDLT_HPP
30template <
typename T1,
typename T2, require_all_matrix_t<T1, T2>* =
nullptr,
31 require_any_st_var<T1, T2>* =
nullptr>
35 if (A.matrix().size() == 0)
41 auto AsolveB =
to_arena(A.ldlt().solve(arena_B.val()));
43 var res = (arena_B.val_op().transpose() * AsolveB).
trace();
46 arena_A.adj() += -res.adj() * AsolveB * AsolveB.transpose();
47 arena_B.adj() += 2 * res.adj() * AsolveB;
53 const auto& B_ref =
to_ref(B);
60 arena_A.adj() += -res.adj() * AsolveB * AsolveB.transpose();
66 auto AsolveB =
to_arena(A.ldlt().solve(arena_B.val()));
68 var res = (arena_B.val_op().transpose() * AsolveB).
trace();
71 arena_B.adj() += 2 * res.adj() * AsolveB;
LDLT_factor is a structure that holds a matrix of type T and the LDLT of its values.
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.
void reverse_pass_callback(F &&functor)
Puts a callback on the autodiff stack to be called in reverse pass.
T value_of(const fvar< T > &v)
Return the value of the specified variable.
value_type_t< T > trace(const T &m)
Calculates trace (sum of diagonal) of given kernel generator expression.
arena_t< T > to_arena(const T &a)
Converts given argument into a type that either has any dynamic allocation on AD stack or schedules i...
ref_type_t< T && > to_ref(T &&a)
This evaluates expensive Eigen expressions.
typename internal::arena_type_impl< std::decay_t< T > >::type arena_t
Determines a type that can be used in place of T that does any dynamic allocations on the AD stack.
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...
Metaprogramming struct to detect whether a given type is constant in the mathematical sense (not the ...