Skip to content

Commit 2157520

Browse files
committed
use to_ref and plain_type_t in cholesky_decompose for prim
1 parent 0c1b65a commit 2157520

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

stan/math/prim/fun/cholesky_decompose.hpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
#ifndef STAN_MATH_PRIM_FUN_CHOLESKY_DECOMPOSE_HPP
22
#define STAN_MATH_PRIM_FUN_CHOLESKY_DECOMPOSE_HPP
33

4-
#include <stan/math/prim/fun/Eigen.hpp>
54
#include <stan/math/prim/meta.hpp>
65
#include <stan/math/prim/err.hpp>
6+
#include <stan/math/prim/fun/Eigen.hpp>
7+
8+
#include <cmath>
79

810
namespace stan {
911
namespace math {
@@ -26,14 +28,11 @@ namespace math {
2628
*/
2729
template <typename EigMat, require_eigen_t<EigMat>* = nullptr,
2830
require_not_eigen_vt<is_var, EigMat>* = nullptr>
29-
inline Eigen::Matrix<value_type_t<EigMat>, EigMat::RowsAtCompileTime,
30-
EigMat::ColsAtCompileTime>
31-
cholesky_decompose(const EigMat& m) {
32-
using PlainMat = plain_type_t<EigMat>;
33-
PlainMat m_eval = m;
31+
inline plain_type_t<EigMat> cholesky_decompose(const EigMat& m) {
32+
auto&& m_eval = to_ref(m);
3433
check_symmetric("cholesky_decompose", "m", m_eval);
3534
check_not_nan("cholesky_decompose", "m", m_eval);
36-
Eigen::LLT<PlainMat> llt = m_eval.llt();
35+
Eigen::LLT<plain_type_t<EigMat>> llt = m_eval.llt();
3736
check_pos_definite("cholesky_decompose", "m", llt);
3837
return llt.matrixL();
3938
}

0 commit comments

Comments
 (0)