CppADCodeGen
2.3.0
A C++ Algorithmic Differentiation Package with Source Code Generation
|
Classes | |
class | Color |
class | LocalSparsityInfo |
class | Position |
Public Member Functions | |
ModelCSourceGen (ADFun< CppAD::cg::CG< Base > > &fun, const std::string &model) | |
ModelCSourceGen (const ModelCSourceGen &)=delete | |
ModelCSourceGen & | operator= (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) |
template<> | |
std::string | baseTypeName () |
template<> | |
std::string | baseTypeName () |
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< CGBase > | prepareForward0WithLoops (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< CGBase > | prepareSparseJacobianWithLoops (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< CGBase > | 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) |
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 >::Color > | colorByRow (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 |
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 > |
Generates C source code for a model.
Definition at line 158 of file declare_cg.hpp.
|
inline |
Creates a new C language compilation helper for a model
fun | The ADFun with the taped model (should only be deleted after this object) |
model | The model name (must be a valid C function name) |
Definition at line 287 of file model_c_source_gen.hpp.
|
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 51 of file model_c_source_gen_loops_hess.hpp.
|
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.
|
inline |
Specializations
Definition at line 823 of file model_c_source_gen_impl.hpp.
|
inlineprotected |
Determines groups of rows from a sparsity pattern which do not share the same columns
columns | the column indexes of interest (all others are ignored); an empty set means all columns |
sparsity | The sparsity pattern to color |
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.
|
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 542 of file model_c_source_gen_hes.hpp.
|
protectedvirtual |
Determine the sparsity pattern
Definition at line 459 of file model_c_source_gen_jac.hpp.
|
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 515 of file model_c_source_gen_hes.hpp.
|
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.
|
protectedvirtual |
with loops
Generate one function for each dependent variable
Definition at line 22 of file model_c_source_gen_for1.hpp.
|
protectedvirtual |
Jacobian
organize results
Create source for each independent/column
Definition at line 132 of file model_c_source_gen_for1.hpp.
|
protectedvirtual |
Generate one function for each dependent variable
Definition at line 62 of file model_c_source_gen_for1.hpp.
|
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 372 of file model_c_source_gen_hes.hpp.
|
protectedvirtual |
Determine the sparsity pattern p for Hessian of w^T F
Definition at line 78 of file model_c_source_gen_hes.hpp.
|
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 92 of file model_c_source_gen_hes.hpp.
|
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 225 of file model_c_source_gen_hes.hpp.
|
inlineprotectedvirtual |
Generate the source code
Definition at line 22 of file model_c_source_gen_loops_hess_r2.hpp.
|
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 318 of file model_c_source_gen_jac.hpp.
|
protectedvirtual |
determine to which functions we can provide the jacobian row/column directly without needing a temporary array (compressed)
with loops
Definition at line 149 of file model_c_source_gen_jac.hpp.
|
protectedvirtual |
Determine the sparsity pattern
call the appropriate method for source code generation
Definition at line 66 of file model_c_source_gen_jac.hpp.
|
protectedvirtual |
Generate the source code
Definition at line 22 of file model_c_source_gen_loops_jac_fr1.hpp.
|
protectedvirtual |
with loops
Generate one function for each dependent variable
Definition at line 22 of file model_c_source_gen_rev1.hpp.
|
protectedvirtual |
Jacobian
organize results
Create source for each equation/row
Definition at line 137 of file model_c_source_gen_rev1.hpp.
|
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.
|
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.
|
protectedvirtual |
Generate one function for each independent variable
Definition at line 145 of file model_c_source_gen_rev2.hpp.
|
protectedvirtual |
Contains loops
Definition at line 22 of file model_c_source_gen_for0.hpp.
|
inline |
Provides the Automatic Differentiation mode used to generate the source code for the Jacobian
Definition at line 453 of file model_c_source_gen.hpp.
|
inline |
Provides the model name which should be a valid C function name.
Definition at line 334 of file model_c_source_gen.hpp.
Referenced by CppAD::cg::ModelLibraryCSourceGen< Base >::addModel().
|
inlinevirtual |
Provides the maximum precision used to print constant values in the generated source code
Definition at line 370 of file model_c_source_gen.hpp.
|
inline |
Determines whether or not to generate source-code for a function that evaluates the original model.
Definition at line 659 of file model_c_source_gen.hpp.
|
inline |
Determines whether or not to generate source-code for a function that evaluates a dense Hessian.
Definition at line 432 of file model_c_source_gen.hpp.
|
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.
Definition at line 569 of file model_c_source_gen.hpp.
|
inline |
Determines whether or not to generate source-code for a function that evaluates a dense Jacobian.
Definition at line 474 of file model_c_source_gen.hpp.
|
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).
Definition at line 724 of file model_c_source_gen.hpp.
|
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.
Definition at line 761 of file model_c_source_gen.hpp.
|
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).
Definition at line 688 of file model_c_source_gen.hpp.
|
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().
Definition at line 507 of file model_c_source_gen.hpp.
|
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.
Definition at line 601 of file model_c_source_gen.hpp.
|
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.
Definition at line 396 of file model_c_source_gen.hpp.
|
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.
Definition at line 542 of file model_c_source_gen.hpp.
|
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.
Definition at line 633 of file model_c_source_gen.hpp.
|
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.
|
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.
|
protectedvirtual |
Loops Generates a sparse Hessian using loops.
The original model is split into two models:
The Hessian elements for the equations in loops are evaluated as:
handler | The operation graph handler |
indVars | The independent variables |
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
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 557 of file model_c_source_gen_loops_hess.hpp.
|
inlineprotected |
indexed variable contributions
non-indexed variable contributions
Definition at line 404 of file model_c_source_gen_loops_jac.hpp.
|
protectedvirtual |
Generates a sparse Jacobian using loops.
The original model is split into two models:
The jacobian elements for the equations in loops are evaluated as:
handler | The operation graph handler |
indVars | The independent variables |
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.
|
protectedvirtual |
sources | maps 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.
|
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.
|
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).
create | true if the generation of the source for first-order forward mode is enabled, false otherwise. |
Definition at line 706 of file model_c_source_gen.hpp.
|
inline |
Defines whether or not to generate source-code for a function that evaluates the original model.
create | true if source-code for the original model should be created, false otherwise |
Definition at line 670 of file model_c_source_gen.hpp.
|
inline |
Defines whether or not to generate source-code for a function that evaluates a dense Hessian.
create | true if source-code for a dense Hessian should be created, false otherwise |
Definition at line 443 of file model_c_source_gen.hpp.
|
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.
create | true if source-code for a Hessians sparsities should be created, false otherwise |
Definition at line 583 of file model_c_source_gen.hpp.
|
inline |
Defines whether or not to generate source-code for a function that evaluates a dense Jacobian.
create | true if source-code for a dense Jacobian should be created, false otherwise |
Definition at line 485 of file model_c_source_gen.hpp.
|
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).
create | true if the source for first-order reverse mode functions should be generated, false otherwise. |
Definition at line 742 of file model_c_source_gen.hpp.
|
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.
create | true to enable the generation of the source for second-order reverse mode, false otherwise. |
Definition at line 782 of file model_c_source_gen.hpp.
|
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().
create | true if source-code for a sparse Hessian should be created, false otherwise |
Definition at line 529 of file model_c_source_gen.hpp.
|
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.
create | true if source-code for a sparse Jacobian should be created, false otherwise |
Definition at line 619 of file model_c_source_gen.hpp.
|
inline |
Defines the Automatic Differentiation mode used to generate the source code for the Jacobian
mode | the Automatic Differentiation mode |
Definition at line 463 of file model_c_source_gen.hpp.
|
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.
multiThreading | whether or not multithreading can be used for this model |
Definition at line 413 of file model_c_source_gen.hpp.
|
inlinevirtual |
Defines the maximum precision used to print constant values in the generated source code.
p | the maximum number of digits |
Definition at line 380 of file model_c_source_gen.hpp.
|
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.
reuse | true if the functions created for reverse 2 mode should be reused to determine the sparse Hessian, false otherwise |
Definition at line 555 of file model_c_source_gen.hpp.
|
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.
reuse | true if the functions created for forward or reverse 1 mode should be reused to determine the sparse Jacobian, false otherwise |
Definition at line 648 of file model_c_source_gen.hpp.
|
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.
x | The typical values. An empty vector removes the currently defined values. |
Definition at line 347 of file model_c_source_gen.hpp.
|
protected |
The order of the atomic functions
Definition at line 223 of file model_c_source_gen.hpp.
|
protected |
Maps each atomic function ID to information regarding how the atomic function is used
Definition at line 227 of file model_c_source_gen.hpp.
|
protected |
the name of the data type used in operations
Definition at line 158 of file model_c_source_gen.hpp.
|
protected |
A string cache for code generation
Definition at line 231 of file model_c_source_gen.hpp.
|
protected |
Custom Hessian element indexes
Definition at line 214 of file model_c_source_gen.hpp.
|
protected |
Custom Jacobian element indexes
Definition at line 209 of file model_c_source_gen.hpp.
|
protected |
the original model
Definition at line 141 of file model_c_source_gen.hpp.
|
protected |
Altered model without the loop equations and with extra dependents for the non-indexed temporary variables used by loops
Definition at line 146 of file model_c_source_gen.hpp.
|
protected |
generate source-code for the Hessian sparsity pattern for each equation/dependent
Definition at line 188 of file model_c_source_gen.hpp.
|
protected |
Hessian sparsity from the model for each equation
Definition at line 219 of file model_c_source_gen.hpp.
|
protected |
Maps the column groups of each loop model to the set of columns (loop->group->{columns->{compressed forward 1 position} })
Definition at line 244 of file model_c_source_gen.hpp.
|
protected |
Maps the column groups of each loop model to the set of columns (loop->group->{row->{compressed reverse 1 position} })
Definition at line 254 of file model_c_source_gen.hpp.
|
protected |
Maps the row groups of each loop model to the set of rows (loop->group->{rows->{compressed reverse 2 position} })
Definition at line 264 of file model_c_source_gen.hpp.
|
protected |
loop models
Definition at line 150 of file model_c_source_gen.hpp.
|
protected |
maximum number of assignments per function (~ lines)
Definition at line 235 of file model_c_source_gen.hpp.
|
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 172 of file model_c_source_gen.hpp.
|
protected |
the name of the model
Definition at line 154 of file model_c_source_gen.hpp.
|
protected |
Jacobian columns with a contribution from non loop equations [var]{compressed forward 1 position}
Definition at line 249 of file model_c_source_gen.hpp.
|
protected |
Jacobian rows with a contribution from non loop equations [eq]{compressed reverse 1 position}
Definition at line 259 of file model_c_source_gen.hpp.
|
protected |
Hessian rows with a contribution from non loop equations [var]{compressed reverse 2 position}
Definition at line 269 of file model_c_source_gen.hpp.
|
protected |
the maximum precision used to print values
Definition at line 162 of file model_c_source_gen.hpp.
|
protected |
Generated source code (maps file names to content)
Definition at line 277 of file model_c_source_gen.hpp.
|
protected |
whether or not the sparse Hessian should reuse the reverse two functions when _sparseHessian is true
Definition at line 204 of file model_c_source_gen.hpp.
|
protected |
whether or not the sparse Jacobian should reuse the forward or reverse one functions when _sparseJacobian is true
Definition at line 199 of file model_c_source_gen.hpp.
|
protected |
Typical values of the independent vector
Definition at line 166 of file model_c_source_gen.hpp.