Stan Math Library  2.15.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 
18  inline matrix_d
20  int K = L.rows();
21  if (K == 0)
22  return L;
23  if (K == 1) {
24  matrix_d result(1, 1);
25  result(0) = square(L(0)); // first elt, so don't need double idx
26  return result;
27  }
28  int J = L.cols();
29  matrix_d LLt(K, K);
30  matrix_d Lt = L.transpose();
31  for (int m = 0; m < K; ++m) {
32  int k = (J < m + 1) ? J : m + 1;
33  LLt(m, m) = Lt.col(m).head(k).squaredNorm();
34  for (int n = (m + 1); n < K; ++n)
35  LLt(n, m) = LLt(m, n) = Lt.col(m).head(k).dot(Lt.col(n).head(k));
36  }
37  return LLt;
38  }
39 
40  }
41 }
42 #endif
fvar< T > square(const fvar< T > &x)
Definition: square.hpp:14
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:22

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