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

Classes

class  Color
 
class  LocalSparsityInfo
 
class  Position
 

Public Member Functions

 ModelCSourceGen (ADFun< CppAD::cg::CG< Base > > &fun, std::string model)
 
 ModelCSourceGen (const ModelCSourceGen &)=delete
 
ModelCSourceGenoperator= (const ModelCSourceGen &)=delete
 
const std::string & getName () const
 
template<class VectorBase >
void setTypicalIndependentValues (const VectorBase &x)
 
void setRelatedDependents (const std::vector< std::set< size_t > > &relatedDepCandidates)
 
const std::vector< std::set< size_t > > & getRelatedDependents () const
 
virtual size_t getParameterPrecision () const
 
virtual void setParameterPrecision (size_t p)
 
bool isMultiThreading () const
 
void setMultiThreading (bool multiThreading)
 
bool isJacobianMultiThreadingEnabled () const
 
bool isHessianMultiThreadingEnabled () const
 
bool isCreateHessian () const
 
void setCreateHessian (bool create)
 
JacobianADMode getJacobianADMode () const
 
void setJacobianADMode (JacobianADMode mode)
 
bool isCreateJacobian () const
 
void setCreateJacobian (bool create)
 
bool isCreateSparseHessian () const
 
void setCreateSparseHessian (bool create)
 
bool isSparseHessianReusesRev2 () const
 
void setSparseHessianReusesRev2 (bool reuse)
 
bool isCreateHessianSparsityByEquation () const
 
void setCreateHessianSparsityByEquation (bool create)
 
bool isCreateSparseJacobian () const
 
void setCreateSparseJacobian (bool create)
 
bool isSparseJacobianReuse1stOrderPasses () const
 
void setSparseJacobianReuse1stOrderPasses (bool reuse)
 
bool isCreateForwardZero () const
 
void setCreateForwardZero (bool create)
 
bool isCreateSparseForwardOne () const
 
void setCreateForwardOne (bool create)
 
bool isCreateReverseOne () const
 
void setCreateReverseOne (bool create)
 
bool isCreateReverseTwo () const
 
void setCreateReverseTwo (bool create)
 
void setCustomSparseJacobianElements (const std::vector< size_t > &row, const std::vector< size_t > &col)
 
template<class VectorSet >
void setCustomSparseJacobianElements (const VectorSet &elements)
 
void setCustomSparseHessianElements (const std::vector< size_t > &row, const std::vector< size_t > &col)
 
template<class VectorSet >
void setCustomSparseHessianElements (const VectorSet &elements)
 
size_t getMaxAssignmentsPerFunc () const
 
void setMaxAssignmentsPerFunc (size_t maxAssignPerFunc)
 
size_t getMaxOperationsPerAssignment () const
 
void setMaxOperationsPerAssignment (size_t maxOperationsPerAssignment)
 
template<>
std::string baseTypeName ()
 
template<>
std::string baseTypeName ()
 

Static Public Member Functions

static std::string baseTypeName ()
 
template<class T >
static void generateFunctionDeclarationSource (std::ostringstream &cache, const std::string &model_function, const std::string &suffix, const std::map< size_t, T > &elements, const std::string &argsDcl)
 

Static Public Attributes

static const std::string FUNCTION_FORWAD_ZERO = "forward_zero"
 
static const std::string FUNCTION_JACOBIAN = "jacobian"
 
static const std::string FUNCTION_HESSIAN = "hessian"
 
static const std::string FUNCTION_FORWARD_ONE = "forward_one"
 
static const std::string FUNCTION_REVERSE_ONE = "reverse_one"
 
static const std::string FUNCTION_REVERSE_TWO = "reverse_two"
 
static const std::string FUNCTION_SPARSE_JACOBIAN = "sparse_jacobian"
 
static const std::string FUNCTION_SPARSE_HESSIAN = "sparse_hessian"
 
static const std::string FUNCTION_JACOBIAN_SPARSITY = "jacobian_sparsity"
 
static const std::string FUNCTION_HESSIAN_SPARSITY = "hessian_sparsity"
 
static const std::string FUNCTION_HESSIAN_SPARSITY2 = "hessian_sparsity2"
 
static const std::string FUNCTION_SPARSE_FORWARD_ONE = "sparse_forward_one"
 
static const std::string FUNCTION_SPARSE_REVERSE_ONE = "sparse_reverse_one"
 
static const std::string FUNCTION_SPARSE_REVERSE_TWO = "sparse_reverse_two"
 
static const std::string FUNCTION_FORWARD_ONE_SPARSITY = "forward_one_sparsity"
 
static const std::string FUNCTION_REVERSE_ONE_SPARSITY = "reverse_one_sparsity"
 
static const std::string FUNCTION_REVERSE_TWO_SPARSITY = "sparse_reverse_two_sparsity"
 
static const std::string FUNCTION_INFO = "info"
 
static const std::string FUNCTION_ATOMIC_FUNC_NAMES = "atomic_functions"
 

Protected Member Functions

virtual VariableNameGenerator< Base > * createVariableNameGenerator (const std::string &depName="y", const std::string &indepName="x", const std::string &tmpName="v", const std::string &tmpArrayName="array")
 
const std::map< std::string, std::string > & getSources (MultiThreadingType multiThreadingType, JobTimer *timer)
 
virtual void generateSources (MultiThreadingType multiThreadingType, JobTimer *timer=nullptr)
 
virtual void generateLoops ()
 
virtual void generateInfoSource ()
 
virtual void generateAtomicFuncNames ()
 
virtual bool isAtomicsUsed ()
 
virtual const std::map< size_t, AtomicUseInfo< Base > > & getAtomicsInfo ()
 
virtual void generateZeroSource ()
 
virtual std::vector< CGBaseprepareForward0WithLoops (CodeHandler< Base > &handler, const std::vector< CGBase > &x)
 
virtual void generateJacobianSource ()
 
virtual void generateSparseJacobianSource (MultiThreadingType multiThreadingType)
 
virtual void generateSparseJacobianSource (bool forward)
 
virtual void generateSparseJacobianForRevSource (bool forward, MultiThreadingType multiThreadingType)
 
virtual std::string generateSparseJacobianForRevSingleThreadSource (const std::string &functionName, std::map< size_t, CompressedVectorInfo > jacInfo, size_t maxCompressedSize, const std::string &functionRevFor, const std::string &revForSuffix, bool forward)
 
virtual std::string generateSparseJacobianForRevMultiThreadSource (const std::string &functionName, std::map< size_t, CompressedVectorInfo > jacInfo, size_t maxCompressedSize, const std::string &functionRevFor, const std::string &revForSuffix, bool forward, MultiThreadingType multiThreadingType)
 
virtual std::vector< CGBaseprepareSparseJacobianWithLoops (CodeHandler< Base > &handler, const std::vector< CGBase > &x, bool forward)
 
void prepareSparseJacobianRowWithLoops (CodeHandler< Base > &handler, LoopModel< Base > &lModel, size_t tapeI, const loops::JacobianWithLoopsRowInfo &rowInfo, const std::vector< std::map< size_t, CGBase > > &dyiDxtape, const std::vector< std::map< size_t, CGBase > > &dzDx, const CGBase &py, IndexOperationNode< Base > &iterationIndexOp, std::vector< loops::IfElseInfo< Base > > &ifElses, size_t &jacLE, std::vector< std::pair< CG< Base >, IndexPattern *> > &indexedLoopResults, std::set< size_t > &allLocations)
 
void analyseSparseJacobianWithLoops (const std::vector< size_t > &rows, const std::vector< size_t > &cols, const std::vector< size_t > &location, SparsitySetType &noLoopEvalSparsity, std::vector< std::map< size_t, std::set< size_t > > > &noLoopEvalLocations, std::map< LoopModel< Base > *, SparsitySetType > &loopsEvalSparsities, std::map< LoopModel< Base > *, std::vector< loops::JacobianWithLoopsRowInfo > > &loopEqInfo)
 
virtual void generateSparseJacobianWithLoopsSourceFromForRev (const std::map< size_t, CompressedVectorInfo > &jacInfo, size_t maxCompressedSize, const std::string &localFunctionTypeName, const std::string &suffix, const std::string &keyName, const std::map< size_t, std::set< size_t > > &nonLoopElements, const std::map< LoopModel< Base > *, std::map< size_t, std::map< size_t, std::set< size_t > > > > &loopGroups, void(*generateLocalFunctionName)(std::ostringstream &cache, const std::string &modelName, const LoopModel< Base > &loop, size_t g))
 
virtual void generateFunctionNameLoopFor1 (std::ostringstream &cache, const LoopModel< Base > &loop, size_t g)
 
virtual void generateFunctionNameLoopRev1 (std::ostringstream &cache, const LoopModel< Base > &loop, size_t i)
 
virtual void generateHessianSource ()
 
virtual void generateSparseHessianSource (MultiThreadingType multiThreadingType)
 
virtual void generateSparseHessianSourceDirectly ()
 
virtual void generateSparseHessianSourceFromRev2 (MultiThreadingType multiThreadingType)
 
virtual std::string generateSparseHessianRev2SingleThreadSource (const std::string &functionName, std::map< size_t, CompressedVectorInfo > hessInfo, size_t maxCompressedSize, const std::string &functionRev2, const std::string &rev2Suffix)
 
virtual std::string generateSparseHessianRev2MultiThreadSource (const std::string &functionName, std::map< size_t, CompressedVectorInfo > hessInfo, size_t maxCompressedSize, const std::string &functionRev2, const std::string &rev2Suffix, MultiThreadingType multiThreadingType)
 
virtual void determineSecondOrderElements4Eval (std::vector< size_t > &userRows, std::vector< size_t > &userCols)
 
virtual std::vector< CGBaseprepareSparseHessianWithLoops (CodeHandler< Base > &handler, std::vector< CGBase > &indVars, std::vector< CGBase > &w, const std::vector< size_t > &lowerHessRows, const std::vector< size_t > &lowerHessCols, const std::vector< size_t > &lowerHessOrder, const std::map< size_t, size_t > &duplicates)
 
void analyseSparseHessianWithLoops (const std::vector< size_t > &lowerHessRows, const std::vector< size_t > &lowerHessCols, const std::vector< size_t > &lowerHessOrder, SparsitySetType &noLoopEvalJacSparsity, SparsitySetType &noLoopEvalHessSparsity, std::vector< std::map< size_t, std::set< size_t > > > &noLoopEvalHessLocations, std::map< LoopModel< Base > *, loops::HessianWithLoopsInfo< Base > > &loopHessInfo, bool useSymmetry)
 
virtual void generateSparseHessianWithLoopsSourceFromRev2 (const std::map< size_t, CompressedVectorInfo > &hessInfo, size_t maxCompressedSize)
 
virtual void generateFunctionNameLoopRev2 (std::ostringstream &cache, const LoopModel< Base > &loop, size_t g)
 
virtual void generateSparsity1DSource (const std::string &function, const std::vector< size_t > &sparsity)
 
virtual void generateSparsity2DSource (const std::string &function, const LocalSparsityInfo &sparsity)
 
virtual void generateSparsity2DSource2 (const std::string &function, const std::vector< LocalSparsityInfo > &sparsities)
 
virtual void generateSparsity1DSource2 (const std::string &function, const std::map< size_t, std::vector< size_t > > &rows)
 
virtual void generateSparseForwardOneSources ()
 
virtual void generateSparseForwardOneSourcesWithAtomics (const std::map< size_t, std::vector< size_t > > &elements)
 
virtual void generateSparseForwardOneSourcesNoAtomics (const std::map< size_t, std::vector< size_t > > &elements)
 
virtual void generateForwardOneSources ()
 
virtual void prepareSparseForwardOneWithLoops (const std::map< size_t, std::vector< size_t > > &elements)
 
virtual void createForwardOneWithLoopsNL (CodeHandler< Base > &handler, size_t j, std::vector< CG< Base > > &jacCol)
 
virtual void generateSparseReverseOneSources ()
 
virtual void generateSparseReverseOneSourcesWithAtomics (const std::map< size_t, std::vector< size_t > > &elements)
 
virtual void generateSparseReverseOneSourcesNoAtomics (const std::map< size_t, std::vector< size_t > > &elements)
 
virtual void generateReverseOneSources ()
 
virtual void prepareSparseReverseOneWithLoops (const std::map< size_t, std::vector< size_t > > &elements)
 
virtual void createReverseOneWithLoopsNL (CodeHandler< Base > &handler, size_t i, std::vector< CG< Base > > &jacRow)
 
virtual void generateSparseReverseTwoSources ()
 
virtual void generateSparseReverseTwoSourcesWithAtomics (const std::map< size_t, std::vector< size_t > > &elements)
 
virtual void generateSparseReverseTwoSourcesNoAtomics (const std::map< size_t, std::vector< size_t > > &elements, const std::vector< size_t > &evalRows, const std::vector< size_t > &evalCols)
 
virtual void generateReverseTwoSources ()
 
virtual void generateGlobalDirectionalFunctionSource (const std::string &function, const std::string &function2_suffix, const std::string &function_sparsity, const std::map< size_t, std::vector< size_t > > &elements)
 
virtual void prepareSparseReverseTwoWithLoops (const std::map< size_t, std::vector< size_t > > &elements)
 
virtual void determineJacobianSparsity ()
 
virtual void generateJacobianSparsitySource ()
 
virtual void determineHessianSparsity ()
 
std::vector< ModelCSourceGen< Base >::ColorcolorByRow (const std::set< size_t > &columns, const SparsitySetType &sparsity)
 
virtual void generateHessianSparsitySource ()
 
void startingJob (const std::string &jobName, const JobType &type=JobTypeHolder<>::DEFAULT)
 
void finishedJob ()
 

Static Protected Member Functions

static void generateFunctionNameLoopFor1 (std::ostringstream &cache, const std::string &modelName, const LoopModel< Base > &loop, size_t g)
 
static void generateFunctionNameLoopRev1 (std::ostringstream &cache, const std::string &modelName, const LoopModel< Base > &loop, size_t i)
 
static void generateFunctionNameLoopRev2 (std::ostringstream &cache, const std::string &modelName, const LoopModel< Base > &loop, size_t g)
 
static std::map< size_t, std::map< size_t, CG< Base > > > generateLoopFor1Jac (ADFun< CGBase > &fun, const SparsitySetType &sparsity, const SparsitySetType &evalSparsity, const std::vector< CGBase > &xl, bool constainsAtomics)
 
static std::vector< std::map< size_t, CGBase > > generateLoopRev1Jac (ADFun< CGBase > &fun, const SparsitySetType &sparsity, const SparsitySetType &evalSparsity, const std::vector< CGBase > &xl, bool constainsAtomics)
 
static std::map< size_t, std::vector< std::set< size_t > > > determineOrderByCol (const std::map< size_t, std::vector< size_t > > &elements, const LocalSparsityInfo &sparsity)
 
static std::map< size_t, std::vector< std::set< size_t > > > determineOrderByCol (const std::map< size_t, std::vector< size_t > > &elements, const std::vector< size_t > &userRows, const std::vector< size_t > &userCols)
 
static std::vector< std::set< size_t > > determineOrderByCol (size_t col, const std::vector< size_t > &colElements, const std::vector< size_t > &userRows, const std::vector< size_t > &userCols)
 
static std::map< size_t, std::vector< std::set< size_t > > > determineOrderByRow (const std::map< size_t, std::vector< size_t > > &elements, const LocalSparsityInfo &sparsity)
 
static std::map< size_t, std::vector< std::set< size_t > > > determineOrderByRow (const std::map< size_t, std::vector< size_t > > &elements, const std::vector< size_t > &userRows, const std::vector< size_t > &userCols)
 
static std::vector< std::set< size_t > > determineOrderByRow (size_t row, const std::vector< size_t > &rowsElements, const std::vector< size_t > &userRows, const std::vector< size_t > &userCols)
 
static void printFileStartPThreads (std::ostringstream &cache, const std::string &baseTypeName)
 
static void printFunctionStartPThreads (std::ostringstream &cache, size_t size)
 
static void printFunctionEndPThreads (std::ostringstream &cache, size_t size)
 
static void printFileStartOpenMP (std::ostringstream &cache)
 
static void printFunctionStartOpenMP (std::ostringstream &cache, size_t size)
 
static void printLoopStartOpenMP (std::ostringstream &cache, size_t size)
 
static void printLoopEndOpenMP (std::ostringstream &cache, size_t size)
 

Protected Attributes

ADFun< CGBase > & _fun
 
LoopFreeModel< Base > * _funNoLoops
 
std::set< LoopModel< Base > * > _loopTapes
 
std::string _name
 
const std::string _baseTypeName
 
size_t _parameterPrecision
 
std::vector< Base > _x
 
bool _multiThreading
 
bool _zero
 generate source code for the zero order model evaluation
 
bool _zeroEvaluated
 
bool _jacobian
 generate source code for a dense Jacobian
 
bool _hessian
 generate source code for a dense Hessian
 
bool _sparseJacobian
 generate source code for a sparse Jacobian
 
bool _sparseHessian
 generate source code for a sparse Hessian
 
bool _hessianByEquation
 
bool _forwardOne
 generate source code for forward first order mode
 
bool _reverseOne
 generate source code for reverse first order mode
 
bool _reverseTwo
 generate source code for reverse second order mode
 
bool _sparseJacobianReusesOne
 
bool _sparseHessianReusesRev2
 
JacobianADMode _jacMode
 
Position _custom_jac
 
LocalSparsityInfo _jacSparsity
 
Position _custom_hess
 
LocalSparsityInfo _hessSparsity
 
std::vector< LocalSparsityInfo_hessSparsities
 
std::vector< std::string > _atomicFunctions
 
std::map< size_t, AtomicUseInfo< Base > > * _atomicsInfo
 
std::ostringstream _cache
 
size_t _maxAssignPerFunc
 
size_t _maxOperationsPerAssignment
 
std::vector< std::set< size_t > > _relatedDepCandidates
 
std::map< LoopModel< Base > *, std::map< size_t, std::map< size_t, std::set< size_t > > > > _loopFor1Groups
 
std::map< size_t, std::set< size_t > > _nonLoopFor1Elements
 
std::map< LoopModel< Base > *, std::map< size_t, std::map< size_t, std::set< size_t > > > > _loopRev1Groups
 
std::map< size_t, std::set< size_t > > _nonLoopRev1Elements
 
std::map< LoopModel< Base > *, std::map< size_t, std::map< size_t, std::set< size_t > > > > _loopRev2Groups
 
std::map< size_t, std::set< size_t > > _nonLoopRev2Elements
 
JobTimer_jobTimer
 
std::map< std::string, std::string > _sources
 

Static Protected Attributes

static const std::string CONST = "const"
 

Friends

class ModelLibraryCSourceGen< Base >
 
class ModelLibraryProcessor< Base >
 

Detailed Description

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

Generates C source code for a model.

Author
Joao Leal

Definition at line 160 of file declare_cg.hpp.

Constructor & Destructor Documentation

◆ ModelCSourceGen()

template<class Base>
CppAD::cg::ModelCSourceGen< Base >::ModelCSourceGen ( ADFun< CppAD::cg::CG< Base > > &  fun,
std::string  model 
)
inline

Creates a new C language compilation helper for a model

Parameters
funThe ADFun with the taped model (should only be deleted after this object)
modelThe model name (must be a valid C function name)

Definition at line 292 of file model_c_source_gen.hpp.

Member Function Documentation

◆ analyseSparseHessianWithLoops()

template<class Base >
void CppAD::cg::ModelCSourceGen< Base >::analyseSparseHessianWithLoops ( const std::vector< size_t > &  lowerHessRows,
const std::vector< size_t > &  lowerHessCols,
const std::vector< size_t > &  lowerHessOrder,
SparsitySetType &  noLoopEvalJacSparsity,
SparsitySetType &  noLoopEvalHessSparsity,
std::vector< std::map< size_t, std::set< size_t > > > &  noLoopEvalHessLocations,
std::map< LoopModel< Base > *, loops::HessianWithLoopsInfo< Base > > &  loopHessInfo,
bool  useSymmetry 
)
inlineprotected

determine sparsities

Load locations in the compressed Hessian d d y_i d x_j2 d x_j1

Present in the equations outside the loops

indexed - indexed d d f_i d x_l2 d x_l1

indexed - non-indexed d d f_i -> d d f_i d x_j2 d x_l1 d x_l2 d x_j1

indexed - constant z d d f_i . d z_k d z_k d x_l1 d x_j2

check if this temporary depends on j2

non-indexed - indexed d d f_i d x_l2 d x_j1

non-indexed - non-indexed d d f_i d x_j2 d x_j1

non-indexed - temporaries d d f_i . d z_k d z_k d x_j1 d x_j2

temporaries

temporary - indexed d d f_i d x_l d z_k1

temporary - non-indexed d d f_i d x_j2 d z_k1

temporary - temporary d d f_i . d z_k2 d z_k2 d z_k1 d x_j2

temporary - temporary d f_i . d d z_k1 d z_k1 d x_j2 d x_j1

Definition at line 52 of file model_c_source_gen_loops_hess.hpp.

◆ analyseSparseJacobianWithLoops()

template<class Base >
void CppAD::cg::ModelCSourceGen< Base >::analyseSparseJacobianWithLoops ( const std::vector< size_t > &  rows,
const std::vector< size_t > &  cols,
const std::vector< size_t > &  location,
SparsitySetType &  noLoopEvalSparsity,
std::vector< std::map< size_t, std::set< size_t > > > &  noLoopEvalLocations,
std::map< LoopModel< Base > *, SparsitySetType > &  loopsEvalSparsities,
std::map< LoopModel< Base > *, std::vector< loops::JacobianWithLoopsRowInfo > > &  loopEqInfo 
)
inlineprotected

determine sparsities

Generate index patterns for the Jacobian elements resulting from loops

Load locations in the compressed Jacobian

Equation present in the model without loops

Equation belongs to a loop

find if there are indexed variables in this equation pattern and iteration which use j

find if there is a non indexed variable in this equation pattern for j

find temporary variables used by this equation pattern

check if this temporary depends on j

Definition at line 38 of file model_c_source_gen_loops_jac.hpp.

◆ baseTypeName()

template<>
std::string CppAD::cg::ModelCSourceGen< double >::baseTypeName ( )
inline

Specializations

Definition at line 823 of file model_c_source_gen_impl.hpp.

◆ colorByRow()

template<class Base >
std::vector< typename ModelCSourceGen< Base >::Color > CppAD::cg::ModelCSourceGen< Base >::colorByRow ( const std::set< size_t > &  columns,
const SparsitySetType &  sparsity 
)
inlineprotected

Determines groups of rows from a sparsity pattern which do not share the same columns

Parameters
columnsthe column indexes of interest (all others are ignored); an empty set means all columns
sparsityThe sparsity pattern to color
Returns
the colors

try not match the columns of each row to a color which did not have those columns yet

Definition at line 256 of file model_c_source_gen_impl.hpp.

◆ determineHessianSparsity()

template<class Base >
void CppAD::cg::ModelCSourceGen< Base >::determineHessianSparsity ( )
protectedvirtual

sparsity for the sum of the hessians of all equations

sparsity for the hessian of each equations

Coloring

For each individual equation

Retrieve the individual hessians for each equation

Definition at line 544 of file model_c_source_gen_hes.hpp.

◆ determineJacobianSparsity()

template<class Base >
void CppAD::cg::ModelCSourceGen< Base >::determineJacobianSparsity ( )
protectedvirtual

Determine the sparsity pattern

Definition at line 461 of file model_c_source_gen_jac.hpp.

◆ determineSecondOrderElements4Eval()

template<class Base >
void CppAD::cg::ModelCSourceGen< Base >::determineSecondOrderElements4Eval ( std::vector< size_t > &  userRows,
std::vector< size_t > &  userCols 
)
protectedvirtual

Atomic functions migth not have all the elements and thus there may be no symmetry. This will explore symmetry in order to provide the second order elements requested by the user.

Definition at line 517 of file model_c_source_gen_hes.hpp.

◆ generateGlobalDirectionalFunctionSource()

template<class Base >
void CppAD::cg::ModelCSourceGen< Base >::generateGlobalDirectionalFunctionSource ( const std::string &  function,
const std::string &  function2_suffix,
const std::string &  function_sparsity,
const std::map< size_t, std::vector< size_t > > &  elements 
)
protectedvirtual

The function that matches each equation to a directional derivative function

Sparsity

Definition at line 314 of file model_c_source_gen_impl.hpp.

◆ generateSparseForwardOneSources()

template<class Base >
void CppAD::cg::ModelCSourceGen< Base >::generateSparseForwardOneSources ( )
protectedvirtual

with loops

Generate one function for each dependent variable

Definition at line 22 of file model_c_source_gen_for1.hpp.

◆ generateSparseForwardOneSourcesNoAtomics()

template<class Base >
void CppAD::cg::ModelCSourceGen< Base >::generateSparseForwardOneSourcesNoAtomics ( const std::map< size_t, std::vector< size_t > > &  elements)
protectedvirtual

Jacobian

organize results

Create source for each independent/column

Definition at line 133 of file model_c_source_gen_for1.hpp.

◆ generateSparseForwardOneSourcesWithAtomics()

template<class Base >
void CppAD::cg::ModelCSourceGen< Base >::generateSparseForwardOneSourcesWithAtomics ( const std::map< size_t, std::vector< size_t > > &  elements)
protectedvirtual

Generate one function for each dependent variable

Definition at line 62 of file model_c_source_gen_for1.hpp.

◆ generateSparseHessianRev2MultiThreadSource()

template<class Base >
std::string CppAD::cg::ModelCSourceGen< Base >::generateSparseHessianRev2MultiThreadSource ( const std::string &  functionName,
std::map< size_t, CompressedVectorInfo hessInfo,
size_t  maxCompressedSize,
const std::string &  functionRev2,
const std::string &  rev2Suffix,
MultiThreadingType  multiThreadingType 
)
protectedvirtual

Create independent functions for each row/column of the Jacobian

PThreads pool needs a function with a void pointer argument

Hessian function

Definition at line 374 of file model_c_source_gen_hes.hpp.

◆ generateSparseHessianSource()

template<class Base >
void CppAD::cg::ModelCSourceGen< Base >::generateSparseHessianSource ( MultiThreadingType  multiThreadingType)
protectedvirtual

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

Definition at line 79 of file model_c_source_gen_hes.hpp.

◆ generateSparseHessianSourceDirectly()

template<class Base >
void CppAD::cg::ModelCSourceGen< Base >::generateSparseHessianSourceDirectly ( )
protectedvirtual

we might have to consider a slightly different order than the one specified by the user according to the available elements in the sparsity

with loops

Definition at line 93 of file model_c_source_gen_hes.hpp.

◆ generateSparseHessianSourceFromRev2()

template<class Base >
void CppAD::cg::ModelCSourceGen< Base >::generateSparseHessianSourceFromRev2 ( MultiThreadingType  multiThreadingType)
protectedvirtual

we might have to consider a slightly different order than the one specified by the user according to the available elements in the sparsity

determine to which functions we can provide the hessian row directly without needing a temporary array (compressed)

determine the maximum size of the temporary array

with loops

Definition at line 227 of file model_c_source_gen_hes.hpp.

◆ generateSparseHessianWithLoopsSourceFromRev2()

template<class Base >
void CppAD::cg::ModelCSourceGen< Base >::generateSparseHessianWithLoopsSourceFromRev2 ( const std::map< size_t, CompressedVectorInfo > &  hessInfo,
size_t  maxCompressedSize 
)
inlineprotectedvirtual

Generate the source code

Definition at line 22 of file model_c_source_gen_loops_hess_r2.hpp.

◆ generateSparseJacobianForRevMultiThreadSource()

template<class Base >
std::string CppAD::cg::ModelCSourceGen< Base >::generateSparseJacobianForRevMultiThreadSource ( const std::string &  functionName,
std::map< size_t, CompressedVectorInfo jacInfo,
size_t  maxCompressedSize,
const std::string &  functionRevFor,
const std::string &  revForSuffix,
bool  forward,
MultiThreadingType  multiThreadingType 
)
protectedvirtual

Create independent functions for each row/column of the Jacobian

PThreads pool needs a function with a void pointer argument

Jacobian function

Definition at line 320 of file model_c_source_gen_jac.hpp.

◆ generateSparseJacobianForRevSource()

template<class Base >
void CppAD::cg::ModelCSourceGen< Base >::generateSparseJacobianForRevSource ( bool  forward,
MultiThreadingType  multiThreadingType 
)
protectedvirtual

determine to which functions we can provide the jacobian row/column directly without needing a temporary array (compressed)

with loops

Definition at line 151 of file model_c_source_gen_jac.hpp.

◆ generateSparseJacobianSource()

template<class Base >
void CppAD::cg::ModelCSourceGen< Base >::generateSparseJacobianSource ( MultiThreadingType  multiThreadingType)
protectedvirtual

Determine the sparsity pattern

call the appropriate method for source code generation

Definition at line 67 of file model_c_source_gen_jac.hpp.

◆ generateSparseJacobianWithLoopsSourceFromForRev()

template<class Base >
void CppAD::cg::ModelCSourceGen< Base >::generateSparseJacobianWithLoopsSourceFromForRev ( const std::map< size_t, CompressedVectorInfo > &  jacInfo,
size_t  maxCompressedSize,
const std::string &  localFunctionTypeName,
const std::string &  suffix,
const std::string &  keyName,
const std::map< size_t, std::set< size_t > > &  nonLoopElements,
const std::map< LoopModel< Base > *, std::map< size_t, std::map< size_t, std::set< size_t > > > > &  loopGroups,
void(*)(std::ostringstream &cache, const std::string &modelName, const LoopModel< Base > &loop, size_t g)  generateLocalFunctionName 
)
protectedvirtual

Generate the source code

Definition at line 22 of file model_c_source_gen_loops_jac_fr1.hpp.

◆ generateSparseReverseOneSources()

template<class Base >
void CppAD::cg::ModelCSourceGen< Base >::generateSparseReverseOneSources ( )
protectedvirtual

with loops

Generate one function for each dependent variable

Definition at line 22 of file model_c_source_gen_rev1.hpp.

◆ generateSparseReverseOneSourcesNoAtomics()

template<class Base >
void CppAD::cg::ModelCSourceGen< Base >::generateSparseReverseOneSourcesNoAtomics ( const std::map< size_t, std::vector< size_t > > &  elements)
protectedvirtual

Jacobian

organize results

Create source for each equation/row

Definition at line 138 of file model_c_source_gen_rev1.hpp.

◆ generateSparseReverseOneSourcesWithAtomics()

template<class Base >
void CppAD::cg::ModelCSourceGen< Base >::generateSparseReverseOneSourcesWithAtomics ( const std::map< size_t, std::vector< size_t > > &  elements)
protectedvirtual

Generate one function for each dependent variable

Generate one function for each dependent variable

Definition at line 62 of file model_c_source_gen_rev1.hpp.

◆ generateSparseReverseTwoSources()

template<class Base >
void CppAD::cg::ModelCSourceGen< Base >::generateSparseReverseTwoSources ( )
protectedvirtual

we might have to consider a slightly different order than the one specified by the user according to the available elements in the sparsity

with loops

Definition at line 22 of file model_c_source_gen_rev2.hpp.

◆ generateSparseReverseTwoSourcesNoAtomics()

template<class Base >
void CppAD::cg::ModelCSourceGen< Base >::generateSparseReverseTwoSourcesNoAtomics ( const std::map< size_t, std::vector< size_t > > &  elements,
const std::vector< size_t > &  evalRows,
const std::vector< size_t > &  evalCols 
)
protectedvirtual

Generate one function for each independent variable

Definition at line 146 of file model_c_source_gen_rev2.hpp.

◆ generateZeroSource()

template<class Base >
void CppAD::cg::ModelCSourceGen< Base >::generateZeroSource ( )
protectedvirtual

Contains loops

Definition at line 22 of file model_c_source_gen_for0.hpp.

◆ getJacobianADMode()

template<class Base>
JacobianADMode CppAD::cg::ModelCSourceGen< Base >::getJacobianADMode ( ) const
inline

Provides the Automatic Differentiation mode used to generate the source code for the Jacobian

Returns
the Automatic Differentiation mode

Definition at line 459 of file model_c_source_gen.hpp.

◆ getMaxAssignmentsPerFunc()

template<class Base>
size_t CppAD::cg::ModelCSourceGen< Base >::getMaxAssignmentsPerFunc ( ) const
inline

The maximum number of assignment per generated function. Zero means it is disabled (no limit). Note that it is not possible to split some function (e.g., containing loops) and, therefore, this limit can be violated.

Returns
The maximum number of assignments per file/function

Definition at line 862 of file model_c_source_gen.hpp.

◆ getMaxOperationsPerAssignment()

template<class Base>
size_t CppAD::cg::ModelCSourceGen< Base >::getMaxOperationsPerAssignment ( ) const
inline

The maximum number of operations per variable assignment.

Returns
The maximum number of operations per variable assignment

Definition at line 885 of file model_c_source_gen.hpp.

◆ getName()

template<class Base>
const std::string& CppAD::cg::ModelCSourceGen< Base >::getName ( ) const
inline

Provides the model name which should be a valid C function name.

Returns
the model name

Definition at line 340 of file model_c_source_gen.hpp.

Referenced by CppAD::cg::ModelLibraryCSourceGen< Base >::addModel().

◆ getParameterPrecision()

template<class Base>
virtual size_t CppAD::cg::ModelCSourceGen< Base >::getParameterPrecision ( ) const
inlinevirtual

Provides the maximum precision used to print constant values in the generated source code

Returns
the maximum number of digits

Definition at line 376 of file model_c_source_gen.hpp.

◆ isCreateForwardZero()

template<class Base>
bool CppAD::cg::ModelCSourceGen< Base >::isCreateForwardZero ( ) const
inline

Determines whether or not to generate source-code for a function that evaluates the original model.

Returns
true if source-code for the original model should be created, false otherwise

Definition at line 665 of file model_c_source_gen.hpp.

◆ isCreateHessian()

template<class Base>
bool CppAD::cg::ModelCSourceGen< Base >::isCreateHessian ( ) const
inline

Determines whether or not to generate source-code for a function that evaluates a dense Hessian.

Returns
true if source-code for a dense Hessian should be created, false otherwise

Definition at line 438 of file model_c_source_gen.hpp.

◆ isCreateHessianSparsityByEquation()

template<class Base>
bool CppAD::cg::ModelCSourceGen< Base >::isCreateHessianSparsityByEquation ( ) const
inline

Determines whether or not to generate source-code for a function that provides the Hessian sparsity pattern for each equation/dependent, when the sparse hessian creation is enabled. Even if this flag is set to false the function can still be generated if the second-order reverse mode is enabled.

Returns
true if source-code for a Hessians sparsities patterns should be created, false otherwise

Definition at line 575 of file model_c_source_gen.hpp.

◆ isCreateJacobian()

template<class Base>
bool CppAD::cg::ModelCSourceGen< Base >::isCreateJacobian ( ) const
inline

Determines whether or not to generate source-code for a function that evaluates a dense Jacobian.

Returns
true if source-code for a dense Jacobian should be created, false otherwise

Definition at line 480 of file model_c_source_gen.hpp.

◆ isCreateReverseOne()

template<class Base>
bool CppAD::cg::ModelCSourceGen< Base >::isCreateReverseOne ( ) const
inline

Determines whether or not to generate source-code for the first-order reverse mode that is used for the evaluation of the Jacobian when the model is used through a user defined atomic AD function. Enabling the generation of individuals functions for reverse-mode might have a small negative impact on the performance of the evaluation of the sparse Jacobian (if reverse-mode is selected).

See also
isCreateSparseJacobian()
Returns
true if the generation of the source for first-order reverse mode is enabled, false otherwise.

Definition at line 730 of file model_c_source_gen.hpp.

◆ isCreateReverseTwo()

template<class Base>
bool CppAD::cg::ModelCSourceGen< Base >::isCreateReverseTwo ( ) const
inline

Determines whether or not to generate source-code for the second-order reverse mode that is used for the evaluation of the hessian when the model is used through a user defined atomic AD function. Enabling the generation of individuals functions for reverse-mode can have a negative impact on the performance of the evaluation of the sparse hessian.

Warning: only the values for px[j * (k+1)] will be defined, since px[j * (k+1) + 1] is not used during the hessian evaluation.

Returns
true if the generation of the source for second-order reverse mode is enabled, false otherwise.

Definition at line 767 of file model_c_source_gen.hpp.

◆ isCreateSparseForwardOne()

template<class Base>
bool CppAD::cg::ModelCSourceGen< Base >::isCreateSparseForwardOne ( ) const
inline

Determines whether or not to generate source-code for the first-order forward mode that is used for the evaluation of the Jacobian when the model is used through a user defined atomic AD function. Enabling the generation of individuals functions for forward-mode might have a small negative impact on the performance of the evaluation of the sparse Jacobian (if forward mode is selected).

See also
isCreateSparseJacobian()
Returns
true if the generation of the source for first-order forward mode is enabled, false otherwise.

Definition at line 694 of file model_c_source_gen.hpp.

◆ isCreateSparseHessian()

template<class Base>
bool CppAD::cg::ModelCSourceGen< Base >::isCreateSparseHessian ( ) const
inline

Determines whether or not to generate source-code for a function that evaluates a sparse Hessian. If ReverseTwo and SparseHessianReusesRev2 are also enabled the generated source-code will use the individual generated functions from the second-order reverse mode. Enabling the generation of individuals functions for reverse-mode can have a negative impact on the performance of the evaluation of the sparse hessian since Hessian symmetry will not be exploited. To improve performance one can request only the upper or lower elements of the hessian using setCustomSparseHessianElements().

See also
setCustomSparseHessianElements()
setSparseHessianReusesRev2()
Returns
true if source-code for a sparse Hessian should be created, false otherwise

Definition at line 513 of file model_c_source_gen.hpp.

◆ isCreateSparseJacobian()

template<class Base>
bool CppAD::cg::ModelCSourceGen< Base >::isCreateSparseJacobian ( ) const
inline

Determines whether or not to generate source-code for a function that evaluates a sparse Jacobian. If ReverseOne or ForwardOne functions are enabled, then the sparse Jacobian evaluation might use those functions. Enabling the generation of individuals functions for reverse-mode can have a small negative impact on the performance of the evaluation of the parse Jacobian.

See also
setCustomSparseJacobianElements()
Returns
true if source-code for a sparse Jacobian should be created, false otherwise

Definition at line 607 of file model_c_source_gen.hpp.

◆ isMultiThreading()

template<class Base>
bool CppAD::cg::ModelCSourceGen< Base >::isMultiThreading ( ) const
inline

Returns whether or not multithreading directives can be generated to parallelize the sparse Jacobian and sparse Hessian evaluation. Multithreaded code is only generated if requested by the model library. For the sparse Jacobian, the _sparseJacobianReusesOne must be enabled, at least one of _forwardOne and _reverseOne must be enabled, and loop detection must be disabled. For the sparse Hessian, the _sparseHessianReusesRev2 and _reverseTwo must be enabled and loop detection must be disabled.

Returns
whether or not multithreading can be used for this model

Definition at line 402 of file model_c_source_gen.hpp.

◆ isSparseHessianReusesRev2()

template<class Base>
bool CppAD::cg::ModelCSourceGen< Base >::isSparseHessianReusesRev2 ( ) const
inline

Determines whether or not the sparse Hessian should reuse functions generated for the reverse two pass. The sparse Hessian will only make use of the reverse two mode if both this flag is set to true and the reverseTwo mode is enabled.

Returns
true if the functions created for reverse 2 mode should be reused to determine the sparse Hessian, false otherwise

Definition at line 548 of file model_c_source_gen.hpp.

◆ isSparseJacobianReuse1stOrderPasses()

template<class Base>
bool CppAD::cg::ModelCSourceGen< Base >::isSparseJacobianReuse1stOrderPasses ( ) const
inline

Determines whether or not the sparse Jacobian should reuse functions generated for the forward one or reverse one pass. The sparse Jacobian will only make use of these functions if both this flag is set to true and one of the forward one and reverse one mode is enabled.

Returns
true if the functions created for forward or reverse 1 mode should be reused to determine the sparse Jacobian, false otherwise

Definition at line 639 of file model_c_source_gen.hpp.

◆ prepareForward0WithLoops()

template<class Base >
std::vector< CG< Base > > CppAD::cg::ModelCSourceGen< Base >::prepareForward0WithLoops ( CodeHandler< Base > &  handler,
const std::vector< CGBase > &  x 
)
protectedvirtual

Generates the operation graph for the zero order model with loops

Definition at line 134 of file model_c_source_gen_loops_for0.hpp.

◆ prepareSparseForwardOneWithLoops()

template<class Base >
void CppAD::cg::ModelCSourceGen< Base >::prepareSparseForwardOneWithLoops ( const std::map< size_t, std::vector< size_t > > &  elements)
protectedvirtual

original equations outside the loops

zero order

Jacobian

Create source for each variable present in equations outside loops

evaluate loop model Jacobian

determine if a loop should be created

Model index pattern

detect the index pattern for the model iterations based on jcol and the local loop iteration

try to fit a combination of two patterns: j = fStart(jcol) + flit(lit);

Local iteration count pattern

make the loop end

move non-indexed expressions outside loop

No loop required

Generate the source code inside the loop

prepare the nodes to be reused!

Sparsity

Definition at line 26 of file model_c_source_gen_loops_for1.hpp.

◆ prepareSparseHessianWithLoops()

template<class Base >
std::vector< CG< Base > > CppAD::cg::ModelCSourceGen< Base >::prepareSparseHessianWithLoops ( CodeHandler< Base > &  handler,
std::vector< CGBase > &  indVars,
std::vector< CGBase > &  w,
const std::vector< size_t > &  lowerHessRows,
const std::vector< size_t > &  lowerHessCols,
const std::vector< size_t > &  lowerHessOrder,
const std::map< size_t, size_t > &  duplicates 
)
protectedvirtual

Loops Generates a sparse Hessian using loops.

The original model is split into two models:

  • one for the repeated equations

    \[ y_i = f(x_{l(j)}, x_v, z_k) \]

  • and another for the equations which do not belong in a loop and the non-indexed temporary variables ( \(z\)) used by \(f\).

    \[ z_k = g_k(x_v) \]

The Hessian elements for the equations in loops are evaluated as:

\[ \frac{\mathrm{d}^2 y_i}{\partial x_w \partial x_v} = \sum_k \left( \frac{\partial^2 f_i}{\partial x_w \partial z_k} \frac{\partial z_k}{\partial x_v} + \frac{\partial f_i}{\partial z_k} \frac{\partial^2 z_k}{\partial x_w \partial x_v} \right) + \sum_j \left( \frac{\partial^2 f_i}{\partial x_w \partial x_{l(j)}} \frac{\partial x_{l(j)}}{\partial x_v} \right) + \frac{\partial^2 f_i}{\partial x_w \partial x_v} \]

Parameters
handlerThe operation graph handler
indVarsThe independent variables
Returns
the operation graph for the compressed jacobin with loops

Load locations in the compressed Hessian d d y_i d x_j2 d x_j1

prepare loop independents

prepare loop independents

make the loop start

make the loop's indexed variables

Calculate Hessians and Jacobians

Loops - evaluate Jacobian and Hessian

No loops

Jacobian and Hessian - temporary variables

Hessian - original equations

Loops - Hessian

loop the groups of equations present at the same iterations

indexed - non-indexed

  • usually done by (non-indexed - indexed) by exploiting the symmetry

indexed - temporary

non-indexed - non-indexed

loop the groups of equations present at the same iterations

non-indexed - temporary

temporary - non-indexed

 d f_i       .    d x_k1

d x_j2 d z_k1 d x_j1

temporary - temporary

temporary - temporary

make the loop end

move non-indexed expressions outside loop

duplicates (TODO: use loops)

Definition at line 558 of file model_c_source_gen_loops_hess.hpp.

◆ prepareSparseJacobianRowWithLoops()

template<class Base >
void CppAD::cg::ModelCSourceGen< Base >::prepareSparseJacobianRowWithLoops ( CodeHandler< Base > &  handler,
LoopModel< Base > &  lModel,
size_t  tapeI,
const loops::JacobianWithLoopsRowInfo rowInfo,
const std::vector< std::map< size_t, CGBase > > &  dyiDxtape,
const std::vector< std::map< size_t, CGBase > > &  dzDx,
const CGBase py,
IndexOperationNode< Base > &  iterationIndexOp,
std::vector< loops::IfElseInfo< Base > > &  ifElses,
size_t &  jacLE,
std::vector< std::pair< CG< Base >, IndexPattern *> > &  indexedLoopResults,
std::set< size_t > &  allLocations 
)
inlineprotected

indexed variable contributions

non-indexed variable contributions

Definition at line 404 of file model_c_source_gen_loops_jac.hpp.

◆ prepareSparseJacobianWithLoops()

template<class Base >
std::vector< CG< Base > > CppAD::cg::ModelCSourceGen< Base >::prepareSparseJacobianWithLoops ( CodeHandler< Base > &  handler,
const std::vector< CGBase > &  x,
bool  forward 
)
protectedvirtual

Generates a sparse Jacobian using loops.

The original model is split into two models:

  • one for the repeated equations

    \[ y_i = f(x_{l(j)}, x_v, z_k) \]

  • and another for the equations which do not belong in a loop and the non-indexed temporary variables ( \(z\)) used by \(f\).

    \[ z_k = g_k(x_v) \]

The jacobian elements for the equations in loops are evaluated as:

\[ \frac{\mathrm{d} y_i}{\mathrm{d} x_v} = \sum_k \left( \frac{\partial f_i}{\partial z_k} \frac{\partial z_k}{\partial x_v} \right) + \sum_j \left( \frac{\partial f_i}{\partial x_{l(j)}} \frac{\partial x_{l(j)}}{\partial x_v} \right) + \frac{\partial f_i}{\partial x_v} \]

Parameters
handlerThe operation graph handler
indVarsThe independent variables
Returns
the operation graph for the compressed jacobin with loops

original equations outside the loops

zero order

Jacobian

make the loop start

evaluate loop model Jacobian

make the loop end

move non-indexed expressions outside loop

Definition at line 217 of file model_c_source_gen_loops_jac.hpp.

◆ prepareSparseReverseOneWithLoops()

template<class Base >
void CppAD::cg::ModelCSourceGen< Base >::prepareSparseReverseOneWithLoops ( const std::map< size_t, std::vector< size_t > > &  elements)
protectedvirtual
Parameters
sourcesmaps files names to the generated source code
elements[equation]{vars}

original equations outside the loops

zero order

jacobian

Create source for each variable present in equations outside loops

evaluate loop model Jacobian

process each equation pattern (row in the loop tape)

determine iteration index through the row index

generate the operation graph for this equation pattern

save information on: row->{compressed reverse 1 position}

Generate the source code

Generate the source code inside the loop

prepare the nodes to be reused!

Sparsity

Definition at line 31 of file model_c_source_gen_loops_rev1.hpp.

◆ prepareSparseReverseTwoWithLoops()

template<class Base >
void CppAD::cg::ModelCSourceGen< Base >::prepareSparseReverseTwoWithLoops ( const std::map< size_t, std::vector< size_t > > &  elements)
protectedvirtual

Loops

Calculate Hessians and Jacobians

prepare loop independents

make the loop's indexed variables

Calculate Hessians and Jacobians

Loops - evaluate Jacobian and Hessian

No loops

Jacobian and Hessian - temporary variables

Loops - Hessian

determine if a loop should be created

Model index pattern

detect the index pattern for the model iterations based on jrow and the local loop iteration

try to fit a combination of two patterns: j = fStart(jrow) + flit(lit);

Local iteration count pattern

make the loop end

move non-indexed expressions outside loop

No loop required

Generate the source code inside the loop

prepare the nodes to be reused!

hessian - original equations

Generate one function for each independent variable / hessian row

Sparsity

Definition at line 62 of file model_c_source_gen_loops_rev2.hpp.

◆ setCreateForwardOne()

template<class Base>
void CppAD::cg::ModelCSourceGen< Base >::setCreateForwardOne ( bool  create)
inline

Defines whether or not to generate source-code for the first-order forward mode that is used for the evaluation of the Jacobian when the model is used through a user defined atomic AD function. Enabling the generation of individuals functions for forward-mode might have a small negative impact on the performance of the evaluation of the sparse Jacobian (if forward-mode is selected).

See also
setCreateSparseJacobian()
Parameters
createtrue if the generation of the source for first-order forward mode is enabled, false otherwise.

Definition at line 712 of file model_c_source_gen.hpp.

◆ setCreateForwardZero()

template<class Base>
void CppAD::cg::ModelCSourceGen< Base >::setCreateForwardZero ( bool  create)
inline

Defines whether or not to generate source-code for a function that evaluates the original model.

Parameters
createtrue if source-code for the original model should be created, false otherwise

Definition at line 676 of file model_c_source_gen.hpp.

◆ setCreateHessian()

template<class Base>
void CppAD::cg::ModelCSourceGen< Base >::setCreateHessian ( bool  create)
inline

Defines whether or not to generate source-code for a function that evaluates a dense Hessian.

Parameters
createtrue if source-code for a dense Hessian should be created, false otherwise

Definition at line 449 of file model_c_source_gen.hpp.

◆ setCreateHessianSparsityByEquation()

template<class Base>
void CppAD::cg::ModelCSourceGen< Base >::setCreateHessianSparsityByEquation ( bool  create)
inline

Defines whether or not to generate source-code for a function that provides the Hessian sparsity pattern for each equation/dependent, when the sparse hessian creation is enabled. Even if this flag is set to false the function can still be generated if the second-order reverse mode is enabled.

Parameters
createtrue if source-code for a Hessians sparsities should be created, false otherwise

Definition at line 589 of file model_c_source_gen.hpp.

◆ setCreateJacobian()

template<class Base>
void CppAD::cg::ModelCSourceGen< Base >::setCreateJacobian ( bool  create)
inline

Defines whether or not to generate source-code for a function that evaluates a dense Jacobian.

Parameters
createtrue if source-code for a dense Jacobian should be created, false otherwise

Definition at line 491 of file model_c_source_gen.hpp.

◆ setCreateReverseOne()

template<class Base>
void CppAD::cg::ModelCSourceGen< Base >::setCreateReverseOne ( bool  create)
inline

Determines whether or not to generate source-code for the first-order reverse mode that is used for the evaluation of the Jacobian when the model is used through a user defined atomic AD function. Enabling the generation of individuals functions for reverse-mode might have a small negative impact on the performance of the evaluation of the sparse Jacobian (if reverse-mode is selected).

See also
setCreateSparseJacobian()
Parameters
createtrue if the source for first-order reverse mode functions should be generated, false otherwise.

Definition at line 748 of file model_c_source_gen.hpp.

◆ setCreateReverseTwo()

template<class Base>
void CppAD::cg::ModelCSourceGen< Base >::setCreateReverseTwo ( bool  create)
inline

Defines whether or not to enable the generation of the source-code for the second-order reverse mode that is used for the evaluation of the hessian when the model is used through a user defined atomic AD function. Enabling the generation of individuals functions for reverse-mode can have a negative impact on the performance of the evaluation of the hessian. To improve performance one can request only the upper or lower elements of the hessian using setCustomSparseHessianElements() and later only request those elements through the outer model (ADFun).

Warning: only the values for px[j * (k+1)] will be defined, since px[j * (k+1) + 1] is not used during the hessian evaluation.

Parameters
createtrue to enable the generation of the source for second-order reverse mode, false otherwise.

Definition at line 788 of file model_c_source_gen.hpp.

◆ setCreateSparseHessian()

template<class Base>
void CppAD::cg::ModelCSourceGen< Base >::setCreateSparseHessian ( bool  create)
inline

Defines whether or not to generate source-code for a function that evaluates a sparse Hessian. If ReverseTwo and SparseHessianReusesRev2 are also enabled the generated source-code will use the individual generated functions from the second-order reverse mode. Enabling the generation of individuals functions for reverse-mode can have a negative impact on the performance of the evaluation of the sparse hessian since Hessian symmetry will not be exploited. To improve performance one can request only the upper or lower elements of the hessian using setCustomSparseHessianElements().

See also
setCustomSparseHessianElements()
setSparseHessianReusesRev2()
Parameters
createtrue if source-code for a sparse Hessian should be created, false otherwise

Definition at line 535 of file model_c_source_gen.hpp.

◆ setCreateSparseJacobian()

template<class Base>
void CppAD::cg::ModelCSourceGen< Base >::setCreateSparseJacobian ( bool  create)
inline

Defines whether or not to generate source-code for a function that evaluates a sparse Jacobian. If ReverseOne or ForwardOne functions are enabled, then the sparse Jacobian evaluation might use those functions. Enabling the generation of individuals functions for reverse-mode can have a small negative impact on the performance of the evaluation of the parse Jacobian.

See also
setCustomSparseJacobianElements()
Parameters
createtrue if source-code for a sparse Jacobian should be created, false otherwise

Definition at line 625 of file model_c_source_gen.hpp.

◆ setCustomSparseHessianElements() [1/2]

template<class Base>
void CppAD::cg::ModelCSourceGen< Base >::setCustomSparseHessianElements ( const std::vector< size_t > &  row,
const std::vector< size_t > &  col 
)
inline

Specifies a user defined Hessian sparsity to be computed. This can be used, for instance, to request only half of the Hessian to be computed due to its symmetry. The elements can be provided in any order as long as they are a subset of the full Hessian sparsity pattern.

Parameters
rowThe row indices of the independent variables for the sparsity pattern in the order they will be provided
colThe column indices of the independent variables for the sparsity pattern in the order they will be provided

Definition at line 833 of file model_c_source_gen.hpp.

◆ setCustomSparseHessianElements() [2/2]

template<class Base>
template<class VectorSet >
void CppAD::cg::ModelCSourceGen< Base >::setCustomSparseHessianElements ( const VectorSet &  elements)
inline

Specifies a user defined Hessian sparsity to be computed. This can be used, for instance, to request only half of the Hessian to be computed due to its symmetry. The elements must be a subset of the full Hessian sparsity pattern.

Template Parameters
VectorSetA vector of sets
Parameters
elementsThe indices of the independent variables for the sparsity pattern (the vector must not be larger than the number independent variables).

Definition at line 850 of file model_c_source_gen.hpp.

◆ setCustomSparseJacobianElements() [1/2]

template<class Base>
void CppAD::cg::ModelCSourceGen< Base >::setCustomSparseJacobianElements ( const std::vector< size_t > &  row,
const std::vector< size_t > &  col 
)
inline

Specifies a user defined Jacobian sparsity to be computed. The elements can be provided in any order as long as they are a subset of the full Jacobian sparsity pattern.

Parameters
rowThe indices of the equations/dependents for the sparsity pattern in the order they will be provided
colThe indices of the independent variables for the sparsity pattern in the order they will be provided

Definition at line 802 of file model_c_source_gen.hpp.

◆ setCustomSparseJacobianElements() [2/2]

template<class Base>
template<class VectorSet >
void CppAD::cg::ModelCSourceGen< Base >::setCustomSparseJacobianElements ( const VectorSet &  elements)
inline

Specifies a user defined Jacobian sparsity to be computed. The elements must be a subset of the full Jacobian sparsity pattern.

Template Parameters
VectorSetA vector of sets
Parameters
elementsThe indices of the independent variables (defined in a set) for each equation/dependent variable (the vector must not be larger than the number dependent variables).

Definition at line 817 of file model_c_source_gen.hpp.

◆ setJacobianADMode()

template<class Base>
void CppAD::cg::ModelCSourceGen< Base >::setJacobianADMode ( JacobianADMode  mode)
inline

Defines the Automatic Differentiation mode used to generate the source code for the Jacobian

Parameters
modethe Automatic Differentiation mode

Definition at line 469 of file model_c_source_gen.hpp.

◆ setMaxAssignmentsPerFunc()

template<class Base>
void CppAD::cg::ModelCSourceGen< Base >::setMaxAssignmentsPerFunc ( size_t  maxAssignPerFunc)
inline

Sets the maximum number of assignment per generated function. Zero means it is disabled (no limit). By setting a limit, it is possible to reduce the compiler workload by having multiple file/function instead of a very large one. Note that it is not possible to split some function (e.g., containing loops) and, therefore, this limit can be violated.

Parameters
maxAssignPerFuncThe maximum number of assignments per file/function

Definition at line 876 of file model_c_source_gen.hpp.

◆ setMaxOperationsPerAssignment()

template<class Base>
void CppAD::cg::ModelCSourceGen< Base >::setMaxOperationsPerAssignment ( size_t  maxOperationsPerAssignment)
inline

Defines the maximum number of operations per variable assignment. Defining a limit can reduce the memory required for compilation of the source code.

Parameters
maxOperationsPerAssignmentThe maximum number of operations per variable assignment.

Definition at line 895 of file model_c_source_gen.hpp.

◆ setMultiThreading()

template<class Base>
void CppAD::cg::ModelCSourceGen< Base >::setMultiThreading ( bool  multiThreading)
inline

Defines whether or not multithreading directives can be generated to parallelize the sparse Jacobian and sparse Hessian evaluation. Multithreaded code is only generated if requested by the model library. For the sparse Jacobian, the _sparseJacobianReusesOne must be enabled, at least one of _forwardOne and _reverseOne must be enabled, and loop detection must be disabled. For the sparse Hessian, the _sparseHessianReusesRev2 and _reverseTwo must be enabled and loop detection must be disabled.

Parameters
multiThreadingwhether or not multithreading can be used for this model

Definition at line 419 of file model_c_source_gen.hpp.

◆ setParameterPrecision()

template<class Base>
virtual void CppAD::cg::ModelCSourceGen< Base >::setParameterPrecision ( size_t  p)
inlinevirtual

Defines the maximum precision used to print constant values in the generated source code.

Parameters
pthe maximum number of digits

Definition at line 386 of file model_c_source_gen.hpp.

◆ setSparseHessianReusesRev2()

template<class Base>
void CppAD::cg::ModelCSourceGen< Base >::setSparseHessianReusesRev2 ( bool  reuse)
inline

Defines whether or not the sparse Hessian should reuse functions generated for the reverse two pass. The sparse Hessian will only make use of the reverse two mode if both this flag is set to true and the reverseTwo mode is enabled.

Parameters
reusetrue if the functions created for reverse 2 mode should be reused to determine the sparse Hessian, false otherwise

Definition at line 561 of file model_c_source_gen.hpp.

◆ setSparseJacobianReuse1stOrderPasses()

template<class Base>
void CppAD::cg::ModelCSourceGen< Base >::setSparseJacobianReuse1stOrderPasses ( bool  reuse)
inline

Defines whether or not the sparse Jacobian should reuse functions generated for the forward one or reverse one pass. The sparse Jacobian will only make use of these functions if both this flag is set to true and one of the forward one and reverse one mode is enabled.

Parameters
reusetrue if the functions created for forward or reverse 1 mode should be reused to determine the sparse Jacobian, false otherwise

Definition at line 654 of file model_c_source_gen.hpp.

◆ setTypicalIndependentValues()

template<class Base>
template<class VectorBase >
void CppAD::cg::ModelCSourceGen< Base >::setTypicalIndependentValues ( const VectorBase &  x)
inline

Defines typical values for the independent variable vector. These values can be useful when there is a need to call atomic functions, since they may allow to reduce some operations.

Parameters
xThe typical values. An empty vector removes the currently defined values.

Definition at line 353 of file model_c_source_gen.hpp.

Member Data Documentation

◆ _atomicFunctions

template<class Base>
std::vector<std::string> CppAD::cg::ModelCSourceGen< Base >::_atomicFunctions
protected

The order of the atomic functions

Definition at line 224 of file model_c_source_gen.hpp.

◆ _atomicsInfo

template<class Base>
std::map<size_t, AtomicUseInfo<Base> >* CppAD::cg::ModelCSourceGen< Base >::_atomicsInfo
protected

Maps each atomic function ID to information regarding how the atomic function is used

Definition at line 228 of file model_c_source_gen.hpp.

◆ _baseTypeName

template<class Base>
const std::string CppAD::cg::ModelCSourceGen< Base >::_baseTypeName
protected

the name of the data type used in operations

Definition at line 159 of file model_c_source_gen.hpp.

◆ _cache

template<class Base>
std::ostringstream CppAD::cg::ModelCSourceGen< Base >::_cache
protected

A string cache for code generation

Definition at line 232 of file model_c_source_gen.hpp.

◆ _custom_hess

template<class Base>
Position CppAD::cg::ModelCSourceGen< Base >::_custom_hess
protected

Custom Hessian element indexes

Definition at line 215 of file model_c_source_gen.hpp.

◆ _custom_jac

template<class Base>
Position CppAD::cg::ModelCSourceGen< Base >::_custom_jac
protected

Custom Jacobian element indexes

Definition at line 210 of file model_c_source_gen.hpp.

◆ _fun

template<class Base>
ADFun<CGBase>& CppAD::cg::ModelCSourceGen< Base >::_fun
protected

the original model

Definition at line 142 of file model_c_source_gen.hpp.

◆ _funNoLoops

template<class Base>
LoopFreeModel<Base>* CppAD::cg::ModelCSourceGen< Base >::_funNoLoops
protected

Altered model without the loop equations and with extra dependents for the non-indexed temporary variables used by loops

Definition at line 147 of file model_c_source_gen.hpp.

◆ _hessianByEquation

template<class Base>
bool CppAD::cg::ModelCSourceGen< Base >::_hessianByEquation
protected

generate source-code for the Hessian sparsity pattern for each equation/dependent

Definition at line 189 of file model_c_source_gen.hpp.

◆ _hessSparsities

template<class Base>
std::vector<LocalSparsityInfo> CppAD::cg::ModelCSourceGen< Base >::_hessSparsities
protected

Hessian sparsity from the model for each equation

Definition at line 220 of file model_c_source_gen.hpp.

◆ _loopFor1Groups

template<class Base>
std::map<LoopModel<Base>*, std::map<size_t, std::map<size_t, std::set<size_t> > > > CppAD::cg::ModelCSourceGen< Base >::_loopFor1Groups
protected

Maps the column groups of each loop model to the set of columns (loop->group->{columns->{compressed forward 1 position} })

Definition at line 249 of file model_c_source_gen.hpp.

◆ _loopRev1Groups

template<class Base>
std::map<LoopModel<Base>*, std::map<size_t, std::map<size_t, std::set<size_t> > > > CppAD::cg::ModelCSourceGen< Base >::_loopRev1Groups
protected

Maps the column groups of each loop model to the set of columns (loop->group->{row->{compressed reverse 1 position} })

Definition at line 259 of file model_c_source_gen.hpp.

◆ _loopRev2Groups

template<class Base>
std::map<LoopModel<Base>*, std::map<size_t, std::map<size_t, std::set<size_t> > > > CppAD::cg::ModelCSourceGen< Base >::_loopRev2Groups
protected

Maps the row groups of each loop model to the set of rows (loop->group->{rows->{compressed reverse 2 position} })

Definition at line 269 of file model_c_source_gen.hpp.

◆ _loopTapes

template<class Base>
std::set<LoopModel<Base>*> CppAD::cg::ModelCSourceGen< Base >::_loopTapes
protected

loop models

Definition at line 151 of file model_c_source_gen.hpp.

◆ _maxAssignPerFunc

template<class Base>
size_t CppAD::cg::ModelCSourceGen< Base >::_maxAssignPerFunc
protected

maximum number of assignments per function (~ lines)

Definition at line 236 of file model_c_source_gen.hpp.

◆ _maxOperationsPerAssignment

template<class Base>
size_t CppAD::cg::ModelCSourceGen< Base >::_maxOperationsPerAssignment
protected

the maximum number of operations per variable assignment

Definition at line 240 of file model_c_source_gen.hpp.

◆ _multiThreading

template<class Base>
bool CppAD::cg::ModelCSourceGen< Base >::_multiThreading
protected

Whether or not to enable the generation of multithreaded code for the sparse Jacobian and sparse Hessian if possible and requested by the model library (experimental).

Definition at line 173 of file model_c_source_gen.hpp.

◆ _name

template<class Base>
std::string CppAD::cg::ModelCSourceGen< Base >::_name
protected

the name of the model

Definition at line 155 of file model_c_source_gen.hpp.

◆ _nonLoopFor1Elements

template<class Base>
std::map<size_t, std::set<size_t> > CppAD::cg::ModelCSourceGen< Base >::_nonLoopFor1Elements
protected

Jacobian columns with a contribution from non loop equations [var]{compressed forward 1 position}

Definition at line 254 of file model_c_source_gen.hpp.

◆ _nonLoopRev1Elements

template<class Base>
std::map<size_t, std::set<size_t> > CppAD::cg::ModelCSourceGen< Base >::_nonLoopRev1Elements
protected

Jacobian rows with a contribution from non loop equations [eq]{compressed reverse 1 position}

Definition at line 264 of file model_c_source_gen.hpp.

◆ _nonLoopRev2Elements

template<class Base>
std::map<size_t, std::set<size_t> > CppAD::cg::ModelCSourceGen< Base >::_nonLoopRev2Elements
protected

Hessian rows with a contribution from non loop equations [var]{compressed reverse 2 position}

Definition at line 274 of file model_c_source_gen.hpp.

◆ _parameterPrecision

template<class Base>
size_t CppAD::cg::ModelCSourceGen< Base >::_parameterPrecision
protected

the maximum precision used to print values

Definition at line 163 of file model_c_source_gen.hpp.

◆ _sources

template<class Base>
std::map<std::string, std::string> CppAD::cg::ModelCSourceGen< Base >::_sources
protected

Generated source code (maps file names to content)

Definition at line 282 of file model_c_source_gen.hpp.

◆ _sparseHessianReusesRev2

template<class Base>
bool CppAD::cg::ModelCSourceGen< Base >::_sparseHessianReusesRev2
protected

whether or not the sparse Hessian should reuse the reverse two functions when _sparseHessian is true

Definition at line 205 of file model_c_source_gen.hpp.

◆ _sparseJacobianReusesOne

template<class Base>
bool CppAD::cg::ModelCSourceGen< Base >::_sparseJacobianReusesOne
protected

whether or not the sparse Jacobian should reuse the forward or reverse one functions when _sparseJacobian is true

Definition at line 200 of file model_c_source_gen.hpp.

◆ _x

template<class Base>
std::vector<Base> CppAD::cg::ModelCSourceGen< Base >::_x
protected

Typical values of the independent vector

Definition at line 167 of file model_c_source_gen.hpp.


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