CoDiPack  3.1.0
A Code Differentiation Package
SciComp TU Kaiserslautern
Loading...
Searching...
No Matches
lowLevelFunctionEntry.hpp
1/*
2 * CoDiPack, a Code Differentiation Package
3 *
4 * Copyright (C) 2015-2026 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 <iomanip>
38#include <sstream>
39#include <string>
40#include <vector>
41
42#include "../../config.h"
43#include "../../misc/byteDataView.hpp"
44#include "../../misc/macros.hpp"
45#include "vectorAccessInterface.hpp"
46
48namespace codi {
49
52 Forward,
53 Reverse,
54 Primal,
55 Delete,
56 IterateInputs,
57 IterateOutputs,
58 MaxElement
59 };
60
68 template<typename T_Tape, typename T_Real, typename T_Identifier>
70 using Tape = T_Tape;
71 using Real = CODI_DD(T_Real, double);
72 using Identifier = CODI_DD(T_Identifier, int);
73
75 using FuncEval = void (*)(Tape* tape, ByteDataView& data, VectorAccessInterface<Real, Identifier>* access);
76
78 using FuncDel = void (*)(Tape* tape, ByteDataView& data);
79
81 using IterCallback = void (*)(Identifier* id, void* userData);
83 using FuncIterate = void (*)(Tape* tape, ByteDataView& data, IterCallback func, void* userData);
84
85 private:
86
87 void* functions[(size_t)LowLevelFunctionEntryCallKind::MaxElement];
88 using FunctionTypes =
89 std::tuple<FuncEval, FuncEval, FuncEval, FuncDel, FuncIterate, FuncIterate>;
90
91 public:
92
94 LowLevelFunctionEntry(FuncEval reverse = nullptr, FuncEval forward = nullptr, FuncEval primal = nullptr,
95 FuncDel del = nullptr, FuncIterate iterIn = nullptr, FuncIterate iterOut = nullptr)
96 : functions{(void*)forward, (void*)reverse, (void*)primal, (void*)del, (void*)iterIn, (void*)iterOut} {}
97
99 template<LowLevelFunctionEntryCallKind callType, typename... Args>
100 void call(Args&&... args) const {
101 using FuncType = typename std::tuple_element<(size_t)callType, FunctionTypes>::type;
102 ((FuncType)functions[(size_t)callType])(std::forward<Args>(args)...);
103 }
104
106 template<LowLevelFunctionEntryCallKind callType, typename... Args>
107 bool has(Args&&... args) const {
108 CODI_UNUSED(args...);
109 return nullptr != functions[(size_t)callType];
110 }
111 };
112
113}
#define CODI_DD(Type, Default)
Abbreviation for CODI_DECLARE_DEFAULT.
Definition macros.hpp:97
CoDiPack - Code Differentiation Package.
Definition codi.hpp:97
LowLevelFunctionEntryCallKind
All possible call types for a low level function entry.
Definition lowLevelFunctionEntry.hpp:51
inlinevoid CODI_UNUSED(Args const &...)
Disable unused warnings for an arbitrary number of arguments.
Definition macros.hpp:55
Definition byteDataView.hpp:51
void(*)(Tape *tape, ByteDataView &data, IterCallback func, void *userData) FuncIterate
Call syntax for IterateInputs and IterateOutputs calls.
Definition lowLevelFunctionEntry.hpp:83
LowLevelFunctionEntry(FuncEval reverse=nullptr, FuncEval forward=nullptr, FuncEval primal=nullptr, FuncDel del=nullptr, FuncIterate iterIn=nullptr, FuncIterate iterOut=nullptr)
Constructors.
Definition lowLevelFunctionEntry.hpp:94
void(*)(Tape *tape, ByteDataView &data) FuncDel
Call syntax for Delete calls.
Definition lowLevelFunctionEntry.hpp:78
T_Real Real
See LowLevelFunctionEntry.
Definition lowLevelFunctionEntry.hpp:71
void call(Args &&... args) const
Call the function corresponding to callType with the given arguments.
Definition lowLevelFunctionEntry.hpp:100
T_Tape Tape
See LowLevelFunctionEntry.
Definition lowLevelFunctionEntry.hpp:70
bool has(Args &&... args) const
Check if a function is provided for the callType.
Definition lowLevelFunctionEntry.hpp:107
T_Identifier Identifier
See LowLevelFunctionEntry.
Definition lowLevelFunctionEntry.hpp:72
void(*)(Identifier *id, void *userData) IterCallback
Callback function for the identifier iteration.
Definition lowLevelFunctionEntry.hpp:81
void(*)(Tape *tape, ByteDataView &data, VectorAccessInterface< Real, Identifier > *access) FuncEval
Call syntax for Forward, Reverse, and Primal calls.
Definition lowLevelFunctionEntry.hpp:75
Unified access to the adjoint vector and primal vector in a tape evaluation.
Definition vectorAccessInterface.hpp:94