1#ifndef STAN_MATH_REV_FUN_TRACE_INV_QUAD_FORM_LDLT_HPP
2#define STAN_MATH_REV_FUN_TRACE_INV_QUAD_FORM_LDLT_HPP
31template <
typename T1,
typename T2, require_all_matrix_t<T1, T2>* =
nullptr,
32 require_any_st_var<T1, T2>* =
nullptr>
36 if (A.matrix().size() == 0)
42 auto AsolveB =
to_arena(A.ldlt().solve(arena_B.val()));
44 var res = (arena_B.val_op().transpose() * AsolveB).
trace();
47 arena_A.adj() += -res.adj() * AsolveB * AsolveB.transpose();
48 arena_B.adj() += 2 * res.adj() * AsolveB;
54 const auto& B_ref =
to_ref(B);
61 arena_A.adj() += -res.adj() * AsolveB * AsolveB.transpose();
67 auto AsolveB =
to_arena(A.ldlt().solve(arena_B.val()));
69 var res = (arena_B.val_op().transpose() * AsolveB).
trace();
72 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 ...