@(@\newcommand{\W}[1]{ \; #1 \; }
\newcommand{\R}[1]{ {\rm #1} }
\newcommand{\B}[1]{ {\bf #1} }
\newcommand{\D}[2]{ \frac{\partial #1}{\partial #2} }
\newcommand{\DD}[3]{ \frac{\partial^2 #1}{\partial #2 \partial #3} }
\newcommand{\Dpow}[2]{ \frac{\partial^{#1}}{\partial {#2}^{#1}} }
\newcommand{\dpow}[2]{ \frac{ {\rm d}^{#1}}{{\rm d}\, {#2}^{#1}} }@)@
This is cppad-20221105 documentation. Here is a link to its
current documentation
.
atomic_two Eigen Cholesky Factorization Class
Purpose
Construct an atomic operation that computes a lower triangular matrix
@(@
L
@)@ such that @(@
L L^\R{T} = A
@)@
for any positive integer @(@
p
@)@
and symmetric positive definite matrix @(@
A \in \B{R}^{p \times p}
@)@.
namespace { // BEGIN_EMPTY_NAMESPACEtemplate <class Base>
class atomic_eigen_cholesky : public CppAD::atomic_base<Base> {
public:
// -----------------------------------------------------------// type of elements during calculation of derivativestypedef Base scalar;
// type of elements during tapingtypedef CppAD::AD<scalar> ad_scalar;
//// type of matrix during calculation of derivativestypedef Eigen::Matrix<
scalar, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor> matrix;
// type of matrix during tapingtypedef Eigen::Matrix<
ad_scalar, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor > ad_matrix;
//// lower triangular scalar matrixtypedef Eigen::TriangularView<matrix, Eigen::Lower> lower_view;
// use atomic operation to invert an AD matrix
ad_matrix op(const ad_matrix& arg)
{ size_t nr = size_t( arg.rows() );
size_t ny = ( (nr + 1 ) * nr ) / 2;
size_t nx = 1 + ny;
assert( nr == size_t( arg.cols() ) );
// -------------------------------------------------------------------// packed version of argCPPAD_TESTVECTOR(ad_scalar) packed_arg(nx);
size_t index = 0;
packed_arg[index++] = ad_scalar( nr );
// lower triangle of symmetric matrix Afor(size_t i = 0; i < nr; i++)
{ for(size_t j = 0; j <= i; j++)
packed_arg[index++] = arg( long(i), long(j) );
}
assert( index == nx );
// -------------------------------------------------------------------// packed version of result = arg^{-1}.// This is an atomic_base function call that CppAD uses to// store the atomic operation on the tape.CPPAD_TESTVECTOR(ad_scalar) packed_result(ny);
(*this)(packed_arg, packed_result);
// -------------------------------------------------------------------// unpack result matrix L
ad_matrix result = ad_matrix::Zero( long(nr), long(nr) );
index = 0;
for(size_t i = 0; i < nr; i++)
{ for(size_t j = 0; j <= i; j++)
result( long(i), long(j) ) = packed_result[index++];
}
return result;
}
private:
// -------------------------------------------------------------// one forward mode vector of matrices for argument and result
CppAD::vector<matrix> f_arg_, f_result_;
// one reverse mode vector of matrices for argument and result
CppAD::vector<matrix> r_arg_, r_result_;
// -------------------------------------------------------------