CoDiPack  2.2.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-2024 Chair for Scientific Computing (SciComp), University of Kaiserslautern-Landau
5 * Homepage: http://www.scicomp.uni-kl.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://www.scicomp.uni-kl.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 MaxElement
57 };
58
66 template<typename T_Tape, typename T_Real, typename T_Identifier>
68 using Tape = T_Tape;
69 using Real = CODI_DD(T_Real, double);
70 using Identifier = CODI_DD(T_Identifier, int);
71
73 using FuncEval = void (*)(Tape* tape, ByteDataView& data, VectorAccessInterface<Real, Identifier>* access);
74
76 using FuncDel = void (*)(Tape* tape, ByteDataView& data);
77
78 private:
79
80 void* functions[(size_t)LowLevelFunctionEntryCallKind::MaxElement];
81 using FunctionTypes = std::tuple<FuncEval, FuncEval, FuncEval, FuncDel>;
82
83 public:
84
86 LowLevelFunctionEntry(FuncEval reverse = nullptr, FuncEval forward = nullptr, FuncEval primal = nullptr,
87 FuncDel del = nullptr)
88 : functions{(void*)forward, (void*)reverse, (void*)primal, (void*)del} {}
89
91 template<LowLevelFunctionEntryCallKind callType, typename... Args>
92 void call(Args&&... args) const {
93 using FuncType = typename std::tuple_element<(size_t)callType, FunctionTypes>::type;
94 ((FuncType)functions[(size_t)callType])(std::forward<Args>(args)...);
95 }
96
98 template<LowLevelFunctionEntryCallKind callType, typename... Args>
99 bool has(Args&&... args) const {
100 return nullptr != functions[(size_t)callType];
101 }
102 };
103
104}
#define CODI_DD(Type, Default)
Abbreviation for CODI_DECLARE_DEFAULT.
Definition: macros.hpp:94
CoDiPack - Code Differentiation Package.
Definition: codi.hpp:90
LowLevelFunctionEntryCallKind
All possible call types for a low level function entry.
Definition: lowLevelFunctionEntry.hpp:51
Definition: byteDataView.hpp:51
Low level function entry on the tape. See LowLevelFunctionTapeInterface for details.
Definition: lowLevelFunctionEntry.hpp:67
void(*)(Tape *tape, ByteDataView &data) FuncDel
Call syntax for Delete calls.
Definition: lowLevelFunctionEntry.hpp:76
T_Identifier Identifier
See LowLevelFunctionEntry.
Definition: lowLevelFunctionEntry.hpp:70
T_Real Real
See LowLevelFunctionEntry.
Definition: lowLevelFunctionEntry.hpp:69
void call(Args &&... args) const
Call the function corresponding to callType with the given arguments.
Definition: lowLevelFunctionEntry.hpp:92
T_Tape Tape
See LowLevelFunctionEntry.
Definition: lowLevelFunctionEntry.hpp:68
bool has(Args &&... args) const
Check if a function is provided for the callType.
Definition: lowLevelFunctionEntry.hpp:99
LowLevelFunctionEntry(FuncEval reverse=nullptr, FuncEval forward=nullptr, FuncEval primal=nullptr, FuncDel del=nullptr)
Constructors.
Definition: lowLevelFunctionEntry.hpp:86
void(*)(Tape *tape, ByteDataView &data, VectorAccessInterface< Real, Identifier > *access) FuncEval
Call syntax for Forward, Reverse, and Primal calls.
Definition: lowLevelFunctionEntry.hpp:73
Unified access to the adjoint vector and primal vector in a tape evaluation.
Definition: vectorAccessInterface.hpp:91