Automatic Differentiation
 
Loading...
Searching...
No Matches
multiply_lower_tri_self_transpose.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_PRIM_FUN_MULTIPLY_LOWER_TRI_SELF_TRANSPOSE_HPP
2#define STAN_MATH_PRIM_FUN_MULTIPLY_LOWER_TRI_SELF_TRANSPOSE_HPP
3
6
7namespace stan {
8namespace math {
9
18template <typename EigMat, require_eigen_matrix_dynamic_t<EigMat>* = nullptr,
19 require_not_st_autodiff<EigMat>* = nullptr>
21 int K = L.rows();
22 if (K == 0) {
23 return L;
24 }
25 if (K == 1) {
26 matrix_d result(1, 1);
27 result.coeffRef(0) = square(L.coeff(0, 0));
28 return result;
29 }
30 int J = L.cols();
31 matrix_d LLt(K, K);
32 matrix_d Lt = L.transpose();
33 for (int m = 0; m < K; ++m) {
34 int k = (J < m + 1) ? J : m + 1;
35 LLt(m, m) = Lt.col(m).head(k).squaredNorm();
36 for (int n = (m + 1); n < K; ++n) {
37 LLt(n, m) = LLt(m, n) = Lt.col(m).head(k).dot(Lt.col(n).head(k));
38 }
39 }
40 return LLt;
41}
42
43} // namespace math
44} // namespace stan
45
46#endif
Eigen::Matrix< value_type_t< EigMat >, EigMat::RowsAtCompileTime, EigMat::RowsAtCompileTime > multiply_lower_tri_self_transpose(const EigMat &m)
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic > matrix_d
Type for matrix of double values.
Definition typedefs.hpp:19
fvar< T > square(const fvar< T > &x)
Definition square.hpp:12
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...