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_REV_MAT_FUN_MULTIPLY_LOWER_TRI_SELF_TRANSPOSE_HPP
2 #define STAN_MATH_REV_MAT_FUN_MULTIPLY_LOWER_TRI_SELF_TRANSPOSE_HPP
3 
4 #include <stan/math/rev/meta.hpp>
6 #include <stan/math/rev/core.hpp>
10 
11 namespace stan {
12 namespace math {
13 
15  // check_square("multiply_lower_tri_self_transpose",
16  // L, "L", (double*)0);
17  int K = L.rows();
18  int J = L.cols();
19  matrix_v LLt(K, K);
20  if (K == 0)
21  return LLt;
22  // if (K == 1) {
23  // LLt(0, 0) = L(0, 0) * L(0, 0);
24  // return LLt;
25  // }
26  int Knz;
27  if (K >= J)
28  Knz = (K - J) * J + (J * (J + 1)) / 2;
29  else // if (K < J)
30  Knz = (K * (K + 1)) / 2;
31  vari** vs = reinterpret_cast<vari**>(
33  int pos = 0;
34  for (int m = 0; m < K; ++m)
35  for (int n = 0; n < ((J < (m + 1)) ? J : (m + 1)); ++n) {
36  vs[pos++] = L(m, n).vi_;
37  }
38  for (int m = 0, mpos = 0; m < K; ++m, mpos += (J < m) ? J : m) {
39  LLt(m, m) = var(
40  new internal::dot_self_vari(vs + mpos, (J < (m + 1)) ? J : (m + 1)));
41  for (int n = 0, npos = 0; n < m; ++n, npos += (J < n) ? J : n) {
42  LLt(m, n) = LLt(n, m) = var(new internal::dot_product_vari<var, var>(
43  vs + mpos, vs + npos, (J < (n + 1)) ? J : (n + 1)));
44  }
45  }
46  return LLt;
47 }
48 
49 } // namespace math
50 } // namespace stan
51 #endif
The variable implementation base class.
Definition: vari.hpp:30
static STAN_THREADS_DEF AutodiffStackStorage * instance_
Independent (input) and dependent (output) variables for gradients.
Definition: var.hpp:33
Eigen::Matrix< var, Eigen::Dynamic, Eigen::Dynamic > matrix_v
The type of a matrix holding var values.
Definition: typedefs.hpp:17
Eigen::Matrix< fvar< T >, R, R > multiply_lower_tri_self_transpose(const Eigen::Matrix< fvar< T >, R, C > &m)
void * alloc(size_t len)
Return a newly allocated block of memory of the appropriate size managed by the stack allocator...

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