- 3.0.1 core module.
ct::core::DerivativesCppadCG< IN_DIM, OUT_DIM > Class Template Reference

Jacobian using Auto-Diff Codegeneration. More...

#include <DerivativesCppadCG.h>

Public Types

typedef ADCGValueType CG_VALUE_TYPE
 autodiff scalar type More...
 
typedef Eigen::Matrix< CG_SCALAR, IN_DIM, 1 > IN_TYPE_CG
 function input vector type More...
 
typedef Eigen::Matrix< CG_SCALAR, OUT_DIM, 1 > OUT_TYPE_CG
 function output vector type More...
 
typedef Eigen::Matrix< bool, IN_DIM, OUT_DIM > Sparsity
 Sparsity pattern type. More...
 
typedef Eigen::Matrix< bool, IN_DIM, IN_DIM > HessianSparsity
 
typedef std::function< OUT_TYPE_CG(const IN_TYPE_CG &)> FUN_TYPE_CG
 function type More...
 

Public Member Functions

 DerivativesCppadCG (FUN_TYPE_CG &f, int inputDim=IN_DIM, int outputDim=OUT_DIM)
 Contructs the derivatives for codegeneration using a FUN_TYPE_CG function. More...
 
 DerivativesCppadCG (const DerivativesCppadCG &arg)
 copy constructor More...
 
virtual ~DerivativesCppadCG ()=default
 destructor More...
 
DerivativesCppadCGclone () const
 deep cloning of Jacobian More...
 
void generateJacobianSource (const std::string &derivativeName, const std::string &outputDir=ct::core::CODEGEN_OUTPUT_DIR, const std::string &templateDir=ct::core::CODEGEN_TEMPLATE_DIR, const std::string &ns1="core", const std::string &ns2="generated", const Sparsity &sparsity=Sparsity::Ones(), bool useReverse=true, bool ignoreZero=true)
 Generates code for computing the Jacobian and writes it to file. More...
 
void generateForwardZeroSource (const std::string &forwardZeroName, const std::string &outputDir=ct::core::CODEGEN_OUTPUT_DIR, const std::string &templateDir=ct::core::CODEGEN_TEMPLATE_DIR, const std::string &ns1="core", const std::string &ns2="generated", bool ignoreZero=true)
 Generates code for computing the zero-order derivative and writes it to file. More...
 
void generateHessianSource (const std::string &derivativeName, const std::string &outputDir=ct::core::CODEGEN_OUTPUT_DIR, const std::string &templateDir=ct::core::CODEGEN_TEMPLATE_DIR, const std::string &ns1="core", const std::string &ns2="generated", const HessianSparsity &sparsity=HessianSparsity::Ones(), bool useReverse=true, bool ignoreZero=true)
 Generates code for computing the Hessian and writes it to file. More...
 

Public Attributes

EIGEN_MAKE_ALIGNED_OPERATOR_NEW typedef ADCGScalar CG_SCALAR
 CG_SCALAR type. More...
 

Detailed Description

template<int IN_DIM, int OUT_DIM>
class ct::core::DerivativesCppadCG< IN_DIM, OUT_DIM >

Jacobian using Auto-Diff Codegeneration.

Uses Auto-Diff code generation to compute the Jacobian $ J(x_s) = \frac{df}{dx} |_{x=x_s} $ of a regular vector-valued mathematical function $ y = f(x) $ .

x has IN_DIM dimension and y has OUT_DIM dimension. Thus, they can be scalar functions (IN_DIM = 1, OUT_DIM = 1), fixed or variable size (IN_DIM = -1, OUT_DIM = -1) functions.

Note
In fact, this class is called Jacobian but computes also zero order derivatives
Template Parameters
IN_DIMInput dimensionality of the function (use Eigen::Dynamic (-1) for dynamic size)
OUT_DIMOutput dimensionailty of the function (use Eigen::Dynamic (-1) for dynamic size)

Member Typedef Documentation

template<int IN_DIM, int OUT_DIM>
typedef ADCGValueType ct::core::DerivativesCppadCG< IN_DIM, OUT_DIM >::CG_VALUE_TYPE

autodiff scalar type

template<int IN_DIM, int OUT_DIM>
typedef Eigen::Matrix<CG_SCALAR, IN_DIM, 1> ct::core::DerivativesCppadCG< IN_DIM, OUT_DIM >::IN_TYPE_CG

function input vector type

template<int IN_DIM, int OUT_DIM>
typedef Eigen::Matrix<CG_SCALAR, OUT_DIM, 1> ct::core::DerivativesCppadCG< IN_DIM, OUT_DIM >::OUT_TYPE_CG

function output vector type

template<int IN_DIM, int OUT_DIM>
typedef Eigen::Matrix<bool, IN_DIM, OUT_DIM> ct::core::DerivativesCppadCG< IN_DIM, OUT_DIM >::Sparsity

Sparsity pattern type.

template<int IN_DIM, int OUT_DIM>
typedef Eigen::Matrix<bool, IN_DIM, IN_DIM> ct::core::DerivativesCppadCG< IN_DIM, OUT_DIM >::HessianSparsity
template<int IN_DIM, int OUT_DIM>
typedef std::function<OUT_TYPE_CG(const IN_TYPE_CG&)> ct::core::DerivativesCppadCG< IN_DIM, OUT_DIM >::FUN_TYPE_CG

function type

Constructor & Destructor Documentation

template<int IN_DIM, int OUT_DIM>
ct::core::DerivativesCppadCG< IN_DIM, OUT_DIM >::DerivativesCppadCG ( FUN_TYPE_CG f,
int  inputDim = IN_DIM,
int  outputDim = OUT_DIM 
)
inline

Contructs the derivatives for codegeneration using a FUN_TYPE_CG function.

Warning
If IN_DIM and/our OUT_DIM are set to dynamic (-1), then the actual dimensions of x and y have to be passed here.
Parameters
fThe function to be autodiffed
[in]inputDiminputDim input dimension, must be specified if template parameter IN_DIM is -1 (dynamic)
[in]outputDimoutputDim output dimension, must be specified if template parameter IN_DIM is -1 (dynamic)
template<int IN_DIM, int OUT_DIM>
ct::core::DerivativesCppadCG< IN_DIM, OUT_DIM >::DerivativesCppadCG ( const DerivativesCppadCG< IN_DIM, OUT_DIM > &  arg)
inline
template<int IN_DIM, int OUT_DIM>
virtual ct::core::DerivativesCppadCG< IN_DIM, OUT_DIM >::~DerivativesCppadCG ( )
virtualdefault

Member Function Documentation

template<int IN_DIM, int OUT_DIM>
DerivativesCppadCG* ct::core::DerivativesCppadCG< IN_DIM, OUT_DIM >::clone ( ) const
inline

deep cloning of Jacobian

template<int IN_DIM, int OUT_DIM>
void ct::core::DerivativesCppadCG< IN_DIM, OUT_DIM >::generateJacobianSource ( const std::string &  derivativeName,
const std::string &  outputDir = ct::core::CODEGEN_OUTPUT_DIR,
const std::string &  templateDir = ct::core::CODEGEN_TEMPLATE_DIR,
const std::string &  ns1 = "core",
const std::string &  ns2 = "generated",
const Sparsity sparsity = Sparsity::Ones(),
bool  useReverse = true,
bool  ignoreZero = true 
)
inline

Generates code for computing the Jacobian and writes it to file.

This function is optional and can be used if you want to generate code for a Jacobian and write it to file. This can be useful to pre-compile Jacobians rather than compiling them at runtime using compileJIT(). This function can make use of a template file in which the keyword "AUTOGENERATED_CODE_PLACEHOLDER" is replaced with the autogenerated code.

Parameters
derivativeNamename of the resulting Jacobian class
outputDiroutput directory
templateDirdirectory in which template file is located
ns1first namespace layer of the Jacobian class
ns2second namespace layer of the Jacobian class
sparsitysparsity pattern to generate sparse Jacobian
useReverseif true, uses Auto-Diff reverse mode, otherwise uses forward mode
ignoreZerodo not assign 0 to sparse entries or zero entries

References ct::core::internal::CGHelpers::generateJacobianSource(), and ct::core::internal::SparsityPattern::initPattern().

template<int IN_DIM, int OUT_DIM>
void ct::core::DerivativesCppadCG< IN_DIM, OUT_DIM >::generateForwardZeroSource ( const std::string &  forwardZeroName,
const std::string &  outputDir = ct::core::CODEGEN_OUTPUT_DIR,
const std::string &  templateDir = ct::core::CODEGEN_TEMPLATE_DIR,
const std::string &  ns1 = "core",
const std::string &  ns2 = "generated",
bool  ignoreZero = true 
)
inline

Generates code for computing the zero-order derivative and writes it to file.

This function is optional and can be used if you want to generate code for a zero-order derivative, i.e. the function itself and write it to file. While it seems weird at first to regenerate code from existing code, this can help to speed up complex computations. Generating source code can be useful to pre-compile the zero order dynamics rather than compiling them at runtime using compileJIT(). This function can make use of a template file in which the keyword "AUTOGENERATED_CODE_PLACEHOLDER" is replaced with the autogenerated code.

Parameters
forwardZeroNamename of the resulting class
outputDiroutput directory
templateDirdirectory in which template file is located
ns1first namespace layer of the class
ns2second namespace layer of the class
ignoreZerodo not assign 0 to sparse entries or zero entries

References ct::core::internal::CGHelpers::generateForwardZeroSource().

template<int IN_DIM, int OUT_DIM>
void ct::core::DerivativesCppadCG< IN_DIM, OUT_DIM >::generateHessianSource ( const std::string &  derivativeName,
const std::string &  outputDir = ct::core::CODEGEN_OUTPUT_DIR,
const std::string &  templateDir = ct::core::CODEGEN_TEMPLATE_DIR,
const std::string &  ns1 = "core",
const std::string &  ns2 = "generated",
const HessianSparsity sparsity = HessianSparsity::Ones(),
bool  useReverse = true,
bool  ignoreZero = true 
)
inline

Generates code for computing the Hessian and writes it to file.

This function is optional and can be used if you want to generate code for a hessian, i.e. the function itself and write it to file. While it seems weird at first to regenerate code from existing code, this can help to speed up complex computations. Generating source code can be useful to pre-compile the hessian dynamics rather than compiling them at runtime using compileJIT(). This function can make use of a template file in which the keyword "AUTOGENERATED_CODE_PLACEHOLDER" is replaced with the autogenerated code.

Parameters
derivativeNamename of the resulting class
outputDiroutput directory
templateDirdirectory in which template file is located
ns1first namespace layer of the class
ns2second namespace layer of the class
sparsitysparsity pattern to generate sparse Jacobian
useReverseif true, uses Auto-Diff reverse mode, otherwise uses forward mode
ignoreZerodo not assign 0 to sparse entries or zero entries

References ct::core::internal::CGHelpers::generateHessianSource(), ct::core::internal::SparsityPattern::initPattern(), ct::core::internal::CGHelpers::parseFile(), ct::core::internal::CGHelpers::replaceAll(), ct::core::internal::CGHelpers::replaceOnce(), ct::core::internal::CGHelpers::writeFile(), x, and y.

Member Data Documentation

template<int IN_DIM, int OUT_DIM>
EIGEN_MAKE_ALIGNED_OPERATOR_NEW typedef ADCGScalar ct::core::DerivativesCppadCG< IN_DIM, OUT_DIM >::CG_SCALAR

CG_SCALAR type.


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