diff --git a/stan/math/prim/fun/chol2inv.hpp b/stan/math/prim/fun/chol2inv.hpp index 2c46de28dd8..8f2f3c3d866 100644 --- a/stan/math/prim/fun/chol2inv.hpp +++ b/stan/math/prim/fun/chol2inv.hpp @@ -3,10 +3,9 @@ #include #include -#include -#include #include #include +#include namespace stan { namespace math { @@ -35,17 +34,7 @@ plain_type_t chol2inv(const T& L) { X.coeffRef(0) = inv_square(L_ref.coeff(0, 0)); return X; } - T_result L_inv = mdivide_left_tri(L_ref); - T_result X(K, K); - for (int k = 0; k < K; ++k) { - X.coeffRef(k, k) = dot_self(L_inv.col(k).tail(K - k).eval()); - for (int j = k + 1; j < K; ++j) { - int Kmj = K - j; - X.coeffRef(k, j) = X.coeffRef(j, k) = dot_product( - L_inv.col(k).tail(Kmj).eval(), L_inv.col(j).tail(Kmj).eval()); - } - } - return X; + return crossprod(mdivide_left_tri(L_ref)); } } // namespace math