CoDiPack  3.1.1
A Code Differentiation Package
SciComp TU Kaiserslautern
Loading...
Searching...
No Matches
codi::TagTapeBase< T_Real, T_Tag, T_Gradient, T_Impl > Struct Template Reference

Base implementation for tagging tapes. More...

#include <tagTapeBase.hpp>

Inheritance diagram for codi::TagTapeBase< T_Real, T_Tag, T_Gradient, T_Impl >:

Classes

struct  ValidateTags
 Looks at the tags for the expression. More...

Public Types

using ActiveTypeTapeData = TagData<Tag>
 See TapeTypesInterface.
using ErrorCallback = void (*)(ValidationEntry<Real, Tag> const& data, Tag const& curTag, void* userData)
 Callback for all errors.
using Gradient = T_Gradient
 See TagTapeBase.
using Identifier = int
 See TapeTypesInterface.
using Impl = T_Impl
 See TagTapeBase.
using Real = T_Real
 See TagTapeBase.
using Tag = T_Tag
 See TagTapeBase.
using TagErrorCallback = void (*)(Tag const& correctTag, Tag const& wrongTag, void* userData)
 Callback for a tag error.
using TagPropertyErrorCallback
 Callback for a change in a lhs value.

Public Member Functions

void swap (Impl &other)
 Swap members.
 TagTapeBase ()
 Constructor.
IdentifierInformationTapeInterface interface partial implementation
inlineIdentifier const & getIdentifier (ActiveTypeTapeData const &data)
inlineIdentifier & getIdentifier (ActiveTypeTapeData &data)

Static Public Attributes

static Tag constexpr InvalidTag = Tag(-1)
 Tag indicating an invalid value.
static Tag constexpr PassiveTag = Tag(0)
 Tag indicating an inactive value.

Protected Attributes

Identifier const activeIdentifier = 1
 Temporary for active identifier.
Tag curTag
 Current tag for new values.
bool doActivityAnalysis = true
 Perform activity analysis for tags.
ErrorCallback errorCallback
 User defined callback for tag and property errors. Has priority over the other callbacks.
void * errorUserData
 User data in call to callback for errors.
Identifier const passiveIdentifier = 0
 Temporary for passive identifier.
bool preaccumulationHandling
 Parameter to enable/disable preaccumulation handling.
Tag preaccumulationTag
 Tag used for preaccumulation specialized handling.
TagErrorCallback tagErrorCallback
 User defined callback for tag errors.
void * tagErrorUserData
 User data in call to callback for tag errors.
TagPropertyErrorCallback tagPropertyErrorCallback
 User defined callback for lhs value errors.
void * tagPropertyErrorUserData
 User data in call to callback for lhs value errors.
Identifier tempIdentifier = 0
 Temporary for identifier values.
ValidationIndicator< Real, Tagvi = {}
 Helper for error detection.

Implementation of InternalStatementRecordingTapeInterface

static bool constexpr AllowJacobianOptimization = false
 Do not allow Jacobian optimization.
template<typename Real>
void initTapeData (Real &value, ActiveTypeTapeData &data)
 Do nothing.
template<typename Real>
void destroyTapeData (Real &value, ActiveTypeTapeData &data)
 Do nothing.
template<typename Aggregated, typename Type, typename Lhs, typename Rhs>
inlinevoid store (AggregatedActiveType< Aggregated, Type, Lhs > &lhs, ExpressionInterface< Aggregated, Rhs > const &rhs)
 Verify all tags of the rhs and properties from the lhs and rhs.
template<typename Aggregated, typename Type, typename Lhs, typename Rhs>
inlinevoid store (AggregatedActiveType< Aggregated, Type, Lhs > &lhs, AggregatedActiveType< Aggregated, Type, Rhs > const &rhs)
 Has to be called by an AD variable every time it is assigned.

template<typename Lhs, typename Rhs>
void store (LhsExpressionInterface< Real, Gradient, Impl, Lhs > &lhs, ExpressionInterface< Real, Rhs > const &rhs)
 Verify all tags of the rhs and properties from the lhs and rhs.
template<typename Lhs, typename Rhs>
void store (LhsExpressionInterface< Real, Gradient, Impl, Lhs > &lhs, LhsExpressionInterface< Real, Gradient, Impl, Rhs > const &rhs)
 Verify all tags of the rhs and the lhs properties.
template<typename Lhs>
void store (LhsExpressionInterface< Real, Gradient, Impl, Lhs > &lhs, Real const &rhs)
 Verify the lhs properties.

Tagging specific functions.

void setDoActivityAnalysis (bool active)
 Enable or disable the activity analysis for the tags. Disabling will mark all active types with the current tag.
void setCurTag (const Tag &tag)
 Set the current tag of the tape.
Tag getCurTag ()
 Get the current tag of the tape.
template<typename Lhs>
Tag getTagFromVariable (LhsExpressionInterface< Real, Gradient, Impl, Lhs > &value)
 Get tag of a CoDiPack active type.
template<typename Lhs>
void setTagOnVariable (LhsExpressionInterface< Real, Gradient, Impl, Lhs > const &value)
 Set tag on a CoDiPack active type.
template<typename Lhs>
void clearTagOnVariable (LhsExpressionInterface< Real, Gradient, Impl, Lhs > &value)
 Clear tag on a CoDiPack active type.
template<typename Lhs>
void clearTagPropertiesOnVariable (LhsExpressionInterface< Real, Gradient, Impl, Lhs > &value)
 Clear properties on a CoDiPack active type.
template<typename Lhs>
void setTagPropertyOnVariable (LhsExpressionInterface< Real, Gradient, Impl, Lhs > &value, TagFlags flag)
 Set properties on a CoDiPack active type.
template<typename Lhs>
bool hasTagPropertyOnVariable (LhsExpressionInterface< Real, Gradient, Impl, Lhs > &value, TagFlags flag)
 Check properties on a CoDiPack active type.
void setTagPropertyErrorCallback (TagPropertyErrorCallback const &callback, void *userData)
 Set the callback and user data for a property error error.
void setTagErrorCallback (TagErrorCallback const &callback, void *userData)
 Set the callback and user data for a tag error.
void setErrorCallback (ErrorCallback const &callback, void *userData)
inlinevoid setPreaccumulationHandlingEnabled (bool enabled)
 Enable or disable specialized handling for preaccumulation. Default: true Uses a special tag to sanitize preaccumulation regions.
inlinevoid setPreaccumulationHandlingTag (Tag tag)
 Set the special tag for preaccumulation regions. See setPreaccumulationHandlingEnabled().
inlinebool isPreaccumulationHandlingEnabled ()
 If handling for preaccumulation is enabled.
inlineTag getPreaccumulationHandlingTag ()
 The special tag for preaccumulation.
ValidationEntry< Real, TagmakeTagError (Tag tag, Real const *value)
 Create a tag error entry.
ValidationEntry< Real, TagmakeProeprtyError (TagFlags flag, Real const *value, Real newValue={})
 Create a property error entry.
void updateLhsTagData (ActiveTypeTapeData &lhsData, bool isActive) const
 Update the tag data for a lhs write. Updates the properties and sets the tag based on the activity.
void verifyRhsAccess (Real const &value, ActiveTypeTapeData const &data, ValidationIndicator< Real, Tag > &vi)
 Check tag and property errors.
void verifyRhsAccessForTag (Real const &value, ActiveTypeTapeData const &data, ValidationIndicator< Real, Tag > &vi)
 Check tag errors. Raises an error for tags that are not equal to the current tag. Ignores passive tags.
void verifyRhsAccessForProperty (Real const &value, ActiveTypeTapeData const &data, ValidationIndicator< Real, Tag > &vi)
 Check properties for rhs values. Validates the 'DoNotUse' property.
inlinevoid verifyLhsWrite (Real const &lhsValue, ActiveTypeTapeData const &lhsData, Real const &rhsValue, ValidationIndicator< Real, Tag > &vi)
 Validates the lhs properties.
template<typename Lhs>
inlinevoid verifyRegisterValue (LhsExpressionInterface< Real, Gradient, Impl, Lhs > &value)
 Verify tag, properties and lhs error.
inlinevoid handleError (ValidationIndicator< Real, Tag > &vi) const
 Call tag error callback.
inlinevoid setTag (Tag &tag) const
 Set tag on value.
inlinevoid resetTag (Tag &tag) const
 Reset tag on value.
static void defaultPropertyErrorCallback (Real const &currentValue, Real const &newValue, TagFlags flag, void *userData)
 Default callback for TagPropertyErrorCallback.
static void defaultTagErrorCallback (Tag const &correctTag, Tag const &wrongTag, void *userData)
 Default callback for TagErrorCallback.
static void defaultErrorCallback (ValidationEntry< Real, Tag > const &data, Tag const &curTag, void *userData)
 Default callback for ErrorCallback. (Currently not used)

Detailed Description

template<typename T_Real, typename T_Tag, typename T_Gradient, typename T_Impl>
struct codi::TagTapeBase< T_Real, T_Tag, T_Gradient, T_Impl >

Base implementation for tagging tapes.

Provides all basic management routines for the tag.

See tests/functional/src/testTagging.cpp for an example.

Template Parameters
T_RealThe computation type of a tape, usually chosen as ActiveType::Real.
T_tagThe type of the tag, usually int.

Member Typedef Documentation

◆ TagPropertyErrorCallback

template<typename T_Real, typename T_Tag, typename T_Gradient, typename T_Impl>
using codi::TagTapeBase< T_Real, T_Tag, T_Gradient, T_Impl >::TagPropertyErrorCallback
Initial value:
void (*)(Real const& currentValue, Real const& newValue, TagFlags flag,
void* userData)
TagFlags
Properties for values.
Definition tagData.hpp:46
T_Real Real
See TagTapeBase.
Definition tagTapeBase.hpp:93

Callback for a change in a lhs value.

Member Function Documentation

◆ getIdentifier() [1/2]

template<typename T_Real, typename T_Tag, typename T_Gradient, typename T_Impl>
inlineIdentifier & codi::TagTapeBase< T_Real, T_Tag, T_Gradient, T_Impl >::getIdentifier ( ActiveTypeTapeData & data)
inline

Extract identifier from the tape data stored in the active type.

◆ getIdentifier() [2/2]

template<typename T_Real, typename T_Tag, typename T_Gradient, typename T_Impl>
inlineIdentifier const & codi::TagTapeBase< T_Real, T_Tag, T_Gradient, T_Impl >::getIdentifier ( ActiveTypeTapeData const & data)
inline

Extract identifier from the tape data stored in the active type.

◆ setErrorCallback()

template<typename T_Real, typename T_Tag, typename T_Gradient, typename T_Impl>
void codi::TagTapeBase< T_Real, T_Tag, T_Gradient, T_Impl >::setErrorCallback ( ErrorCallback const & callback,
void * userData )
inline

Set a general error handle for both, tag and property, errors. If this error handler is set, the others are no longer called.

◆ store()

template<typename T_Real, typename T_Tag, typename T_Gradient, typename T_Impl>
template<typename Aggregated, typename Type, typename Lhs, typename Rhs>
inlinevoid codi::TagTapeBase< T_Real, T_Tag, T_Gradient, T_Impl >::store ( AggregatedActiveType< Aggregated, Type, Lhs > & lhs,
AggregatedActiveType< Aggregated, Type, Rhs > const & rhs )
inline

Has to be called by an AD variable every time it is assigned.

Update of the value is performed by the tape. The tape will additionally store information, e.g., for the reversal of the statement.

Template Parameters
LhsHas to implement LhsExpressionInterface.
RhsHas to implement ExpressionInterface.
Optimization for copy statements of aggregated types.

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