| Stan Math Library 2.12.0 reverse mode automatic differentiation

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

LDLT_factor.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_MAT_FUN_LDLT_FACTOR_HPP
2 #define STAN_MATH_PRIM_MAT_FUN_LDLT_FACTOR_HPP
3
4 #include <stan/math/prim/mat/fun/Eigen.hpp>
5 #include <boost/shared_ptr.hpp>
6 #include <stan/math/prim/mat/err/check_square.hpp>
7 #include <stan/math/prim/scal/fun/is_nan.hpp>
8
9 namespace stan {
10 namespace math {
11
12 template<typename T, int R, int C>
13 class LDLT_factor;
14
55 template<int R, int C, typename T>
56 class LDLT_factor<T, R, C> {
57 public:
58 LDLT_factor()
59 : N_(0), ldltP_(new Eigen::LDLT< Eigen::Matrix<T, R, C> >()) {}
60
61 explicit LDLT_factor(const Eigen::Matrix<T, R, C> &A)
62 : N_(0), ldltP_(new Eigen::LDLT< Eigen::Matrix<T, R, C> >()) {
63 compute(A);
64 }
65
66 inline void compute(const Eigen::Matrix<T, R, C> &A) {
67 check_square("LDLT_factor", "A", A);
68 N_ = A.rows();
69 ldltP_->compute(A);
70 }
71
72 inline bool success() const {
73 if (ldltP_->info() != Eigen::Success)
74 return false;
75 if (!(ldltP_->isPositive()))
76 return false;
77 Eigen::Matrix<T, Eigen::Dynamic, 1> ldltP_diag(ldltP_->vectorD());
78 for (int i = 0; i < ldltP_diag.size(); ++i)
79 if (ldltP_diag(i) <= 0 || is_nan(ldltP_diag(i)))
80 return false;
81 return true;
82 }
83
84 inline T log_abs_det() const {
85 return ldltP_->vectorD().array().log().sum();
86 }
87
88 inline void inverse(Eigen::Matrix<T, R, C> &invA) const {
89 invA.setIdentity(N_);
90 ldltP_->solveInPlace(invA);
91 }
92
93 template<typename Rhs>
94 inline const
95 Eigen::internal::solve_retval<Eigen::LDLT< Eigen::Matrix<T, R, C> >, Rhs>
96 solve(const Eigen::MatrixBase<Rhs>& b) const {
97 return ldltP_->solve(b);
98 }
99
100 inline Eigen::Matrix<T, R, C>
101 solveRight(const Eigen::Matrix<T, R, C> &B) const {
102 return ldltP_->solve(B.transpose()).transpose();
103 }
104
105 inline Eigen::Matrix<T, Eigen::Dynamic, 1> vectorD() const {
106 return ldltP_->vectorD();
107 }
108
109 inline Eigen::LDLT<Eigen::Matrix<T, R, C> > matrixLDLT() const {
110 return ldltP_->matrixLDLT();
111 }
112
113 inline size_t rows() const { return N_; }
114 inline size_t cols() const { return N_; }
115
116 typedef size_t size_type;
117 typedef double value_type;
118
119 size_t N_;
120 boost::shared_ptr< Eigen::LDLT< Eigen::Matrix<T, R, C> > > ldltP_;
121 };
122
123 }
124 }
125 #endif
ldltP_
boost::shared_ptr< Eigen::LDLT< Eigen::Matrix< double, R1, C1 > > > ldltP_
This share_ptr is used to prevent copying the LDLT factorizations for mdivide_left_ldlt(ldltA, b) when ldltA is a LDLT_factor.
Definition: mdivide_left_ldlt.hpp:23
stan::math::LDLT_factor< T, R, C >::inverse
void inverse(Eigen::Matrix< T, R, C > &invA) const
Definition: LDLT_factor.hpp:88
stan::math::LDLT_factor< T, R, C >::solve
const Eigen::internal::solve_retval< Eigen::LDLT< Eigen::Matrix< T, R, C > >, Rhs > solve(const Eigen::MatrixBase< Rhs > &b) const
Definition: LDLT_factor.hpp:96
stan::math::LDLT_factor< T, R, C >::value_type
double value_type
Definition: LDLT_factor.hpp:117
is_nan.hpp
stan
Definition: log_sum_exp.hpp:8
stan::math::LDLT_factor< T, R, C >::LDLT_factor
LDLT_factor()
Definition: LDLT_factor.hpp:58
stan::math::LDLT_factor< T, R, C >::LDLT_factor
LDLT_factor(const Eigen::Matrix< T, R, C > &A)
Definition: LDLT_factor.hpp:61
stan::math::LDLT_factor< T, R, C >::solveRight
Eigen::Matrix< T, R, C > solveRight(const Eigen::Matrix< T, R, C > &B) const
Definition: LDLT_factor.hpp:101
Eigen
(Expert) Numerical traits for algorithmic differentiation variables.
Definition: Eigen_NumTraits.hpp:9
stan::math::LDLT_factor
Definition: LDLT_factor.hpp:13
stan::math::LDLT_factor< T, R, C >::success
bool success() const
Definition: LDLT_factor.hpp:72
stan::math::LDLT_factor< T, R, C >::matrixLDLT
Eigen::LDLT< Eigen::Matrix< T, R, C > > matrixLDLT() const
Definition: LDLT_factor.hpp:109
stan::math::LDLT_factor< T, R, C >::vectorD
Eigen::Matrix< T, Eigen::Dynamic, 1 > vectorD() const
Definition: LDLT_factor.hpp:105
stan::math::LDLT_factor< T, R, C >::log_abs_det
T log_abs_det() const
Definition: LDLT_factor.hpp:84
stan::math::LDLT_factor< T, R, C >::N_
size_t N_
Definition: LDLT_factor.hpp:119
Eigen.hpp
stan::math::LDLT_factor< T, R, C >::size_type
size_t size_type
Definition: LDLT_factor.hpp:116
stan::math::LDLT_factor< T, R, C >::ldltP_
boost::shared_ptr< Eigen::LDLT< Eigen::Matrix< T, R, C > > > ldltP_
Definition: LDLT_factor.hpp:120
stan::math::LDLT_factor< T, R, C >::rows
size_t rows() const
Definition: LDLT_factor.hpp:113
stan::math::LDLT_factor< T, R, C >::compute
void compute(const Eigen::Matrix< T, R, C > &A)
Definition: LDLT_factor.hpp:66
stan::math::is_nan
int is_nan(const fvar< T > &x)
Returns 1 if the input's value is NaN and 0 otherwise.
Definition: is_nan.hpp:21
stan::math::transpose
Eigen::Matrix< T, C, R > transpose(const Eigen::Matrix< T, R, C > &m)
Definition: transpose.hpp:12
stan::math::check_square
bool check_square(const char *function, const char *name, const Eigen::Matrix< T_y, Eigen::Dynamic, Eigen::Dynamic > &y)
Return true if the specified matrix is square.
Definition: check_square.hpp:28
stan::math::LDLT_factor< T, R, C >::cols
size_t cols() const
Definition: LDLT_factor.hpp:114
N_
int N_
Definition: mdivide_left.hpp:20
check_square.hpp

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