Automatic Differentiation
 
Loading...
Searching...
No Matches
chol2inv.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_PRIM_FUN_CHOL2INV_HPP
2#define STAN_MATH_PRIM_FUN_CHOL2INV_HPP
3
10
11namespace stan {
12namespace math {
13
23template <typename T, require_eigen_t<T>* = nullptr>
25 decltype(auto) L_ref = to_ref(std::forward<T>(L));
26 check_square("chol2inv", "L", L_ref);
27 check_lower_triangular("chol2inv", "L", L_ref);
28 int K = L_ref.rows();
29 using T_result = plain_type_t<T>;
30 if (K == 0) {
31 return std::forward<decltype(L_ref)>(L_ref);
32 }
33 if (K == 1) {
34 T_result X(1, 1);
35 X.coeffRef(0) = inv_square(L_ref.coeff(0, 0));
36 return X;
37 }
38 return crossprod(
39 mdivide_left_tri<Eigen::Lower>(std::forward<decltype(L_ref)>(L_ref)));
40}
41
42} // namespace math
43} // namespace stan
44
45#endif
void check_square(const char *function, const char *name, const T_y &y)
Check if the specified matrix is square.
fvar< T > inv_square(const fvar< T > &x)
plain_type_t< T > chol2inv(T &&L)
Returns the inverse of the matrix whose Cholesky factor is L.
Definition chol2inv.hpp:24
matrix_cl< typename std::decay_t< T_A >::Scalar > crossprod(T_A &&A)
Returns the result of pre-multiplying a matrix by its own transpose.
Definition crossprod.hpp:21
ref_type_t< T && > to_ref(T &&a)
This evaluates expensive Eigen expressions.
Definition to_ref.hpp:18
void check_lower_triangular(const char *function, const char *name, const T_y &y)
Check if the specified matrix is lower triangular.
typename plain_type< std::decay_t< T > >::type plain_type_t
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...