Stan  2.5.0
probability, sampling & optimization
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
multiply_lower_tri_self_transpose.hpp
Go to the documentation of this file.
1 #ifndef STAN__AGRAD__REV__MATRIX__MULTIPLY_LOWER_TRI_SELF_TRANSPOSE_HPP
2 #define STAN__AGRAD__REV__MATRIX__MULTIPLY_LOWER_TRI_SELF_TRANSPOSE_HPP
3 
4 #include <vector>
5 #include <boost/math/tools/promotion.hpp>
9 #include <stan/agrad/rev/var.hpp>
14 
15 namespace stan {
16  namespace agrad {
17 
18  inline matrix_v
20  //stan::math::check_square("multiply_lower_tri_self_transpose(%1%)",
21  //L,"L",(double*)0);
22  int K = L.rows();
23  int J = L.cols();
24  matrix_v LLt(K,K);
25  if (K == 0) return LLt;
26  // if (K == 1) {
27  // LLt(0,0) = L(0,0) * L(0,0);
28  // return LLt;
29  // }
30  int Knz;
31  if (K >= J)
32  Knz = (K-J)*J + (J * (J + 1)) / 2;
33  else // if (K < J)
34  Knz = (K * (K + 1)) / 2;
35  vari** vs = (vari**)memalloc_.alloc( Knz * sizeof(vari*) );
36  int pos = 0;
37  for (int m = 0; m < K; ++m)
38  for (int n = 0; n < ((J < (m+1))?J:(m+1)); ++n) {
39  vs[pos++] = L(m,n).vi_;
40  }
41  for (int m = 0, mpos=0; m < K; ++m, mpos += (J < m)?J:m) {
42  LLt(m,m) = var(new dot_self_vari(vs + mpos, (J < (m+1))?J:(m+1)));
43  for (int n = 0, npos = 0; n < m; ++n, npos += (J < n)?J:n) {
44  LLt(m,n) = LLt(n,m) = var(new dot_product_vari<var,var>(vs + mpos, vs + npos, (J < (n+1))?J:(n+1)));
45  }
46  }
47  return LLt;
48  }
49 
50  }
51 }
52 #endif
memory::stack_alloc memalloc_
Definition: var_stack.cpp:16
Eigen::Matrix< var, Eigen::Dynamic, Eigen::Dynamic > matrix_v
The type of a matrix holding stan::agrad::var values.
Definition: typedefs.hpp:21
The variable implementation base class.
Definition: vari.hpp:28
void * alloc(size_t len)
Return a newly allocated block of memory of the appropriate size managed by the stack allocator...
Independent (input) and dependent (output) variables for gradients.
Definition: var.hpp:27
Eigen::Matrix< fvar< T >, R, R > multiply_lower_tri_self_transpose(const Eigen::Matrix< fvar< T >, R, C > &m)

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