CoDiPack  2.3.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 (typename PrimalTapeStatementFunctions::Handle)Generator::template statementGetWriteInformation<Expr>);
89
102 template<typename T_Real>
104 public:
105
106 using Real = CODI_DD(T_Real, double);
107
108 /*******************************************************************************/
111
113
115 template<typename Tape, typename... Args>
116 static Real callForward(Handle const& h, Args&&... args) {
117 return Tape::statementEvaluateForwardFull((FunctionForward<Tape>)h->forward, h->maxActiveArguments,
118 h->maxConstantArguments, std::forward<Args>(args)...);
119 }
120
122 template<typename Tape, typename... Args>
123 static Real callPrimal(Handle const& h, Args&&... args) {
124 return Tape::statementEvaluatePrimalFull((FunctionPrimal<Tape>)h->primal, h->maxActiveArguments,
125 h->maxConstantArguments, std::forward<Args>(args)...);
126 }
127
129 template<typename Tape, typename... Args>
130 static void callReverse(Handle const& h, Args&&... args) {
131 Tape::statementEvaluateReverseFull((FunctionReverse<Tape>)h->reverse, h->maxActiveArguments,
132 h->maxConstantArguments, std::forward<Args>(args)...);
133 }
134
136 template<typename Tape, typename Generator, typename Expr>
140
142 template<typename Tape, typename... Args>
143 static WriteInfo getWriteInformation(Handle const& h, Args&&... args) {
144 return ((FunctionWriteInformation<Tape>)h->writeInformation)(std::forward<Args>(args)...);
145 }
146
148
149 protected:
150
152 template<typename Tape>
153 using FunctionForward = decltype(&Tape::template statementEvaluateForwardInner<ActiveType<Tape>>);
154
156 template<typename Tape>
157 using FunctionPrimal = decltype(&Tape::template statementEvaluatePrimalInner<ActiveType<Tape>>);
158
160 template<typename Tape>
161 using FunctionReverse = decltype(&Tape::template statementEvaluateReverseInner<ActiveType<Tape>>);
162
164 template<typename Tape>
165 using FunctionWriteInformation = decltype(&Tape::template statementGetWriteInformation<ActiveType<Tape>>);
166 };
167}
#define CODI_DD(Type, Default)
Abbreviation for CODI_DECLARE_DEFAULT.
Definition macros.hpp:94
CoDiPack - Code Differentiation Package.
Definition codi.hpp:91
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, typename Base::Handle writeInformation)
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:103
decltype(&Tape::template statementEvaluatePrimalInner< ActiveType< Tape > >) FunctionPrimal
Full primal function type.
Definition innerStatementEvaluator.hpp:157
static WriteInfo getWriteInformation(Handle const &h, Args &&... args)
Definition innerStatementEvaluator.hpp:143
static void callReverse(Handle const &h, Args &&... args)
Definition innerStatementEvaluator.hpp:130
decltype(&Tape::template statementGetWriteInformation< ActiveType< Tape > >) FunctionWriteInformation
Write information function type.
Definition innerStatementEvaluator.hpp:165
static Real callForward(Handle const &h, Args &&... args)
Definition innerStatementEvaluator.hpp:116
T_Real Real
See InnerStatementEvaluator.
Definition innerStatementEvaluator.hpp:106
decltype(&Tape::template statementEvaluateForwardInner< ActiveType< Tape > >) FunctionForward
Full forward function type.
Definition innerStatementEvaluator.hpp:153
decltype(&Tape::template statementEvaluateReverseInner< ActiveType< Tape > >) FunctionReverse
Full reverse function type.
Definition innerStatementEvaluator.hpp:161
static Handle createHandle()
Definition innerStatementEvaluator.hpp:137
static Real callPrimal(Handle const &h, Args &&... args)
Definition innerStatementEvaluator.hpp:123
InnerPrimalTapeStatementData const * Handle
Pointer to static storage location.
Definition innerStatementEvaluator.hpp:112
Data required for all possible handle calls.
Definition directStatementEvaluator.hpp:51
Handle forward
Forward function handle.
Definition directStatementEvaluator.hpp:56
void * Handle
Function pointer.
Definition directStatementEvaluator.hpp:54
Handle primal
Primal function handle.
Definition directStatementEvaluator.hpp:57
PrimalTapeStatementFunctions(Handle forward, Handle primal, Handle reverse, Handle writeInformation)
Constructor.
Definition directStatementEvaluator.hpp:61
Handle reverse
Reverse function handle.
Definition directStatementEvaluator.hpp:58
Handle writeInformation
Definition directStatementEvaluator.hpp:59
Creation of handles for the evaluation of expressions in a context where the expression type is not a...
Definition statementEvaluatorInterface.hpp:104
This class is used during the writing process of a primal value tape. The WriteInfo is returned by co...
Definition tapeReaderWriterInterface.hpp:69