40#include "../../expressions/lhsExpressionInterface.hpp"
41#include "../../traits/realTraits.hpp"
42#include "../../traits/tapeTraits.hpp"
43#include "../algorithms.hpp"
44#include "../data/hessian.hpp"
45#include "../data/jacobian.hpp"
102 template<
typename T_Type,
typename T_Impl>
110 using Real =
typename Type::Real;
121 using Tape =
typename Type::Tape;
266 tape.registerInput(value);
282 tape.registerOutput(value);
323 for (
size_t j = 0; j <
inputValues.size(); j += 1) {
327 tape.evaluateForward();
372 for (
size_t j = 0; j <
inputValues.size(); j += 1) {
378 tape.clearAdjoints();
444 template<
typename Jac>
449 if (Algo::EvaluationType::Forward == evalType) {
451 }
else if (Algo::EvaluationType::Reverse == evalType) {
454 CODI_EXCEPTION(
"Evaluation type not implemented.");
475 template<
typename Jac = DummyJacobian>
495 template<
typename Jac = DummyJacobian>
500 cast().evalHessian(hes, jac);
507 return static_cast<Impl&
>(*this);
522 tape.clearAdjoints();
535 template<
typename T_Type>
539 CODI_STATIC_ASSERT(
false && std::is_void<T_Type>::value,
"Tape helper not implemented for this tape.");
542 using Real =
typename Type::Real;
550 template<typename Jac = DummyJacobian>
560 template<
typename T_Type>
565 using Real =
typename Type::Real;
574 "No primal evaluation for Jacobian tapes. "
575 "Please use codi::RealReversePrimal or codi::RealReversePrimalIndex types for this kind of functionality.");
579 template<
typename Jac = DummyJacobian>
584 "No direct Hessian evaluation for Jacobian tapes. "
585 "Please use codi::RealReversePrimal or codi::RealReversePrimalIndex types for this kind of functionality "
586 "or the EvaluationHelper class.");
595 template<
typename T_Type>
600 using Real =
typename Type::Real;
606 for (
size_t j = 0; j < this->
inputValues.size(); j += 1) {
610 this->
tape.evaluatePrimal();
613 for (
size_t i = 0; i < this->
outputValues.size(); i += 1) {
620 template<
typename Jac = DummyJacobian>
623 typename Algo::EvaluationType evalType =
624 Algo::getEvaluationChoice(this->
inputValues.size(), this->outputValues.size());
626 if (Algo::EvaluationType::Forward == evalType) {
628 }
else if (Algo::EvaluationType::Reverse == evalType) {
631 CODI_EXCEPTION(
"Evaluation type not implemented.");
635 this->
tape, this->
tape.getZeroPosition(), this->tape.getPosition(), this->inputValues.data(),
636 this->inputValues.size(), this->outputValues.data(), this->outputValues.size(), hes, jac);
641 template<
typename Type,
typename =
void>
644#ifndef DOXYGEN_DISABLE
646 template<
typename Type>
650 template<
typename Type>
651 struct TapeHelper<Type, TapeTraits::EnableIfPrimalValueTape<typename Type::Tape>> :
public TapeHelperPrimal<Type> {};
#define CODI_INLINE
See codi::Config::ForcedInlines.
Definition config.h:457
#define CODI_DD(Type, Default)
Abbreviation for CODI_DECLARE_DEFAULT.
Definition macros.hpp:94
#define CODI_STATIC_ASSERT(cond, message)
Static assert in CoDiPack.
Definition macros.hpp:123
bool constexpr ReversalZeroesAdjoints
With a linear index management, control if adjoints are set to zero during reversal.
Definition config.h:289
typename TraitsImplementation< Type >::PassiveReal PassiveReal
The original computation type, that was used in the application.
Definition realTraits.hpp:117
CoDiPack - Code Differentiation Package.
Definition codi.hpp:90
void CODI_UNUSED(Args const &...)
Disable unused warnings for an arbitrary number of arguments.
Definition macros.hpp:46
Basic algorithms for tape evaluation in CoDiPack.
Definition algorithms.hpp:68
static void computeHessianPrimalValueTape(Tape &tape, Position const &start, Position const &end, Identifier const *input, size_t const inputSize, Identifier const *output, size_t const outputSize, Hes &hes, Jac &jac=StaticDummy< DummyJacobian >::dummy)
Compute the Hessian with multiple tape sweeps.
Definition algorithms.hpp:244
Default implementation of the Hessian interface.
Definition hessian.hpp:59
Wrapper for JacboianInterfaces that requires a passive value conversion.
Definition jacobian.hpp:186
Default implementation of the Jacobian interface.
Definition jacobian.hpp:60
Static dummy objects for e.g. default reference arguments.
Definition staticDummy.hpp:42
A helper class that allows for a simpler access and management of a CoDiPack tape.
Definition tapeHelper.hpp:103
Gradient * createGradientVectorInput()
Create a gradient vector that can hold the tangent/adjoint of the input variables.
Definition tapeHelper.hpp:146
void evalForward(Gradient const *x_d, Gradient *y_d)
Perform a forward (tangent) evaluation of the recorded tape.
Definition tapeHelper.hpp:320
virtual ~TapeHelperBase()
Destructor.
Definition tapeHelper.hpp:136
void evalHessian(HessianType &hes, Jac &jac=StaticDummy< DummyJacobian >::dummy)
Evaluates the full Hessian of the recorded tape.
JacobianType & createJacobian()
Create a Jacobian that can hold the Jacobian of the recorded tape.
Definition tapeHelper.hpp:170
void deleteGradientVector(Gradient *vec)
Delete a gradient vector that was created with createGradientVectorInput or createGradientVectorOutpu...
Definition tapeHelper.hpp:215
Tape & tape
Reference to the global tape.
Definition tapeHelper.hpp:123
void changeStateToForwardEvaluation()
Change state.
Definition tapeHelper.hpp:511
void registerOutput(Type &value)
Add an output variable to the tape.
Definition tapeHelper.hpp:281
void evalJacobianAt(Real const *x, JacobianType &jac, Real *y=nullptr)
Re-evaluate the tape with new input variables and compute the full Jacobian at the new inputs.
Definition tapeHelper.hpp:431
void deletePrimalVector(Real *vec)
Delete a primal vector that was created with createPrimalVectorInput or createPrimalVectorOutput.
Definition tapeHelper.hpp:236
size_t getOutputSize()
Definition tapeHelper.hpp:250
void deleteHessian(HessianType &hes)
Delete the Hessian that was created with createHessian function.
Definition tapeHelper.hpp:229
void evalReverseAt(Real const *x, Gradient const *y_b, Gradient *x_b, Real *y=nullptr)
Re-evaluate the tape with new input variables and compute the AD forward mode.
Definition tapeHelper.hpp:397
void changeStateToReverseEvaluation()
Change state and clear the adjoints.
Definition tapeHelper.hpp:518
void evalForwardAt(Real const *x, Gradient const *x_d, Gradient *y_d, Real *y=nullptr)
Re-evaluate the tape with new input variables and compute the AD forward mode.
Definition tapeHelper.hpp:350
void evalJacobian(JacobianType &jac)
Evaluates the full Jacobian of the recorded tape.
Definition tapeHelper.hpp:412
void stopRecording()
Stop the recording process.
Definition tapeHelper.hpp:296
void evalJacobianGen(Jac &jac)
Evaluates the full Jacobian of the recorded tape with a custom Jacobian type chosen by the user.
Definition tapeHelper.hpp:445
Jacobian< PassiveReal > JacobianType
Type of the Jacobian.
Definition tapeHelper.hpp:116
T_Type Type
See TapeHelperBase.
Definition tapeHelper.hpp:107
typename Type::Tape Tape
Underlying tape type.
Definition tapeHelper.hpp:121
void registerInput(Type &value)
Add an input variable to the tape.
Definition tapeHelper.hpp:265
Real * createPrimalVectorInput()
Create a primal vector that can hold the primal seeding of the input variables.
Definition tapeHelper.hpp:198
Impl & cast()
Cast to the implementing class.
Definition tapeHelper.hpp:506
std::vector< Identifier > inputValues
Input value identifiers.
Definition tapeHelper.hpp:125
Gradient * createGradientVectorOutput()
Create a gradient vector that can hold the tangent/adjoint of the output variables.
Definition tapeHelper.hpp:158
typename Type::Real Real
See LhsExpressionInterface.
Definition tapeHelper.hpp:110
T_Impl Impl
See TapeHelperBase.
Definition tapeHelper.hpp:108
Hessian< PassiveReal > HessianType
Type of the Hessian.
Definition tapeHelper.hpp:117
typename Type::Identifier Identifier
See LhsExpressionInterface.
Definition tapeHelper.hpp:111
void evalHessianAt(Real const *x, HessianType &hes, Real *y=nullptr, Jac &jac=StaticDummy< DummyJacobian >::dummy)
Re-evaluate the tape with new input variables and compute the full Hessian at the new inputs.
Definition tapeHelper.hpp:496
typename Type::Gradient Gradient
See LhsExpressionInterface.
Definition tapeHelper.hpp:112
void startRecording()
Start the recording process. Deletes the old tape.
Definition tapeHelper.hpp:287
size_t getInputSize()
Definition tapeHelper.hpp:244
typename RealTraits::PassiveReal< Real > PassiveReal
Passive base of the CoDiPack type.
Definition tapeHelper.hpp:114
Real * createPrimalVectorOutput()
Create a primal vector that can hold the primal result of the output variables.
Definition tapeHelper.hpp:210
void evalReverse(Gradient const *y_b, Gradient *x_b)
Perform a reverse (adjoint) evaluation of the recorded tape.
Definition tapeHelper.hpp:363
std::vector< Identifier > outputValues
Input value identifiers.
Definition tapeHelper.hpp:126
virtual void evalPrimal(Real const *x, Real *y=nullptr)=0
Perform a primal re-evaluation of the tape.
bool wasForwardEvaluated
State of the last evaluation.
Definition tapeHelper.hpp:128
TapeHelperBase()
Constructor.
Definition tapeHelper.hpp:133
HessianType & createHessian()
Create a Hessian that can hold the Hessian of the recorded tape.
Definition tapeHelper.hpp:184
void deleteJacobian(JacobianType &jac)
Delete the Jacobian that was created with createJacobian function.
Definition tapeHelper.hpp:222
Definition tapeHelper.hpp:561
virtual void evalPrimal(Real const *x, Real *y=nullptr)
Throws an exception since primal evaluations are not support by Jacobian tapes.
Definition tapeHelper.hpp:570
void evalHessian(typename Base::HessianType &hes, Jac &jac=StaticDummy< DummyJacobian >::dummy)
Throws an exception since primal evaluations are not supported by Jacobian tapes.
Definition tapeHelper.hpp:580
typename Type::Real Real
See TapeHelperBase.
Definition tapeHelper.hpp:565
T_Type Type
See TapeHelperBase.
Definition tapeHelper.hpp:564
Definition tapeHelper.hpp:536
virtual void evalPrimal(Real const *x, Real *y=nullptr)=0
Missing implementation will yield linker errors.
typename Type::Real Real
See TapeHelperBase.
Definition tapeHelper.hpp:542
T_Type Type
See TapeHelperBase.
Definition tapeHelper.hpp:541
void evalHessian(typename Base::HessianType &hes, Jac &jac=StaticDummy< DummyJacobian >::dummy)
Missing implementation will yield linker errors.
Definition tapeHelper.hpp:596
virtual void evalPrimal(Real const *x, Real *y=nullptr)
Perform a primal re-evaluation of the tape.
Definition tapeHelper.hpp:605
T_Type Type
See TapeHelperBase.
Definition tapeHelper.hpp:599
typename Type::Real Real
See TapeHelperBase.
Definition tapeHelper.hpp:600
void evalHessian(typename Base::HessianType &hes, Jac &jac=StaticDummy< DummyJacobian >::dummy)
Evaluates the full Hessian of the recorded tape.
Definition tapeHelper.hpp:621
See TapeHelperBase.
Definition tapeHelper.hpp:642