CoDiPack  2.2.0
A Code Differentiation Package
SciComp TU Kaiserslautern
Loading...
Searching...
No Matches
directStatementEvaluator.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 "statementEvaluatorInterface.hpp"
44
46namespace codi {
47
64
67 template<typename Generator, typename Expr>
75
76 template<typename Generator, typename Expr>
78 (typename PrimalTapeStatementFunctions::Handle)Generator::template statementEvaluateForward<Expr>,
79 (typename PrimalTapeStatementFunctions::Handle)Generator::template statementEvaluatePrimal<Expr>,
80 (typename PrimalTapeStatementFunctions::Handle)Generator::template statementEvaluateReverse<Expr>);
81
92 template<typename T_Real>
94 public:
95
96 using Real = CODI_DD(T_Real, double);
97
98 /*******************************************************************************/
101
103
105 template<typename Tape, typename... Args>
106 static Real callForward(Handle const& h, Args&&... args) {
107 return ((FunctionForward<Tape>)h->forward)(std::forward<Args>(args)...);
108 }
109
111 template<typename Tape, typename... Args>
112 static Real callPrimal(Handle const& h, Args&&... args) {
113 return ((FunctionPrimal<Tape>)h->primal)(std::forward<Args>(args)...);
114 }
115
117 template<typename Tape, typename... Args>
118 static void callReverse(Handle const& h, Args&&... args) {
119 ((FunctionReverse<Tape>)h->reverse)(std::forward<Args>(args)...);
120 }
121
123 template<typename Tape, typename Generator, typename Expr>
127
129
130 protected:
131
133 template<typename Tape>
134 using FunctionForward = decltype(&Tape::template statementEvaluateForward<ActiveType<Tape>>);
135
137 template<typename Tape>
138 using FunctionPrimal = decltype(&Tape::template statementEvaluatePrimal<ActiveType<Tape>>);
139
141 template<typename Tape>
142 using FunctionReverse = decltype(&Tape::template statementEvaluateReverse<ActiveType<Tape>>);
143 };
144}
#define CODI_DD(Type, Default)
Abbreviation for CODI_DECLARE_DEFAULT.
Definition macros.hpp:94
CoDiPack - Code Differentiation Package.
Definition codi.hpp:90
Definition directStatementEvaluator.hpp:68
static PrimalTapeStatementFunctions const staticStore
Definition directStatementEvaluator.hpp:73
Full evaluation of the expression in the function handle. Storing in static context.
Definition directStatementEvaluator.hpp:93
T_Real Real
See DirectStatementEvaluator.
Definition directStatementEvaluator.hpp:96
decltype(&Tape::template statementEvaluateReverse< ActiveType< Tape > >) FunctionReverse
Full reverse function type.
Definition directStatementEvaluator.hpp:142
static Real callForward(Handle const &h, Args &&... args)
Definition directStatementEvaluator.hpp:106
static Real callPrimal(Handle const &h, Args &&... args)
Definition directStatementEvaluator.hpp:112
decltype(&Tape::template statementEvaluatePrimal< ActiveType< Tape > >) FunctionPrimal
Full primal function type.
Definition directStatementEvaluator.hpp:138
static Handle createHandle()
Definition directStatementEvaluator.hpp:124
PrimalTapeStatementFunctions const * Handle
Pointer to static storage location.
Definition directStatementEvaluator.hpp:102
static void callReverse(Handle const &h, Args &&... args)
Definition directStatementEvaluator.hpp:118
decltype(&Tape::template statementEvaluateForward< ActiveType< Tape > >) FunctionForward
Full forward function type.
Definition directStatementEvaluator.hpp:134
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