Stan  1.3
probability, sampling & optimization
 All Classes Namespaces Files Functions Variables Typedefs 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>
11 #include <stan/agrad/rev/var.hpp>
16 
17 namespace stan {
18  namespace agrad {
19 
20  inline matrix_v
22  // stan::math::validate_square(L,"multiply_lower_tri_self_transpose");
23  int K = L.rows();
24  int J = L.cols();
25  matrix_v LLt(K,K);
26  if (K == 0) return LLt;
27  // if (K == 1) {
28  // LLt(0,0) = L(0,0) * L(0,0);
29  // return LLt;
30  // }
31  int Knz;
32  if (K >= J)
33  Knz = (K-J)*J + (J * (J + 1)) / 2;
34  else // if (K < J)
35  Knz = (K * (K + 1)) / 2;
36  vari** vs = (vari**)memalloc_.alloc( Knz * sizeof(vari*) );
37  int pos = 0;
38  for (int m = 0; m < K; ++m)
39  for (int n = 0; n < ((J < (m+1))?J:(m+1)); ++n) {
40  vs[pos++] = L(m,n).vi_;
41  }
42  for (int m = 0, mpos=0; m < K; ++m, mpos += (J < m)?J:m) {
43  LLt(m,m) = var(new dot_self_vari(vs + mpos, (J < (m+1))?J:(m+1)));
44  for (int n = 0, npos = 0; n < m; ++n, npos += (J < n)?J:n) {
45  LLt(m,n) = LLt(n,m) = var(new dot_product_vv_vari(vs + mpos, vs + npos, (J < (n+1))?J:(n+1)));
46  }
47  }
48  return LLt;
49  }
50 
51  }
52 }
53 #endif

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