CoDiPack  2.2.0
A Code Differentiation Package
SciComp TU Kaiserslautern
Loading...
Searching...
No Matches
innerStatementEvaluator.hpp
1/*
2 * CoDiPack, a Code Differentiation Package
3 *
4 * Copyright (C) 2015-2024 Chair for Scientific Computing (SciComp), University of Kaiserslautern-Landau
5 * Homepage: http://scicomp.rptu.de
6 * Contact: Prof. Nicolas R. Gauger (codi@scicomp.uni-kl.de)
7 *
8 * Lead developers: Max Sagebaum, Johannes Blühdorn (SciComp, University of Kaiserslautern-Landau)
9 *
10 * This file is part of CoDiPack (http://scicomp.rptu.de/software/codi).
11 *
12 * CoDiPack is free software: you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, either version 3 of the
15 * License, or (at your option) any later version.
16 *
17 * CoDiPack is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty
19 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
20 *
21 * See the GNU General Public License for more details.
22 * You should have received a copy of the GNU
23 * General Public License along with CoDiPack.
24 * If not, see <http://www.gnu.org/licenses/>.
25 *
26 * For other licensing options please contact us.
27 *
28 * Authors:
29 * - SciComp, University of Kaiserslautern-Landau:
30 * - Max Sagebaum
31 * - Johannes Blühdorn
32 * - Former members:
33 * - Tim Albring
34 */
35#pragma once
36
37#include <algorithm>
38#include <functional>
39#include <type_traits>
40
41#include "../../expressions/activeType.hpp"
42#include "../../misc/macros.hpp"
43#include "../../traits/expressionTraits.hpp"
44#include "directStatementEvaluator.hpp"
45#include "statementEvaluatorInterface.hpp"
46
48namespace codi {
49
69
72 template<typename Tape, typename Expr>
80
81 template<typename Generator, typename Expr>
85 (typename PrimalTapeStatementFunctions::Handle)Generator::template statementEvaluateForwardInner<Expr>,
86 (typename PrimalTapeStatementFunctions::Handle)Generator::template statementEvaluatePrimalInner<Expr>,
87 (typename PrimalTapeStatementFunctions::Handle)Generator::template statementEvaluateReverseInner<Expr>);
88
101 template<typename T_Real>
103 public:
104
105 using Real = CODI_DD(T_Real, double);
106
107 /*******************************************************************************/
110
112
114 template<typename Tape, typename... Args>
115 static Real callForward(Handle const& h, Args&&... args) {
116 return Tape::statementEvaluateForwardFull((FunctionForward<Tape>)h->forward, h->maxActiveArguments,
117 h->maxConstantArguments, std::forward<Args>(args)...);
118 }
119
121 template<typename Tape, typename... Args>
122 static Real callPrimal(Handle const& h, Args&&... args) {
123 return Tape::statementEvaluatePrimalFull((FunctionPrimal<Tape>)h->primal, h->maxActiveArguments,
124 h->maxConstantArguments, std::forward<Args>(args)...);
125 }
126
128 template<typename Tape, typename... Args>
129 static void callReverse(Handle const& h, Args&&... args) {
130 Tape::statementEvaluateReverseFull((FunctionReverse<Tape>)h->reverse, h->maxActiveArguments,
131 h->maxConstantArguments, std::forward<Args>(args)...);
132 }
133
135 template<typename Tape, typename Generator, typename Expr>
139
141
142 protected:
143
145 template<typename Tape>
146 using FunctionForward = decltype(&Tape::template statementEvaluateForwardInner<ActiveType<Tape>>);
147
149 template<typename Tape>
150 using FunctionPrimal = decltype(&Tape::template statementEvaluatePrimalInner<ActiveType<Tape>>);
151
153 template<typename Tape>
154 using FunctionReverse = decltype(&Tape::template statementEvaluateReverseInner<ActiveType<Tape>>);
155 };
156}
#define CODI_DD(Type, Default)
Abbreviation for CODI_DECLARE_DEFAULT.
Definition macros.hpp:94
CoDiPack - Code Differentiation Package.
Definition codi.hpp:90
Counts the number of nodes that inherit from LhsExpressionInterface in the expression.
Definition expressionTraits.hpp:184
Counts the number of types that inherit from ConstantExpression in the expression.
Definition expressionTraits.hpp:210
Additional data required by an InnerStatementEvaluator.
Definition innerStatementEvaluator.hpp:53
size_t maxConstantArguments
Maximum number of constant arguments.
Definition innerStatementEvaluator.hpp:59
InnerPrimalTapeStatementData(size_t maxActiveArguments, size_t maxConstantArguments, typename Base::Handle forward, typename Base::Handle primal, typename Base::Handle reverse)
Constructor.
Definition innerStatementEvaluator.hpp:62
size_t maxActiveArguments
Maximum number of active arguments.
Definition innerStatementEvaluator.hpp:58
Definition innerStatementEvaluator.hpp:73
static InnerPrimalTapeStatementData const staticStore
Static storage.
Definition innerStatementEvaluator.hpp:78
Expression evaluation in the inner function. Data loading in the compilation context of the tape....
Definition innerStatementEvaluator.hpp:102
decltype(&Tape::template statementEvaluatePrimalInner< ActiveType< Tape > >) FunctionPrimal
Full primal function type.
Definition innerStatementEvaluator.hpp:150
static void callReverse(Handle const &h, Args &&... args)
Definition innerStatementEvaluator.hpp:129
static Real callForward(Handle const &h, Args &&... args)
Definition innerStatementEvaluator.hpp:115
T_Real Real
See InnerStatementEvaluator.
Definition innerStatementEvaluator.hpp:105
decltype(&Tape::template statementEvaluateForwardInner< ActiveType< Tape > >) FunctionForward
Full forward function type.
Definition innerStatementEvaluator.hpp:146
decltype(&Tape::template statementEvaluateReverseInner< ActiveType< Tape > >) FunctionReverse
Full reverse function type.
Definition innerStatementEvaluator.hpp:154
static Handle createHandle()
Definition innerStatementEvaluator.hpp:136
static Real callPrimal(Handle const &h, Args &&... args)
Definition innerStatementEvaluator.hpp:122
InnerPrimalTapeStatementData const * Handle
Pointer to static storage location.
Definition innerStatementEvaluator.hpp:111
Data required for all possible handle calls.
Definition directStatementEvaluator.hpp:51
Handle forward
Forward function handle.
Definition directStatementEvaluator.hpp:56
PrimalTapeStatementFunctions(Handle forward, Handle primal, Handle reverse)
Constructor.
Definition directStatementEvaluator.hpp:61
void * Handle
Function pointer.
Definition directStatementEvaluator.hpp:54
Handle primal
Primal function handle.
Definition directStatementEvaluator.hpp:57
Handle reverse
Reverse function handle.
Definition directStatementEvaluator.hpp:58
Creation of handles for the evaluation of expressions in a context where the expression type is not a...
Definition statementEvaluatorInterface.hpp:103