CppADCodeGen
HEAD
A C++ Algorithmic Differentiation Package with Source Code Generation
|
Public Types | |
using | Node = OperationNode< Base > |
using | Arg = Argument< Base > |
Public Member Functions | |
LanguageC (std::string varTypeName, size_t spaces=3) | |
const std::string & | getArgumentIn () const |
void | setArgumentIn (const std::string &inArgName) |
const std::string & | getArgumentOut () const |
void | setArgumentOut (const std::string &outArgName) |
const std::string & | getArgumentAtomic () const |
void | setArgumentAtomic (const std::string &atomicArgName) |
const std::string & | getDependentAssignOperation () const |
void | setDependentAssignOperation (const std::string &depAssignOperation) |
bool | isIgnoreZeroDepAssign () const |
void | setIgnoreZeroDepAssign (bool ignore) |
virtual void | setGenerateFunction (const std::string &functionName) |
virtual void | setFunctionIndexArgument (const Node &funcArgIndex) |
virtual void | setFunctionIndexArguments (const std::vector< const Node *> &funcArgIndexes) |
virtual const std::vector< const Node * > & | getFunctionIndexArguments () const |
virtual size_t | getParameterPrecision () const |
virtual void | setParameterPrecision (size_t p) |
virtual void | setMaxAssignmentsPerFunction (size_t maxAssignmentsPerFunction, std::map< std::string, std::string > *sources) |
size_t | getMaxOperationsPerAssignment () const |
void | setMaxOperationsPerAssignment (size_t maxOperationsPerAssignment) |
std::string | generateTemporaryVariableDeclaration (bool isWrapperFunction, bool zeroArrayDependents, const std::vector< int > &atomicMaxForward, const std::vector< int > &atomicMaxReverse) |
virtual std::string | generateTemporaryVariableDeclaration (bool isWrapperFunction=false, bool zeroArrayDependents=false, int maxForwardOrder=-1, int maxReverseOrder=-1) |
void | generateArrayContainersDeclaration (std::ostringstream &ss, const std::vector< int > &atomicMaxForward, const std::vector< int > &atomicMaxReverse) |
virtual void | generateArrayContainersDeclaration (std::ostringstream &ss, int maxForwardOrder=-1, int maxReverseOrder=-1) |
virtual std::string | generateDependentVariableDeclaration () |
virtual std::string | generateIndependentVariableDeclaration () |
std::string | generateArgumentAtomicDcl () const |
virtual std::string | generateFunctionArgumentsDcl () const |
virtual std::vector< std::string > | generateFunctionArgumentsDcl2 () const |
virtual std::string | generateDefaultFunctionArgumentsDcl () const |
virtual std::vector< std::string > | generateDefaultFunctionArgumentsDcl2 () const |
virtual std::string | generateFunctionIndexArgumentsDcl () const |
virtual std::vector< std::string > | generateFunctionIndexArgumentsDcl2 () const |
virtual std::string | generateDefaultFunctionArguments () const |
virtual std::string | generateFunctionIndexArguments () const |
void | createIndexDeclaration () |
Static Public Member Functions | |
static void | printFunctionDeclaration (std::ostringstream &out, const std::string &returnType, const std::string &functionName, const std::vector< std::string > &arguments, const std::vector< std::string > &arguments2={}) |
static void | printIndexCondExpr (std::ostringstream &out, const std::vector< size_t > &info, const std::string &index) |
static void | printStaticIndexArray (std::ostringstream &os, const std::string &name, const std::vector< size_t > &values) |
static void | printStaticIndexMatrix (std::ostringstream &os, const std::string &name, const std::map< size_t, std::map< size_t, size_t > > &values) |
static void | generateNames4RandomIndexPatterns (const std::set< RandomIndexPattern *> &randomPatterns) |
static void | printRandomIndexPatternDeclaration (std::ostringstream &os, const std::string &identation, const std::set< RandomIndexPattern *> &randomPatterns) |
static std::string | indexPattern2String (const IndexPattern &ip, const Node &index) |
static std::string | indexPattern2String (const IndexPattern &ip, const std::string &index) |
static std::string | indexPattern2String (const IndexPattern &ip, const std::vector< const Node *> &indexes) |
static std::string | indexPattern2String (const IndexPattern &ip, const std::vector< const std::string *> &indexes) |
static std::string | linearIndexPattern2String (const LinearIndexPattern &lip, const Node &index) |
static std::string | linearIndexPattern2String (const LinearIndexPattern &lip, const std::string &index) |
static bool | isOffsetBy (const IndexPattern *ip, const IndexPattern *refIp, long offset) |
static bool | isOffsetBy (const LinearIndexPattern *lIp, const LinearIndexPattern *refLIp, long offset) |
static bool | isOffsetBy (const LinearIndexPattern &lIp, const LinearIndexPattern &refLIp, long offset) |
static bool | isOffsetBy (const SectionedIndexPattern *sIp, const SectionedIndexPattern *refSecp, long offset) |
static bool | isOffsetBy (const SectionedIndexPattern &lIp, const SectionedIndexPattern &refSecp, long offset) |
static Plane2DIndexPattern * | encapsulateIndexPattern (const LinearIndexPattern &refLIp, size_t starti) |
static Plane2DIndexPattern * | encapsulateIndexPattern (const SectionedIndexPattern &refSecp, size_t starti) |
Static Public Attributes | |
static const std::string | U_INDEX_TYPE = "unsigned long" |
static const std::string | ATOMICFUN_STRUCT_DEFINITION |
Protected Member Functions | |
void | generateSourceCode (std::ostream &out, std::unique_ptr< LanguageGenerationData< Base > > info) override |
size_t | getVariableID (const Node &node) const |
unsigned | printAssignment (Node &node) |
unsigned | pushAssignment (Node &nodeName, const Arg &nodeRhs) |
unsigned | pushAssignment (Node &nodeName, Node &nodeRhs) |
virtual void | pushAssignmentStart (Node &op) |
virtual void | pushAssignmentStart (Node &node, const std::string &varName, bool isDep) |
virtual void | pushAssignmentEnd (Node &op) |
virtual std::string | argumentDeclaration (const FuncArgument &funcArg) const |
virtual void | saveLocalFunction (std::vector< std::string > &localFuncNames, bool zeroDependentArray) |
bool | createsNewVariable (const Node &var, size_t totalUseCount, size_t opCount) const override |
virtual bool | requiresVariableName (const Node &var) const |
virtual bool | directlyAssignsVariable (const Node &var) const |
bool | requiresVariableArgument (enum CGOpCode op, size_t argIndex) const override |
const std::string & | createVariableName (Node &var) |
bool | requiresVariableDependencies () const override |
virtual void | pushIndependentVariableName (Node &op) |
virtual unsigned | push (const Arg &arg) |
virtual unsigned | pushExpression (Node &op) |
virtual unsigned | pushExpressionNoVarCheck2 (Node &node) |
virtual unsigned | pushExpressionNoVarCheck (Node &node) |
virtual unsigned | pushAssignOp (Node &node) |
virtual void | pushUnaryFunction (Node &op) |
virtual void | pushPowFunction (Node &op) |
virtual void | pushSignFunction (Node &op) |
virtual unsigned | pushOperationAlias (Node &op) |
virtual void | pushOperationAdd (Node &op) |
virtual void | pushOperationMinus (Node &op) |
bool | encloseInParenthesesDiv (const Node *node) const |
virtual void | pushOperationDiv (Node &op) |
bool | encloseInParenthesesMul (const Node *node) const |
virtual void | pushOperationMul (Node &op) |
virtual void | pushOperationUnaryMinus (Node &op) |
virtual void | pushPrintOperation (const Node &node) |
virtual void | pushConditionalAssignment (Node &node) |
bool | isSameArgument (const Arg &newArg, const Arg *oldArg) |
virtual void | pushArrayCreationOp (Node &op) |
virtual void | pushSparseArrayCreationOp (Node &op) |
void | printArrayStructInit (const std::string &dataArrayName, size_t pos, const std::vector< Node *> &arrays, size_t k) |
void | printArrayStructInit (const std::string &dataArrayName, Node &array) |
void | markArrayChanged (Node &ty) |
size_t | printArrayCreationUsingLoop (size_t startPos, Node &array, size_t startj, std::vector< const Arg *> &tmpArrayValues) |
std::string | getTempArrayName (const Node &op) |
virtual void | pushArrayElementOp (Node &op) |
virtual void | pushAtomicForwardOp (Node &atomicFor) |
virtual void | pushAtomicReverseOp (Node &atomicRev) |
virtual unsigned | pushDependentMultiAssign (Node &node) |
virtual void | pushLoopStart (Node &node) |
virtual void | pushLoopEnd (Node &node) |
virtual size_t | printLoopIndexDeps (const std::vector< Node *> &variableOrder, size_t pos) |
virtual size_t | printLoopIndexedDepsUsingLoop (const std::vector< Node *> &variableOrder, size_t starti) |
virtual void | pushLoopIndexedDep (Node &node) |
virtual void | pushLoopIndexedIndep (Node &node) |
virtual void | pushLoopIndexedTmp (Node &node) |
virtual void | pushTmpVar (Node &node) |
virtual void | pushIndexAssign (Node &node) |
virtual void | pushIndexCondExprOp (Node &node) |
virtual void | pushStartIf (Node &node) |
virtual void | pushElseIf (Node &node) |
virtual void | pushElse (Node &node) |
virtual void | pushEndIf (Node &node) |
virtual void | pushCondResult (Node &node) |
virtual void | pushUserCustom (Node &node) |
bool | isDependent (const Node &arg) const |
virtual void | printParameter (const Base &value) |
virtual void | pushParameter (const Base &value) |
template<class Output > | |
void | writeParameter (const Base &value, Output &output) |
virtual const std::string & | getComparison (enum CGOpCode op) const |
const std::string & | getPrintfBaseFormat () |
template<> | |
const std::string & | getPrintfBaseFormat () |
template<> | |
const std::string & | getPrintfBaseFormat () |
Static Protected Member Functions | |
static bool | isFunction (enum CGOpCode op) |
static bool | isUnaryFunction (enum CGOpCode op) |
static bool | isCondAssign (enum CGOpCode op) |
Protected Attributes | |
const std::string | _baseTypeName |
const std::string | _spaces |
std::unique_ptr< LanguageGenerationData< Base > > | _info |
std::string | _indentation |
std::string | _inArgName |
std::string | _outArgName |
std::string | _atomicArgName |
std::ostringstream | _code |
VariableNameGenerator< Base > * | _nameGen |
std::ostringstream | _ss |
LangStreamStack< Base > | _streamStack |
size_t | _independentSize |
size_t | _minTemporaryVarID |
std::map< size_t, size_t > | _dependentIDs |
const ArrayView< CG< Base > > * | _dependent |
std::map< size_t, Node * > | _temporary |
std::string | _depAssignOperation |
bool | _ignoreZeroDepAssign |
std::string | _functionName |
size_t | _maxAssignmentsPerFunction |
size_t | _maxOperationsPerAssignment |
std::map< std::string, std::string > * | _sources |
std::vector< const Arg * > | _tmpArrayValues |
std::vector< const Arg * > | _tmpSparseArrayValues |
std::map< std::string, AtomicFuncArray > | _atomicFuncArrays |
std::vector< const Node * > | _funcArgIndexes |
std::vector< const LoopStartOperationNode< Base > * > | _currentLoops |
size_t | _parameterPrecision |
Generates code for the C language
Definition at line 126 of file declare_cg.hpp.
|
inlineexplicit |
Creates a C language source code generator
varTypeName | variable data type (e.g. double) |
spaces | number of spaces for indentations |
Definition at line 127 of file language_c.hpp.
|
inlineoverrideprotectedvirtual |
Whether or not a new variable is created as a result of this operation
op | Operation |
totalUseCount | the number of times this node has been used as an argument in other operations |
Implements CppAD::cg::Language< Base >.
Definition at line 1091 of file language_c.hpp.
|
inlineprotectedvirtual |
Whether or not this operation assign its expression to a variable by itself.
var | the operation node |
Definition at line 1146 of file language_c.hpp.
|
inlineoverrideprotectedvirtual |
generate index array names (might be used for variable names)
generate variable names
function variable declaration
Determine the dependent variables that result from the same operations
non-constant variables
Source code generation magic!
Create the wrapper function which calls the other functions
encapsulate the code in a function
Implements CppAD::cg::Language< Base >.
Definition at line 663 of file language_c.hpp.
|
inlinevirtual |
Declares temporary variables used by a function.
isWrapperFunction | true if the declarations are for a wrapper function which calls other functions where the actual work is performed |
zeroArrayDependents | whether or not the dependent variables should be set to zero before executing the operation graph |
maxForwardOrder | the maximum order of forward mode calls to atomic functions |
maxReverseOrder | the maximum order of reverse mode calls to atomic functions |
temporary variables
temporary array variables
temporary sparse array variables
Definition at line 308 of file language_c.hpp.
|
inline |
The maximum number of operations per variable assignment.
Definition at line 263 of file language_c.hpp.
|
inlinevirtual |
Provides the maximum precision used to print constant values in the generated source code
Definition at line 227 of file language_c.hpp.
|
inline |
Whether or not source code to set dependent variables to zero will be generated. It may be used not to set the dependent variables to zero when it is known they are already set to zero before the source code generation.
Definition at line 189 of file language_c.hpp.
|
inlineprotected |
from independents array
from independents array in a loop
from temporary variable array
constant value?
print the loop
update values in the global temporary array
Definition at line 125 of file language_c_arrays.hpp.
|
inlinestatic |
Prints a function declaration where each argument is in a different line.
out | the stream where the declaration is printed |
returnType | the function return type |
functionName | the function name |
arguments | function arguments |
arguments2 | additional function arguments |
Definition at line 538 of file language_c.hpp.
Referenced by CppAD::cg::ModelCSourceGen< Base >::generateGlobalDirectionalFunctionSource(), CppAD::cg::ModelCSourceGen< Base >::generateSparseForwardOneSourcesNoAtomics(), CppAD::cg::ModelCSourceGen< Base >::generateSparseJacobianForRevMultiThreadSource(), CppAD::cg::ModelCSourceGen< Base >::generateSparseReverseOneSourcesNoAtomics(), and CppAD::cg::ModelCSourceGen< Base >::generateSparseReverseTwoSourcesNoAtomics().
|
inlineprotectedvirtual |
Check that the assigned value is from an array
check that the type of index pattern can be used within a loop
Find last compatible variable in variableOrder
Create the dependent variable name with the new index pattern
print the loop
Definition at line 58 of file language_c_loops.hpp.
|
inlinestatic |
1D
2D
Definition at line 56 of file language_c_index_patterns.hpp.
Referenced by CppAD::cg::LanguageC< Base >::printFunctionDeclaration().
|
inlineprotectedvirtual |
the values of ty are now changed
Definition at line 1791 of file language_c.hpp.
|
inlineprotectedvirtual |
the values of px are now changed
Definition at line 1833 of file language_c.hpp.
|
inlineprotectedvirtual |
the first argument is the if start node, the following arguments are assignments in the previous if branch
Definition at line 2035 of file language_c.hpp.
|
inlineprotectedvirtual |
the first argument is the condition, the second argument is the if start node, the following arguments are assignments in the previous if branch
Definition at line 2015 of file language_c.hpp.
|
inlineprotectedvirtual |
the first argument is the condition, following arguments are just extra dependencies that must be defined outside the if
Definition at line 1999 of file language_c.hpp.
|
inlineoverrideprotectedvirtual |
Whether or not this language can use information regarding the dependencies between different equations/variables.
Implements CppAD::cg::Language< Base >.
Definition at line 1231 of file language_c.hpp.
|
inline |
Whether or not to generate expressions to set dependent variables to zero. It may be used not to set the dependent variables to zero when it is known they are already set to zero before the source code generation.
ignore | true if source code to explicitly set dependent variables to zero will NOT be created. |
Definition at line 200 of file language_c.hpp.
|
inlinevirtual |
Defines 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.
maxAssignmentsPerFunction | the maximum number of assignments per file/function |
sources | A map where the file names are associated with their contents. |
Definition at line 252 of file language_c.hpp.
Referenced by CppAD::cg::ModelCSourceGen< Base >::generateSparseForwardOneSourcesNoAtomics(), CppAD::cg::ModelCSourceGen< Base >::generateSparseForwardOneSourcesWithAtomics(), CppAD::cg::ModelCSourceGen< Base >::generateSparseHessianSourceDirectly(), CppAD::cg::ModelCSourceGen< Base >::generateSparseReverseOneSourcesNoAtomics(), CppAD::cg::ModelCSourceGen< Base >::generateSparseReverseOneSourcesWithAtomics(), CppAD::cg::ModelCSourceGen< Base >::generateSparseReverseTwoSources(), CppAD::cg::ModelCSourceGen< Base >::generateSparseReverseTwoSourcesNoAtomics(), CppAD::cg::ModelCSourceGen< Base >::generateZeroSource(), and CppAD::cg::ModelCSourceGen< Base >::prepareSparseReverseOneWithLoops().
|
inline |
Defines the maximum number of operations per variable assignment. Defining a limit can reduce the memory required for compilation of the source code.
maxOperationsPerAssignment | The maximum number of operations per variable assignment. |
Definition at line 273 of file language_c.hpp.
Referenced by CppAD::cg::ModelCSourceGen< Base >::generateSparseForwardOneSourcesNoAtomics(), CppAD::cg::ModelCSourceGen< Base >::generateSparseForwardOneSourcesWithAtomics(), CppAD::cg::ModelCSourceGen< Base >::generateSparseHessianSourceDirectly(), CppAD::cg::ModelCSourceGen< Base >::generateSparseReverseOneSourcesNoAtomics(), CppAD::cg::ModelCSourceGen< Base >::generateSparseReverseOneSourcesWithAtomics(), CppAD::cg::ModelCSourceGen< Base >::generateSparseReverseTwoSources(), CppAD::cg::ModelCSourceGen< Base >::generateSparseReverseTwoSourcesNoAtomics(), and CppAD::cg::ModelCSourceGen< Base >::generateZeroSource().
|
inlinevirtual |
Defines the maximum precision used to print constant values in the generated source code
p | the maximum number of digits |
Definition at line 237 of file language_c.hpp.
Referenced by CppAD::cg::ModelCSourceGen< Base >::generateSparseForwardOneSourcesNoAtomics(), CppAD::cg::ModelCSourceGen< Base >::generateSparseForwardOneSourcesWithAtomics(), CppAD::cg::ModelCSourceGen< Base >::generateSparseHessianSourceDirectly(), CppAD::cg::ModelCSourceGen< Base >::generateSparseReverseOneSourcesNoAtomics(), CppAD::cg::ModelCSourceGen< Base >::generateSparseReverseOneSourcesWithAtomics(), CppAD::cg::ModelCSourceGen< Base >::generateSparseReverseTwoSources(), CppAD::cg::ModelCSourceGen< Base >::generateSparseReverseTwoSourcesNoAtomics(), CppAD::cg::ModelCSourceGen< Base >::generateZeroSource(), and CppAD::cg::ModelCSourceGen< Base >::prepareSparseReverseOneWithLoops().
|
static |
Definition at line 40 of file language_c.hpp.