Stan Math Library  2.14.0
reverse mode automatic differentiation
Public Types | Public Member Functions | Public Attributes | List of all members
stan::math::LDLT_factor< var, R, C > Class Template Reference

A template specialization of src/stan/math/matrix/LDLT_factor.hpp for var which can be used with all the *_ldlt functions. More...

#include <LDLT_factor.hpp>

Public Types

typedef size_t size_type
 
typedef var value_type
 

Public Member Functions

 LDLT_factor ()
 Default constructor. More...
 
 LDLT_factor (const Eigen::Matrix< var, R, C > &A)
 
void compute (const Eigen::Matrix< var, R, C > &A)
 Use the LDLT_factor object to factorize a new matrix. More...
 
template<typename Rhs >
const Eigen::internal::solve_retval< Eigen::LDLT< Eigen::Matrix< double, R, C > >, Rhs > solve (const Eigen::MatrixBase< Rhs > &b) const
 Compute the actual numerical result of inv(A)*b. More...
 
bool success () const
 Determine whether the most recent factorization succeeded. More...
 
Eigen::VectorXd vectorD () const
 The entries of the diagonal matrix D. More...
 
size_t rows () const
 
size_t cols () const
 

Public Attributes

LDLT_alloc< R, C > * alloc_
 The LDLT_alloc object actually contains the factorization but is derived from the chainable_alloc class so that it is allocated on the vari stack. More...
 

Detailed Description

template<int R, int C>
class stan::math::LDLT_factor< var, R, C >

A template specialization of src/stan/math/matrix/LDLT_factor.hpp for var which can be used with all the *_ldlt functions.

The usage pattern is:

Eigen::Matrix<T, R, C> A1, A2;
LDLT_factor<T, R, C> ldlt_A1(A1);
LDLT_factor<T, R, C> ldlt_A2;
ldlt_A2.compute(A2);

Now, the caller should check that ldlt_A1.success() and ldlt_A2.success() are true or abort accordingly. Alternatively, call check_ldlt_factor(). The behaviour of using an LDLT_factor without success() returning true is undefined.

Note that ldlt_A1 and ldlt_A2 are completely equivalent. They simply demonstrate two different ways to construct the factorization.

Now, the caller can use the LDLT_factor objects as needed. For instance

x1 = mdivide_left_ldlt(ldlt_A1, b1);
x2 = mdivide_right_ldlt(b2, ldlt_A2);
d1 = log_determinant_ldlt(ldlt_A1);
d2 = log_determinant_ldlt(ldlt_A2);

Definition at line 46 of file LDLT_factor.hpp.

Member Typedef Documentation

§ size_type

template<int R, int C>
typedef size_t stan::math::LDLT_factor< var, R, C >::size_type

Definition at line 129 of file LDLT_factor.hpp.

§ value_type

template<int R, int C>
typedef var stan::math::LDLT_factor< var, R, C >::value_type

Definition at line 130 of file LDLT_factor.hpp.

Constructor & Destructor Documentation

§ LDLT_factor() [1/2]

template<int R, int C>
stan::math::LDLT_factor< var, R, C >::LDLT_factor ( )
inline

Default constructor.

The caller MUST call compute() after this. Any calls which use the LDLT_factor without calling compute() run the risk of crashing Stan from within Eigen.

Definition at line 53 of file LDLT_factor.hpp.

§ LDLT_factor() [2/2]

template<int R, int C>
stan::math::LDLT_factor< var, R, C >::LDLT_factor ( const Eigen::Matrix< var, R, C > &  A)
inlineexplicit

Definition at line 55 of file LDLT_factor.hpp.

Member Function Documentation

§ cols()

template<int R, int C>
size_t stan::math::LDLT_factor< var, R, C >::cols ( ) const
inline

Definition at line 127 of file LDLT_factor.hpp.

§ compute()

template<int R, int C>
void stan::math::LDLT_factor< var, R, C >::compute ( const Eigen::Matrix< var, R, C > &  A)
inline

Use the LDLT_factor object to factorize a new matrix.

After calling this function, the user should call success() to check that the factorization was successful. If the factorization is not successful, the LDLT_factor is not valid and other functions should not be used.

Parameters
AA symmetric positive definite matrix to factorize

Definition at line 68 of file LDLT_factor.hpp.

§ rows()

template<int R, int C>
size_t stan::math::LDLT_factor< var, R, C >::rows ( ) const
inline

Definition at line 126 of file LDLT_factor.hpp.

§ solve()

template<int R, int C>
template<typename Rhs >
const Eigen::internal::solve_retval<Eigen::LDLT<Eigen::Matrix<double, R, C> >, Rhs> stan::math::LDLT_factor< var, R, C >::solve ( const Eigen::MatrixBase< Rhs > &  b) const
inline

Compute the actual numerical result of inv(A)*b.

Note that this isn't meant to handle any of the autodiff. This is a convenience function for the actual implementations in mdivide_left_ldlt.

Precondition: success() must return true. If success() returns false, this function runs the risk of crashing Stan from within Eigen.

Parameters
bThe right handside. Note that this is templated such that Eigen's expression-templating magic can work properly here.

Definition at line 96 of file LDLT_factor.hpp.

§ success()

template<int R, int C>
bool stan::math::LDLT_factor< var, R, C >::success ( ) const
inline

Determine whether the most recent factorization succeeded.

This should always be called after the object is constructed (with a matrix) or after compute() is called.

Definition at line 106 of file LDLT_factor.hpp.

§ vectorD()

template<int R, int C>
Eigen::VectorXd stan::math::LDLT_factor< var, R, C >::vectorD ( ) const
inline

The entries of the diagonal matrix D.

They should be strictly positive for a positive definite matrix.

Precondition: success() must return true. If success() returns false, this function runs the risk of crashing Stan from within Eigen.

Definition at line 122 of file LDLT_factor.hpp.

Member Data Documentation

§ alloc_

template<int R, int C>
LDLT_alloc<R, C>* stan::math::LDLT_factor< var, R, C >::alloc_

The LDLT_alloc object actually contains the factorization but is derived from the chainable_alloc class so that it is allocated on the vari stack.

This ensures that it's lifespan is longer than the LDLT_factor object which created it. This is needed because the factorization is required during the chain() calls which happen after an LDLT_factor object will most likely have been destroyed.

Definition at line 140 of file LDLT_factor.hpp.


The documentation for this class was generated from the following file:

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