Stan Math Library  2.20.0
reverse mode automatic differentiation
multiply_lower_tri_self_transpose.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_MAT_FUN_MULTIPLY_LOWER_TRI_SELF_TRANSPOSE_HPP
2 #define STAN_MATH_PRIM_MAT_FUN_MULTIPLY_LOWER_TRI_SELF_TRANSPOSE_HPP
3 
6 
7 namespace stan {
8 namespace math {
9 
19  int K = L.rows();
20  if (K == 0)
21  return L;
22  if (K == 1) {
23  matrix_d result(1, 1);
24  result(0) = square(L(0)); // first elt, so don't need double idx
25  return result;
26  }
27  int J = L.cols();
28  matrix_d LLt(K, K);
29  matrix_d Lt = L.transpose();
30  for (int m = 0; m < K; ++m) {
31  int k = (J < m + 1) ? J : m + 1;
32  LLt(m, m) = Lt.col(m).head(k).squaredNorm();
33  for (int n = (m + 1); n < K; ++n)
34  LLt(n, m) = LLt(m, n) = Lt.col(m).head(k).dot(Lt.col(n).head(k));
35  }
36  return LLt;
37 }
38 
39 } // namespace math
40 } // namespace stan
41 #endif
fvar< T > square(const fvar< T > &x)
Definition: square.hpp:12
Eigen::Matrix< fvar< T >, R, R > multiply_lower_tri_self_transpose(const Eigen::Matrix< fvar< T >, R, C > &m)
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic > matrix_d
Type for matrix of double values.
Definition: typedefs.hpp:19

     [ Stan Home Page ] © 2011–2018, Stan Development Team.