CoDiPack  2.2.0
A Code Differentiation Package
SciComp TU Kaiserslautern
Loading...
Searching...
No Matches
codi::ForwardEvaluation< T_Real, T_Gradient > Struct Template Reference

Implementation of a tape-free forward AD mode through the internal expression interfaces. More...

#include <forwardEvaluation.hpp>

Inheritance diagram for codi::ForwardEvaluation< T_Real, T_Gradient >:

Public Types

using Gradient = T_Gradient
 See ForwardEvaluation.
 
using Identifier = Gradient
 Same as the gradient type. Tangent data is stored in the active types.
 
using PassiveReal = RealTraits::PassiveReal<Real>
 Basic computation type.
 
using Real = T_Real
 See ForwardEvaluation.
 
- Public Types inherited from codi::InternalStatementRecordingTapeInterface< T_Gradient >
using Identifier
 See InternalStatementRecordingTapeInterface.
 
- Public Types inherited from codi::GradientAccessTapeInterface< T_Gradient, T_Gradient >
using Gradient
 See GradientAccessTapeInterface.
 
using Identifier
 See GradientAccessTapeInterface.
 

Public Member Functions

template<typename Lhs , typename Rhs >
void store (LhsExpressionInterface< Real, Gradient, ForwardEvaluation, Lhs > &lhs, ExpressionInterface< Real, 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, ForwardEvaluation, Lhs > &lhs, LhsExpressionInterface< Real, Gradient, ForwardEvaluation, Rhs > const &rhs)
 Has to be called by an AD variable every time it is assigned.

 
template<typename Lhs >
void store (LhsExpressionInterface< Real, Gradient, ForwardEvaluation, Lhs > &lhs, Real const &rhs)
 Has to be called by an AD variable every time it is assigned.

 
Implementation of GradientAccessTapeInterface
void setGradient (Identifier &identifier, Gradient const &gradient, AdjointsManagement adjointsManagement=AdjointsManagement::Automatic)
 Set the gradient.
 
Gradient const & getGradient (Identifier const &identifier, AdjointsManagement adjointsManagement=AdjointsManagement::Automatic) const
 Set the gradient.
 
Gradientgradient (Identifier &identifier, AdjointsManagement adjointsManagement=AdjointsManagement::Automatic)
 Reference access to gradient.
 
Gradient const & gradient (Identifier const &identifier, AdjointsManagement adjointsManagement=AdjointsManagement::Automatic) const
 Constant reference access to gradient.
 
- Public Member Functions inherited from codi::InternalStatementRecordingTapeInterface< T_Gradient >
void initIdentifier (Real &value, Identifier &identifier)
 
void destroyIdentifier (Real &value, Identifier &identifier)
 Has to be called for each identifier, before it is deallocated.
 
void store (Lhs &lhs, Rhs const &rhs)
 Has to be called by an AD variable every time it is assigned.
 
- Public Member Functions inherited from codi::GradientAccessTapeInterface< T_Gradient, T_Gradient >
void setGradient (Identifier const &identifier, Gradient const &gradient, AdjointsManagement adjointsManagement=AdjointsManagement::Automatic)
 Set the gradient.
 
Gradient const & getGradient (Identifier const &identifier, AdjointsManagement adjointsManagement=AdjointsManagement::Automatic) const
 Set the gradient.
 
Gradientgradient (Identifier const &identifier, AdjointsManagement adjointsManagement=AdjointsManagement::Automatic)
 Reference access to gradient.
 
Gradient const & gradient (Identifier const &identifier, AdjointsManagement adjointsManagement=AdjointsManagement::Automatic) const
 Constant reference access to gradient.
 

Implementation of InternalStatementRecordingTapeInterface

static bool constexpr AllowJacobianOptimization = true
 See InternalStatementRecordingTapeInterface.
 
template<typename Real >
void initIdentifier (Real &value, Identifier &identifier)
 
template<typename Real >
void destroyIdentifier (Real &value, Identifier &identifier)
 Has to be called for each identifier, before it is deallocated.
 

Additional Inherited Members

- Static Public Attributes inherited from codi::InternalStatementRecordingTapeInterface< T_Gradient >
static bool constexpr AllowJacobianOptimization
 If certain operations can be hidden from the tape.
 

Detailed Description

template<typename T_Real, typename T_Gradient>
struct codi::ForwardEvaluation< T_Real, T_Gradient >

Implementation of a tape-free forward AD mode through the internal expression interfaces.

For an explanation of the forward AD mode please see the Section forward AD.

The store method implementation performs a reverse AD sweep on the expression itself. The result is then added to the tangent data of the left hand side type.

The identifier data in the LhsExpressionInterface implementations is used by this class to store the tangent data for each value.

This way, a tape-free foward mode is implemented in a manner that is consistent with CoDiPack's taping interface, even if no tape is actually recorded.

See Tape Interface Design for a general overview of the tape interface design in CoDiPack.

Template Parameters
T_RealThe computation type of a tape usually defined by ActiveType::Real.
T_GradientThe gradient type of a tape usually defined by ActiveType::Gradient.

Member Function Documentation

◆ destroyIdentifier()

template<typename T_Real , typename T_Gradient >
template<typename Real >
void codi::ForwardEvaluation< T_Real, T_Gradient >::destroyIdentifier ( Real & value,
Identifier & identifier )
inline

Has to be called for each identifier, before it is deallocated.

◆ getGradient()

template<typename T_Real , typename T_Gradient >
Gradient const & codi::ForwardEvaluation< T_Real, T_Gradient >::getGradient ( Identifier const & identifier,
AdjointsManagement adjointsManagement = AdjointsManagement::Automatic ) const
inline

Set the gradient.

Automatic adjoints management involves bounds checking and locking. If no adjoint variable with the given identifier exists, a reference to adjoints[0] is returned. See AdjointsManagement for details.
Implementation: Automatic adjoints management has no effect. The forward mode does not maintain internal adjoints.

◆ gradient() [1/2]

template<typename T_Real , typename T_Gradient >
Gradient & codi::ForwardEvaluation< T_Real, T_Gradient >::gradient ( Identifier & identifier,
AdjointsManagement adjointsManagement = AdjointsManagement::Automatic )
inline

Reference access to gradient.

Automatic adjoints management involves bounds checking, resizing, and locking, see AdjointsManagement for details.
Implementation: Automatic adjoints management has no effect. The forward mode does not maintain internal adjoints.

◆ gradient() [2/2]

template<typename T_Real , typename T_Gradient >
Gradient const & codi::ForwardEvaluation< T_Real, T_Gradient >::gradient ( Identifier const & identifier,
AdjointsManagement adjointsManagement = AdjointsManagement::Automatic ) const
inline

Constant reference access to gradient.

Automatic adjoints management involves bounds checking and locking. If no adjoint variable with the given identifier exists, a reference to adjoints[0] is returned. See AdjointsManagement for details.
Implementation: Automatic adjoints management has no effect. The forward mode does not maintain internal adjoints.

◆ initIdentifier()

template<typename T_Real , typename T_Gradient >
template<typename Real >
void codi::ForwardEvaluation< T_Real, T_Gradient >::initIdentifier ( Real & value,
Identifier & identifier )
inline

Has to be called for each identifier, after it is allocated.

◆ setGradient()

template<typename T_Real , typename T_Gradient >
void codi::ForwardEvaluation< T_Real, T_Gradient >::setGradient ( Identifier & identifier,
Gradient const & gradient,
AdjointsManagement adjointsManagement = AdjointsManagement::Automatic )
inline

Set the gradient.

Automatic adjoints management involves bounds checking, resizing, and locking, see AdjointsManagement for details.
Implementation: Automatic adjoints management has no effect. The forward mode does not maintain internal adjoints.

◆ store() [1/3]

template<typename T_Real , typename T_Gradient >
template<typename Lhs , typename Rhs >
void codi::ForwardEvaluation< T_Real, T_Gradient >::store ( LhsExpressionInterface< Real, Gradient, ForwardEvaluation< T_Real, T_Gradient >, Lhs > & lhs,
ExpressionInterface< Real, 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.

◆ store() [2/3]

template<typename T_Real , typename T_Gradient >
template<typename Lhs , typename Rhs >
void codi::ForwardEvaluation< T_Real, T_Gradient >::store ( LhsExpressionInterface< Real, Gradient, ForwardEvaluation< T_Real, T_Gradient >, Lhs > & lhs,
LhsExpressionInterface< Real, Gradient, ForwardEvaluation< T_Real, T_Gradient >, 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.

◆ store() [3/3]

template<typename T_Real , typename T_Gradient >
template<typename Lhs >
void codi::ForwardEvaluation< T_Real, T_Gradient >::store ( LhsExpressionInterface< Real, Gradient, ForwardEvaluation< T_Real, T_Gradient >, Lhs > & lhs,
Real 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.
Specialization for passive assignments.

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