41#include "../misc/tupleMemory.hpp"
42#include "../traits/computationTraits.hpp"
43#include "../traits/expressionTraits.hpp"
44#include "expressionInterface.hpp"
45#include "logic/compileTimeTraversalLogic.hpp"
46#include "logic/nodeInterface.hpp"
47#include "logic/traversalLogic.hpp"
61 template<
typename T_Real>
70 template<
typename... Args>
75 template<
size_t argNumber,
typename Tangent,
typename... Args>
80 template<
size_t argNumber,
typename Adjoint,
typename... Args>
97 template<
typename T_Real,
typename T_Impl>
104 template<
typename Arg>
109 template<
typename Tangent,
typename Arg>
114 template<
typename Adjo
int,
typename Arg>
124 template<
size_t argNumber,
typename Tangent,
typename Arg>
126 return Impl::applyTangentArg(tangent, result,
arg);
132 template<
size_t argNumber,
typename Adjo
int,
typename Arg>
134 return Impl::applyAdjointArg(adjoint, result,
arg);
148 template<
typename T_Real,
typename T_Impl>
155 template<
typename Arg>
159 template<
typename Arg>
169 template<
typename Tangent,
typename Arg>
171 return Impl::gradient(
arg, result) * tangent;
177 template<
typename Adjo
int,
typename Arg>
179 return ComputationTraits::transpose(Impl::gradient(
arg, result)) * adjoint;
196 template<
typename T_Real,
typename T_Impl>
203 template<
typename ArgA,
typename ArgB>
208 template<
typename Tangent,
typename ArgA,
typename ArgB>
214 template<
typename Adjo
int,
typename ArgA,
typename ArgB>
220 template<
typename Tangent,
typename ArgA,
typename ArgB>
226 template<
typename Adjo
int,
typename ArgA,
typename ArgB>
234#ifndef DOXYGEN_DISABLE
235 template<
typename Func,
bool derivB = false>
236 struct CallSwitchTangent {
238 template<
typename... Args>
240 return Impl::applyTangentArgA(std::forward<Args>(args)...);
244 template<
typename Temp>
245 struct CallSwitchTangent<Temp, true> {
247 template<
typename... Args>
249 return Impl::applyTangentArgB(std::forward<Args>(args)...);
253 template<
typename Func,
bool derivB = false>
254 struct CallSwitchAdjoint {
256 template<
typename... Args>
258 return Impl::applyAdjointArgA(std::forward<Args>(args)...);
262 template<
typename Temp>
263 struct CallSwitchAdjoint<Temp, true> {
265 template<
typename... Args>
267 return Impl::applyAdjointArgB(std::forward<Args>(args)...);
275 template<
size_t argNumber,
typename Tangent,
typename ArgA,
typename ArgB>
278 return CallSwitchTangent < void, argNumber == 1 > ::call(tangent, result, argA, argB);
284 template<
size_t argNumber,
typename Adjo
int,
typename ArgA,
typename ArgB>
287 return CallSwitchAdjoint < void, argNumber == 1 > ::call(adjoint, result, argA, argB);
301 template<
typename T_Real,
typename T_Impl>
308 template<
typename ArgA,
typename ArgB>
312 template<
typename ArgA,
typename ArgB>
316 template<
typename ArgA,
typename ArgB>
326 template<
typename Tangent,
typename ArgA,
typename ArgB>
329 return Impl::gradientA(argA, argB, result) * tangent;
335 template<
typename Adjo
int,
typename ArgA,
typename ArgB>
338 return ComputationTraits::transpose(Impl::gradientA(argA, argB, result)) * adjoint;
344 template<
typename Tangent,
typename ArgA,
typename ArgB>
347 return Impl::gradientB(argA, argB, result) * tangent;
353 template<
typename Adjo
int,
typename ArgA,
typename ArgB>
356 return ComputationTraits::transpose(Impl::gradientB(argA, argB, result)) * adjoint;
369 template<
typename T_Real,
template<
typename>
class T_Operation,
typename... T_ArgExprs>
371 :
public ExpressionInterface<T_Real, ComputeExpression<T_Real, T_Operation, T_ArgExprs...> > {
378 using ArgReals = std::tuple<
typename T_ArgExprs::Real...>;
380 std::tuple<
typename T_ArgExprs::StoreAs...>;
410 typename T_ArgExprs::ADLogic...>
::ADLogic;
420 template<
size_t argNumber,
typename Tangent>
422 return callTangent<argNumber>(tangent,
result,
args);
428 template<
size_t argNumber,
typename Adjo
int>
430 return callAdjoint<argNumber>(adjoint,
result,
args);
438 static size_t constexpr LinkCount = std::tuple_size<ArgReals>::value;
441 template<
size_t argNumber>
443 return args.template get<argNumber>();
451 template<
size_t argNumber,
typename EvalArg,
typename Tuple,
size_t... I>
452 static CODI_INLINE auto callAdjoint(EvalArg
const& evalArg, Real
const&
result, Tuple t,
453 std::index_sequence<I...>) {
457 template<
size_t argNumber,
typename EvalArg,
typename Tuple>
458 static CODI_INLINE auto callAdjoint(EvalArg
const& evalArg, Real
const&
result, Tuple
const& t) {
459 static constexpr auto size = std::tuple_size<ArgStoresTypes>::value;
460 return callAdjoint<argNumber>(evalArg,
result, t, std::make_index_sequence<size>{});
463 template<
size_t argNumber,
typename EvalArg,
typename Tuple,
size_t... I>
465 std::index_sequence<I...>) {
469 template<
size_t argNumber,
typename EvalArg,
typename Tuple>
471 static constexpr auto size = std::tuple_size<ArgStoresTypes>::value;
472 return callTangent<argNumber>(evalArg,
result, t, std::make_index_sequence<size>{});
#define CODI_INLINE
See codi::Config::ForcedInlines.
Definition config.h:469
#define CODI_DD(Type, Default)
Abbreviation for CODI_DECLARE_DEFAULT.
Definition macros.hpp:96
#define CODI_T(...)
Abbreviation for CODI_TEMPLATE.
Definition macros.hpp:116
ValidateADLogicImpl< Results... > ValidateADLogic
Validates if the AD logic of an arbitrary amount of expressions are the same or compatible....
Definition expressionTraits.hpp:119
CoDiPack - Code Differentiation Package.
Definition codi.hpp:94
inlineauto arg(ExpressionInterface< std::complex< Real >, Arg > const &arg)
Function overload for FUNCTION.
Definition allOperators.hpp:75
Implements BinaryOperation for functions where the gradients can be computed and transposed.
Definition computeExpression.hpp:302
T_Impl Impl
See BinaryJacobianOperation.
Definition computeExpression.hpp:321
static inlineauto gradientA(ArgA const &argA, ArgB const &argB, Real const &result)
Compute .
static inlineReal primal(ArgA const &argA, ArgB const &argB)
static inlineauto applyTangentArgA(Tangent const &tangent, Real const &result, ArgA const &argA, ArgB const &argB)
Definition computeExpression.hpp:327
static inlineArgA applyAdjointArgA(Adjoint const &adjoint, Real const &result, ArgA const &argA, ArgB const &argB)
Definition computeExpression.hpp:336
static inlineauto applyTangentArgB(Tangent const &tangent, Real const &result, ArgA const &argA, ArgB const &argB)
Definition computeExpression.hpp:345
static inlineArgB applyAdjointArgB(Adjoint const &adjoint, Real const &result, ArgA const &argA, ArgB const &argB)
Definition computeExpression.hpp:354
static inlineauto gradientB(ArgA const &argA, ArgB const &argB, Real const &result)
Compute .
T_Real Real
See BinaryJacobianOperation.
Definition computeExpression.hpp:305
Implements ComputeOperation for two arguments.
Definition computeExpression.hpp:197
static inlineReal primal(ArgA const &argA, ArgB const &argB)
static inlineauto applyAdjoint(Adjoint const &adjoint, Real const &result, ArgA const &argA, ArgB const &argB)
Definition computeExpression.hpp:285
static inlineauto applyAdjointArgB(Adjoint const &adjoint, Real const &result, ArgA const &argA, ArgB const &argB)
static inlineauto applyTangentArgB(Tangent const &tangent, Real const &result, ArgA const &argA, ArgB const &argB)
T_Real Real
See BinaryOperation.
Definition computeExpression.hpp:200
static inlineauto applyTangent(Tangent const &tangent, Real const &result, ArgA const &argA, ArgB const &argB)
Definition computeExpression.hpp:276
T_Impl Impl
See BinaryOperation.
Definition computeExpression.hpp:232
static inlineauto applyTangentArgA(Tangent const &tangent, Real const &result, ArgA const &argA, ArgB const &argB)
static inlineauto applyAdjointArgA(Adjoint const &adjoint, Real const &result, ArgA const &argA, ArgB const &argB)
std::tuple< T_ArgExprs... > ArgExprs
Definition computeExpression.hpp:376
std::tuple< typename T_ArgExprs::StoreAs... > ArgStoresTypes
Definition computeExpression.hpp:379
InnerReal Real
Definition computeExpression.hpp:373
TupleMemory< typename T_ArgExprs::StoreAs... > ArgStores
Definition computeExpression.hpp:381
inlinestd::string getMathRep() const
Get the math symbol of the operation. E.g. + for operators and pow() for functions.
Definition computeExpression.hpp:399
ComputeExpression StoreAs
Definition computeExpression.hpp:408
inlineexplicit ComputeExpression(ExpressionInterface< typename T_ArgExprs::Real, T_ArgExprs > const &... args)
Constructor.
Definition computeExpression.hpp:388
static size_t constexpr LinkCount
Definition computeExpression.hpp:438
typename ExpressionTraits::ValidateADLogic< typename T_ArgExprs::ADLogic... >::ADLogic ADLogic
Definition computeExpression.hpp:409
inlinestd::tuple_element_t< argNumber, ArgStoresTypes > const & getLink() const
an expression.
Definition computeExpression.hpp:442
inlineReal applyTangent(Tangent const &tangent) const
Definition computeExpression.hpp:421
std::tuple< typename T_ArgExprs::Real... > ArgReals
Definition computeExpression.hpp:378
ArrayAccessOperation< T > Operation
Definition computeExpression.hpp:375
inlineReal const & getValue() const
Definition computeExpression.hpp:413
Real result
Definition computeExpression.hpp:385
inlineauto applyAdjoint(Adjoint const &adjoint) const
Definition computeExpression.hpp:429
ArgStores args
Definition computeExpression.hpp:383
Interface for implementing the logic for a ComputeExpression.
Definition computeExpression.hpp:62
static inlinestd::string getMathRep()
Get the math symbol of the operation. E.g. + for operators and pow() for functions.
static inlineauto applyAdjoint(Adjoint const &adjoint, Real const &result, Args const &... args)
static inlineauto applyTangent(Tangent const &tangent, Real const &result, Args const &... args)
static inlineReal primal(Args const &... args)
T_Real Real
See ComputeOperation.
Definition computeExpression.hpp:65
ExpressionInterface()=default
inlineImpl const & cast() const
Cast to the implementation.
Definition expressionInterface.hpp:76
Tuple implementation which allows to force inline of the construction of the tuple.
Definition tupleMemory.hpp:92
Implements UnaryOperation for functions where the gradient can be computed and transposed.
Definition computeExpression.hpp:149
static inlineReal primal(Arg const &arg)
static inlineauto applyTangentArg(Tangent const &tangent, Real const &result, Arg const &arg)
Definition computeExpression.hpp:170
static inlineauto gradient(Arg const &arg, Real const &result)
Compute .
static inlineArg applyAdjointArg(Adjoint const &adjoint, Real const &result, Arg const &arg)
Definition computeExpression.hpp:178
T_Impl Impl
See UnaryOperation.
Definition computeExpression.hpp:164
T_Real Real
See UnaryJacobianOperation.
Definition computeExpression.hpp:152
Implements ComputeOperation for one argument.
Definition computeExpression.hpp:98
T_Impl Impl
See UnaryOperation.
Definition computeExpression.hpp:119
static inlineauto applyAdjointArg(Adjoint const &adjoint, Real const &result, Arg const &arg)
static inlineauto applyTangent(Tangent const &tangent, Real const &result, Arg const &arg)
Definition computeExpression.hpp:125
static inlineReal primal(Arg const &arg)
T_Real Real
See UnaryOperation.
Definition computeExpression.hpp:101
static inlineauto applyTangentArg(Tangent const &tangent, Real const &result, Arg const &arg)
static inlineauto applyAdjoint(Adjoint const &adjoint, Real const &result, Arg const &arg)
Definition computeExpression.hpp:133