| Stan Math Library 2.6.3 probability, sampling & optimization

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros
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/prim/mat/fun/Eigen.hpp>
5 #include <stan/math/prim/mat/fun/typedefs.hpp>
6 #include <stan/math/prim/mat/err/check_square.hpp>
7 #include <stan/math/rev/core.hpp>
8 #include <stan/math/rev/mat/fun/typedefs.hpp>
9 #include <stan/math/rev/mat/fun/dot_product.hpp>
10 #include <stan/math/rev/mat/fun/dot_self.hpp>
11 #include <stan/math/rev/mat/fun/columns_dot_self.hpp>
12 #include <boost/math/tools/promotion.hpp>
13 #include <vector>
14
15 namespace stan {
16 namespace math {
17
18 inline matrix_v
19 multiply_lower_tri_self_transpose(const matrix_v& L) {
20 // stan::math::check_square("multiply_lower_tri_self_transpose",
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
36 = reinterpret_cast<vari**>(ChainableStack::memalloc_
37 .alloc(Knz * sizeof(vari*)));
38 int pos = 0;
39 for (int m = 0; m < K; ++m)
40 for (int n = 0; n < ((J < (m+1)) ? J : (m+1)); ++n) {
41 vs[pos++] = L(m, n).vi_;
42 }
43 for (int m = 0, mpos=0; m < K; ++m, mpos += (J < m) ? J : m) {
44 LLt(m, m) = var(new dot_self_vari(vs + mpos, (J < (m+1)) ? J : (m+1)));
45 for (int n = 0, npos = 0; n < m; ++n, npos += (J < n) ? J : n) {
46 LLt(m, n)
47 = LLt(n, m)
48 = var(new dot_product_vari<var, var>(vs + mpos, vs + npos,
49 (J < (n+1))?J:(n+1)));
50 }
51 }
52 return LLt;
53 }
54
55 }
56 }
57 #endif
core.hpp
stan::math::AutodiffStackStorage::memalloc_
static stack_alloc memalloc_
Definition: autodiffstackstorage.hpp:16
stan::math::vari
The variable implementation base class.
Definition: vari.hpp:28
stan::math::var
Independent (input) and dependent (output) variables for gradients.
Definition: var.hpp:32
columns_dot_self.hpp
stan::math::matrix_v
Eigen::Matrix< var, Eigen::Dynamic, Eigen::Dynamic > matrix_v
The type of a matrix holding stan::math::var values.
Definition: typedefs.hpp:21
stan::math::multiply_lower_tri_self_transpose
Eigen::Matrix< fvar< T >, R, R > multiply_lower_tri_self_transpose(const Eigen::Matrix< fvar< T >, R, C > &m)
Definition: multiply_lower_tri_self_transpose.hpp:17
dot_self.hpp
typedefs.hpp
dot_product.hpp
Eigen.hpp
stan::math::stack_alloc::alloc
void * alloc(size_t len)
Return a newly allocated block of memory of the appropriate size managed by the stack allocator...
Definition: stack_alloc.hpp:170
typedefs.hpp
check_square.hpp

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