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
9
10namespace stan {
11namespace math {
12
22template <typename T, require_eigen_t<T>* = nullptr>
24 const Eigen::Ref<const plain_type_t<T>>& L_ref = L;
25 check_square("chol2inv", "L", L_ref);
26 check_lower_triangular("chol2inv", "L", L_ref);
27 int K = L.rows();
28 using T_result = plain_type_t<T>;
29 if (K == 0) {
30 return L_ref;
31 }
32 if (K == 1) {
33 T_result X(1, 1);
34 X.coeffRef(0) = inv_square(L_ref.coeff(0, 0));
35 return X;
36 }
37 return crossprod(mdivide_left_tri<Eigen::Lower>(L_ref));
38}
39
40} // namespace math
41} // namespace stan
42
43#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(const T &L)
Returns the inverse of the matrix whose Cholesky factor is L.
Definition chol2inv.hpp:23
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
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< T >::type plain_type_t
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...