1#ifndef STAN_MATH_REV_FUN_LOG_DETERMINANT_SPD_HPP
2#define STAN_MATH_REV_FUN_LOG_DETERMINANT_SPD_HPP
24template <
typename T, require_rev_matrix_t<T>* =
nullptr>
33 auto M_ldlt = M_d.ldlt();
34 if (M_ldlt.info() != Eigen::Success) {
35 constexpr double y = 0;
37 "failed LDLT factorization");
40 M_d.setIdentity(M.rows(), M.cols());
41 M_ldlt.solveInPlace(M_d);
42 auto arena_M_inv_transpose =
to_arena(M_d.transpose());
44 if (M_ldlt.isNegative() || (M_ldlt.vectorD().array() <= 1
e-16).any()) {
45 constexpr double y = 0;
47 "matrix is negative definite");
53 arena_M.adj() += log_det.adj() * arena_M_inv_transpose;
void check_symmetric(const char *function, const char *name, const matrix_cl< T > &y)
Check if the matrix_cl is symmetric.
static constexpr double e()
Return the base of the natural logarithm.
value_type_t< EigMat > log_determinant_spd(const EigMat &m)
Returns the log absolute determinant of the specified square matrix.
void reverse_pass_callback(F &&functor)
Puts a callback on the autodiff stack to be called in reverse pass.
fvar< T > log(const fvar< T > &x)
void throw_domain_error(const char *function, const char *name, const T &y, const char *msg1, const char *msg2)
Throw a domain error with a consistently formatted message.
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...
auto sum(const std::vector< T > &m)
Return the sum of the entries of the specified standard vector.
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic > matrix_d
Type for matrix of double values.
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 ...