CppADCodeGen  HEAD
A C++ Algorithmic Differentiation Package with Source Code Generation
CppAD::cg::CGAtomicFunBridge< Base > Class Template Reference
Inheritance diagram for CppAD::cg::CGAtomicFunBridge< Base >:
Inheritance graph
Collaboration diagram for CppAD::cg::CGAtomicFunBridge< Base >:
Collaboration graph

Public Types

using CGB = CppAD::cg::CG< Base >
 
using ADCGD = CppAD::AD< CGB >
 
using Super = BaseAbstractAtomicFun< Base >
 
using Arg = Argument< Base >
 

Public Member Functions

 CGAtomicFunBridge (const std::string &name, CppAD::ADFun< CGB > &fun, bool standAlone=false, bool cacheSparsities=true)
 
 CGAtomicFunBridge (const CGAtomicFunBridge &orig)=delete
 
CGAtomicFunBridgeoperator= (const CGAtomicFunBridge &rhs)=delete
 
template<class ADVector >
void operator() (const ADVector &ax, ADVector &ay, size_t id=0)
 
template<class VectorSize >
void setCustomSparseJacobianElements (const VectorSize &row, const VectorSize &col)
 
template<class VectorSet >
void setCustomSparseJacobianElements (const VectorSet &elements)
 
template<class VectorSize >
void setCustomSparseHessianElements (const VectorSize &row, const VectorSize &col)
 
template<class VectorSet >
void setCustomSparseHessianElements (const VectorSet &elements)
 
bool for_sparse_jac (size_t q, const CppAD::vector< std::set< size_t > > &r, CppAD::vector< std::set< size_t > > &s, const CppAD::vector< CGB > &x) override
 
bool for_sparse_jac (size_t q, const CppAD::vector< std::set< size_t > > &r, CppAD::vector< std::set< size_t > > &s) override
 
bool rev_sparse_jac (size_t q, const CppAD::vector< std::set< size_t > > &rt, CppAD::vector< std::set< size_t > > &st, const CppAD::vector< CGB > &x) override
 
bool rev_sparse_jac (size_t q, const CppAD::vector< std::set< size_t > > &rt, CppAD::vector< std::set< size_t > > &st) override
 
bool rev_sparse_hes (const CppAD::vector< bool > &vx, const CppAD::vector< bool > &s, CppAD::vector< bool > &t, size_t q, const CppAD::vector< std::set< size_t > > &r, const CppAD::vector< std::set< size_t > > &u, CppAD::vector< std::set< size_t > > &v, const CppAD::vector< CGB > &x) override
 
bool rev_sparse_hes (const CppAD::vector< bool > &vx, const CppAD::vector< bool > &s, CppAD::vector< bool > &t, size_t q, const CppAD::vector< std::set< size_t > > &r, const CppAD::vector< std::set< size_t > > &u, CppAD::vector< std::set< size_t > > &v) override
 
size_t getId () const
 
bool isStandAlone () const
 
bool forward (size_t q, size_t p, const CppAD::vector< bool > &vx, CppAD::vector< bool > &vy, const CppAD::vector< CGB > &tx, CppAD::vector< CGB > &ty) override
 
bool reverse (size_t p, const CppAD::vector< CGB > &tx, const CppAD::vector< CGB > &ty, CppAD::vector< CGB > &px, const CppAD::vector< CGB > &py) override
 
virtual CppAD::vector< std::set< size_t > > jacobianForwardSparsitySet (size_t m, const CppAD::vector< CGB > &x)
 
virtual CppAD::vector< std::set< size_t > > jacobianReverseSparsitySet (size_t m, const CppAD::vector< CGB > &x)
 
virtual CppAD::vector< std::set< size_t > > hessianSparsitySet (size_t m, const CppAD::vector< CGB > &x)
 
virtual CppAD::vector< std::set< size_t > > hessianSparsitySet (const CppAD::vector< bool > &s, const CppAD::vector< CGB > &x)
 

Static Public Member Functions

static size_t createNewAtomicFunctionID ()
 

Protected Member Functions

void zeroOrderDependency (const CppAD::vector< bool > &vx, CppAD::vector< bool > &vy, const CppAD::vector< CGB > &x) override
 
bool atomicForward (size_t q, size_t p, const CppAD::vector< Base > &tx, CppAD::vector< Base > &ty) override
 
bool atomicReverse (size_t p, const CppAD::vector< Base > &tx, const CppAD::vector< Base > &ty, CppAD::vector< Base > &px, const CppAD::vector< Base > &py) override
 

Static Protected Member Functions

static void appendAsArguments (typename std::vector< Arg >::iterator begin, const CppAD::vector< CGB > &tx)
 
static OperationNode< Base > * makeArray (CodeHandler< Base > &handler, const CppAD::vector< CGB > &tx)
 
static OperationNode< Base > * makeArray (CodeHandler< Base > &handler, const CppAD::vector< CGB > &tx, size_t p, size_t k)
 
static OperationNode< Base > * makeZeroArray (CodeHandler< Base > &handler, size_t size)
 
static OperationNode< Base > * makeEmptySparseArray (CodeHandler< Base > &handler, size_t size)
 
static OperationNode< Base > * makeSparseArray (CodeHandler< Base > &handler, const CppAD::vector< CGB > &py, size_t p, size_t k)
 
static bool isParameters (const CppAD::vector< CGB > &tx)
 
static bool isValuesDefined (const CppAD::vector< CGB > &tx)
 

Protected Attributes

ADFun< CGB > & fun_
 
bool cacheSparsities_
 
CustomPosition custom_jac_
 
CustomPosition custom_hess_
 
std::map< size_t, CppAD::vector< std::set< size_t > > > hess_
 
const size_t id_
 
bool standAlone_
 

Detailed Description

template<class Base>
class CppAD::cg::CGAtomicFunBridge< Base >

An atomic function wrapper for atomic functions using the CppAD::cg::CG type. This class can be useful when a CppAD::ADFun<CppAD::cg::CG> is going to be used to create a compiled model library but has not been compiled yet.

Author
Joao Leal

Definition at line 31 of file atomic_fun_bridge.hpp.

Constructor & Destructor Documentation

◆ CGAtomicFunBridge()

template<class Base >
CppAD::cg::CGAtomicFunBridge< Base >::CGAtomicFunBridge ( const std::string &  name,
CppAD::ADFun< CGB > &  fun,
bool  standAlone = false,
bool  cacheSparsities = true 
)
inline

Creates a new atomic function wrapper.

Parameters
nameThe atomic function name
funThe atomic function to be wrapped
standAloneWhether or not forward and reverse function calls do not require the Taylor coefficients for the dependent variables (ty) and the previous evaluation of other forward/reverse modes.
cacheSparsitiesWhether or not to cache information related with sparsity evaluation.

Definition at line 55 of file atomic_fun_bridge.hpp.

Member Function Documentation

◆ atomicForward()

template<class Base >
bool CppAD::cg::CGAtomicFunBridge< Base >::atomicForward ( size_t  q,
size_t  p,
const CppAD::vector< Base > &  tx,
CppAD::vector< Base > &  ty 
)
inlineoverrideprotectedvirtual

Used to evaluate function values and forward mode function values and derivatives.

Parameters
qLowest order for this forward mode calculation.
pHighest order for this forward mode calculation.
vxIf size not zero, which components of x are variables
vyIf size not zero, which components of y are variables
txTaylor coefficients corresponding to x for this calculation
tyTaylor coefficient corresponding to y for this calculation
Returns
true on success, false otherwise

Implements CppAD::cg::CGAbstractAtomicFun< Base >.

Definition at line 282 of file atomic_fun_bridge.hpp.

◆ atomicReverse()

template<class Base >
bool CppAD::cg::CGAtomicFunBridge< Base >::atomicReverse ( size_t  p,
const CppAD::vector< Base > &  tx,
const CppAD::vector< Base > &  ty,
CppAD::vector< Base > &  px,
const CppAD::vector< Base > &  py 
)
inlineoverrideprotectedvirtual

Used to evaluate reverse mode function derivatives.

Parameters
pHighest order for this forward mode calculation.
txTaylor coefficients corresponding to x for this calculation
tyTaylor coefficient corresponding to y for this calculation
pxPartials w.r.t. the x Taylor coefficients.
pyPartials w.r.t. the y Taylor coefficients
Returns
true on success, false otherwise

Implements CppAD::cg::CGAbstractAtomicFun< Base >.

Definition at line 299 of file atomic_fun_bridge.hpp.

◆ createNewAtomicFunctionID()

template<class Base>
static size_t CppAD::cg::CGAbstractAtomicFun< Base >::createNewAtomicFunctionID ( )
inlinestaticinherited

Uses an internal counter to produce IDs for atomic functions.

Definition at line 495 of file abstract_atomic_fun.hpp.

◆ forward()

template<class Base>
bool CppAD::cg::CGAbstractAtomicFun< Base >::forward ( size_t  q,
size_t  p,
const CppAD::vector< bool > &  vx,
CppAD::vector< bool > &  vy,
const CppAD::vector< CGB > &  tx,
CppAD::vector< CGB > &  ty 
)
inlineoverrideinherited

Use the jacobian sparsity to determine which elements will always be zero

Definition at line 94 of file abstract_atomic_fun.hpp.

◆ getId()

template<class Base>
size_t CppAD::cg::CGAbstractAtomicFun< Base >::getId ( ) const
inlineinherited

Provides a unique identifier for this atomic function type.

Returns
a unique identifier ID

Definition at line 81 of file abstract_atomic_fun.hpp.

◆ hessianSparsitySet()

template<class Base>
virtual CppAD::vector<std::set<size_t> > CppAD::cg::CGAbstractAtomicFun< Base >::hessianSparsitySet ( const CppAD::vector< bool > &  s,
const CppAD::vector< CGB > &  x 
)
inlinevirtualinherited

Determine the sparsity pattern p for Hessian of w^T F

Definition at line 462 of file abstract_atomic_fun.hpp.

◆ isStandAlone()

template<class Base>
bool CppAD::cg::CGAbstractAtomicFun< Base >::isStandAlone ( ) const
inlineinherited

Whether or not forward and reverse function calls do not require the Taylor coefficients for the dependent variables (ty) and any previous evaluation of other forward/reverse modes.

Definition at line 90 of file abstract_atomic_fun.hpp.

◆ rev_sparse_hes()

template<class Base >
bool CppAD::cg::CGAtomicFunBridge< Base >::rev_sparse_hes ( const CppAD::vector< bool > &  vx,
const CppAD::vector< bool > &  s,
CppAD::vector< bool > &  t,
size_t  q,
const CppAD::vector< std::set< size_t > > &  r,
const CppAD::vector< std::set< size_t > > &  u,
CppAD::vector< std::set< size_t > > &  v 
)
inlineoverride

V(x) = f'^T(x) U(x) + Sum( s(x)i f''(x) R(x) )

S(x) * f'(x)

Definition at line 172 of file atomic_fun_bridge.hpp.

◆ reverse()

template<class Base>
bool CppAD::cg::CGAbstractAtomicFun< Base >::reverse ( size_t  p,
const CppAD::vector< CGB > &  tx,
const CppAD::vector< CGB > &  ty,
CppAD::vector< CGB > &  px,
const CppAD::vector< CGB > &  py 
)
inlineoverrideinherited

Use the Jacobian sparsity to determine which elements will always be zero

Use the Hessian sparsity to determine which elements will always be zero

Definition at line 233 of file abstract_atomic_fun.hpp.

Member Data Documentation

◆ id_

template<class Base>
const size_t CppAD::cg::CGAbstractAtomicFun< Base >::id_
protectedinherited

A unique identifier for this atomic function type

Definition at line 37 of file abstract_atomic_fun.hpp.

Referenced by CppAD::cg::CGAbstractAtomicFun< ScalarOut >::getId().

◆ standAlone_

template<class Base>
bool CppAD::cg::CGAbstractAtomicFun< Base >::standAlone_
protectedinherited

Whether or not forward and reverse function calls do not require the Taylor coefficients for the dependent variables (ty) and any previous evaluation of other forward/reverse modes.

Definition at line 43 of file abstract_atomic_fun.hpp.

Referenced by CppAD::cg::CGAbstractAtomicFun< ScalarOut >::isStandAlone().


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