CppADCodeGen
2.3.0
A C++ Algorithmic Differentiation Package with Source Code Generation
|
Public Types | |
using | Node = OperationNode< Base > |
using | Arg = Argument< Base > |
Public Member Functions | |
LanguageC (const 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 | setMaxAssigmentsPerFunction (size_t maxAssigmentsPerFunction, std::map< std::string, std::string > *sources) |
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, const std::unique_ptr< LanguageGenerationData< Base > > &info) override |
size_t | getVariableID (const Node &node) const |
unsigned | printAssignment (Node &node) |
unsigned | printAssignment (Node &nodeName, const Arg &nodeRhs) |
unsigned | printAssignment (Node &nodeName, Node &nodeRhs) |
virtual void | printAssignmentStart (Node &op) |
virtual void | printAssignmentStart (Node &node, const std::string &varName, bool isDep) |
virtual void | printAssignmentEnd (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) 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 | printIndependentVariableName (Node &op) |
virtual unsigned | print (const Arg &arg) |
virtual unsigned | printExpression (Node &op) |
virtual unsigned | printExpressionNoVarCheck (Node &node) |
virtual unsigned | printAssignOp (Node &node) |
virtual void | printUnaryFunction (Node &op) |
virtual void | printPowFunction (Node &op) |
virtual void | printSignFunction (Node &op) |
virtual unsigned | printOperationAlias (Node &op) |
virtual void | printOperationAdd (Node &op) |
virtual void | printOperationMinus (Node &op) |
bool | encloseInParenthesesDiv (const Node *node) const |
virtual void | printOperationDiv (Node &op) |
bool | encloseInParenthesesMul (const Node *node) const |
virtual void | printOperationMul (Node &op) |
virtual void | printOperationUnaryMinus (Node &op) |
virtual void | printPrintOperation (const Node &node) |
virtual void | printConditionalAssignment (Node &node) |
bool | isSameArgument (const Arg &newArg, const Arg *oldArg) |
virtual void | printArrayCreationOp (Node &op) |
virtual void | printSparseArrayCreationOp (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 | printArrayElementOp (Node &op) |
virtual void | printAtomicForwardOp (Node &atomicFor) |
virtual void | printAtomicReverseOp (Node &atomicRev) |
virtual unsigned | printDependentMultiAssign (Node &node) |
virtual void | printLoopStart (Node &node) |
virtual void | printLoopEnd (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 | printLoopIndexedDep (Node &node) |
virtual void | printLoopIndexedIndep (Node &node) |
virtual void | printLoopIndexedTmp (Node &node) |
virtual void | printTmpVar (Node &node) |
virtual void | printIndexAssign (Node &node) |
virtual void | printIndexCondExprOp (Node &node) |
virtual void | printStartIf (Node &node) |
virtual void | printElseIf (Node &node) |
virtual void | printElse (Node &node) |
virtual void | printEndIf (Node &node) |
virtual void | printCondResult (Node &node) |
virtual void | printUserCustom (Node &node) |
bool | isDependent (const Node &arg) const |
virtual void | printParameter (const Base &value) |
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 |
LanguageGenerationData< Base > * | _info |
std::string | _indentation |
std::string | _inArgName |
std::string | _outArgName |
std::string | _atomicArgName |
std::ostringstream | _code |
VariableNameGenerator< Base > * | _nameGen |
std::ostringstream | _ss |
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 |
std::string | _localFunctionArguments |
size_t | _maxAssigmentsPerFunction |
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 124 of file declare_cg.hpp.
|
inline |
Creates a C language source code generator
varTypeName | variable data type (e.g. double) |
spaces | number of spaces for indentations |
Definition at line 125 of file language_c.hpp.
|
inlineoverrideprotectedvirtual |
Whether or not a new variable is created as a result of this operation
op | Operation |
Implements CppAD::cg::Language< Base >.
Definition at line 1034 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 1087 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 614 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 260 of file language_c.hpp.
|
inlinevirtual |
Provides the maximum precision used to print constant values in the generated source code
Definition at line 209 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 124 of file language_c_arrays.hpp.
|
inlineprotectedvirtual |
the values of ty are now changed
Definition at line 1702 of file language_c.hpp.
|
inlineprotectedvirtual |
the values of px are now changed
Definition at line 1744 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 1946 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 1926 of file language_c.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 489 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 57 of file language_c_loops.hpp.
|
inlinestatic |
1D
2D
Definition at line 55 of file language_c_index_patterns.hpp.
Referenced by CppAD::cg::LanguageC< Base >::printFunctionDeclaration().
|
inlineprotectedvirtual |
the first argument is the condition, following arguments are just extra dependencies that must be defined outside the if
Definition at line 1910 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 1172 of file language_c.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 219 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.