| Stan Math Library 2.12.0 reverse mode automatic differentiation

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

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
4 #include <stan/math/prim/mat/fun/typedefs.hpp>
5 #include <stan/math/prim/scal/fun/square.hpp>
6
7 namespace stan {
8 namespace math {
9
18 inline matrix_d
19 multiply_lower_tri_self_transpose(const matrix_d& L) {
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
stan
Definition: log_sum_exp.hpp:8
square.hpp
stan::math::square
fvar< T > square(const fvar< T > &x)
Definition: square.hpp:14
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
stan::math::matrix_d
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic > matrix_d
Type for matrix of double values.
Definition: typedefs.hpp:22
typedefs.hpp

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