CoDiPack  3.1.1
A Code Differentiation Package
SciComp TU Kaiserslautern
Loading...
Searching...
No Matches
tagTapeReverse.hpp
1/*
2 * CoDiPack, a Code Differentiation Package
3 *
4 * Copyright (C) 2015-2026 Chair for Scientific Computing (SciComp), RPTU University 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, RPTU University 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, RPTU University Kaiserslautern-Landau:
30 * - Max Sagebaum
31 * - Johannes Blühdorn
32 * - Former members:
33 * - Tim Albring
34 */
35#pragma once
36
37#include "../interfaces/fullTapeInterface.hpp"
38#include "../misc/adjointVectorAccess.hpp"
39#include "tagTapeBase.hpp"
40
42namespace codi {
43
54 template<typename T_Real, typename T_Tag>
55 struct TagTapeReverse : public FullTapeInterface<T_Real, T_Real, TagData<T_Tag>, EmptyPosition, TagData<T_Tag>>,
56 public TagTapeBase<T_Real, T_Tag, T_Real, TagTapeReverse<T_Real, T_Tag>> {
57 using Real = CODI_DD(T_Real, double);
58 using Tag = CODI_DD(T_Tag, int);
59
61 struct TapeTypes {
63 struct IndexManager {
65 using Index = int;
66 };
67 };
68
69 using Gradient = Real;
70 using Identifier = int;
73
75
77
78 private:
79 bool active;
80
81 Real tempPrimal;
82 Gradient tempGradient;
83
84 std::set<TapeParameters> parameters;
85
86 public:
87
89 TagTapeReverse() : Base(), active(), tempPrimal(), tempGradient(), parameters() {}
90
95 using Base::store;
96
97 /*******************************************************************************/
100
102 template<typename Adjoint>
103 void evaluate(Position const& start, Position const& end, Adjoint* data) {
104 CODI_UNUSED(start, end, data);
105 }
106
108 template<typename Adjoint>
109 void evaluateForward(Position const& start, Position const& end, Adjoint* data) {
110 CODI_UNUSED(start, end, data);
111 }
112
114 /*******************************************************************************/
117
119 void writeToFile(std::string const& filename) const {
120 CODI_UNUSED(filename);
121 }
122
124 void readFromFile(std::string const& filename) {
125 CODI_UNUSED(filename);
126 }
127
129 void deleteData() {}
130
132 std::set<TapeParameters> const& getAvailableParameters() const {
133 return parameters;
134 }
135
137 size_t getParameter(TapeParameters parameter) const {
138 CODI_UNUSED(parameter);
139
140 return 0;
141 }
142
144 bool hasParameter(TapeParameters parameter) const {
145 CODI_UNUSED(parameter);
146
147 return false;
148 }
149
151 void setParameter(TapeParameters parameter, size_t value) {
152 CODI_UNUSED(parameter, value);
153 }
154
159
161 template<typename Adjoint>
163 CODI_UNUSED(data);
164 return nullptr;
165 }
166
169 delete access;
170 }
171
173 void swap(TagTapeReverse& other) {
174 std::swap(active, other.active);
175 std::swap(parameters, other.parameters);
176 Base::swap(other);
177 }
178 void resetHard() {}
179
184
186 /*******************************************************************************/
189
191 template<typename Lhs>
197
200 CODI_UNUSED(extFunc);
201 }
202
204 /*******************************************************************************/
207
209 void evaluateForward(Position const& start, Position const& end) {
210 CODI_UNUSED(start, end);
211 }
212
215
217 /*******************************************************************************/
220
222 void setGradient(Identifier const& identifier, Gradient const& gradient,
224 CODI_UNUSED(identifier, gradient, adjointsManagement);
225 }
226
228 Gradient const& getGradient(Identifier const& identifier,
229 AdjointsManagement adjointsManagement = AdjointsManagement::Automatic) const {
230 CODI_UNUSED(identifier, adjointsManagement);
231
232 return tempGradient;
233 }
234
236 Gradient& gradient(Identifier const& identifier,
238 CODI_UNUSED(identifier, adjointsManagement);
239
240 return tempGradient;
241 }
242
244 Gradient const& gradient(Identifier const& identifier,
245 AdjointsManagement adjointsManagement = AdjointsManagement::Automatic) const {
246 CODI_UNUSED(identifier, adjointsManagement);
247
248 return tempGradient;
249 }
250
252 /*******************************************************************************/
255
257 static bool constexpr LinearIndexHandling = true;
258
263
268
270 bool isIdentifierActive(Identifier const& index) const {
271 return index != Base::PassiveTag;
272 }
273
275 template<typename Lhs>
279
281 /*******************************************************************************/
284
286 void pushJacobiManual(Real const& jacobian, Real const& value, ActiveTypeTapeData const& index) {
287 CODI_UNUSED(jacobian, value, index);
288 }
289
291 void storeManual(Real const& lhsValue, ActiveTypeTapeData& lhsIndex, Config::ArgumentSize const& size) {
292 CODI_UNUSED(lhsValue, size);
293
294 Base::setTag(lhsIndex.tag);
295 Base::verifyLhsWrite(lhsValue, lhsIndex, lhsValue, Base::vi);
297 }
298
300 /*******************************************************************************/
303
305 void evaluate(Position const& start, Position const& end) {
306 CODI_UNUSED(start, end);
307 }
308
310 void clearAdjoints(Position const& start, Position const& end) {
311 CODI_UNUSED(start, end);
312 }
313
316 return Position();
317 }
318
321 return Position();
322 }
323
325 void resetTo(Position const& pos, bool resetAdjoints = true) {
326 CODI_UNUSED(pos, resetAdjoints);
327 }
328
330 /*******************************************************************************/
333
335 void evaluateKeepState(Position const& start, Position const& end) {
336 CODI_UNUSED(start, end);
337 }
338
339 void evaluateForwardKeepState(Position const& start, Position const& end) {
340 CODI_UNUSED(start, end);
341 }
342
344 /*******************************************************************************/
347
348 static bool constexpr HasPrimalValues = false;
349 static bool constexpr RequiresPrimalRestore = false;
350
352 void evaluatePrimal(Position const& start, Position const& end) {
353 CODI_UNUSED(start, end);
354 }
355
358
360 void setPrimal(Identifier const& identifier, Real const& gradient) {
361 CODI_UNUSED(identifier, gradient);
362 }
363
365 Real const& getPrimal(Identifier const& identifier) const {
366 CODI_UNUSED(identifier);
367 return tempPrimal;
368 }
369
371 Real& primal(Identifier const& identifier) {
372 CODI_UNUSED(identifier);
373 return tempPrimal;
374 }
375
377 Real const& primal(Identifier const& identifier) const {
378 CODI_UNUSED(identifier);
379 return tempPrimal;
380 }
381
383 void revertPrimals(Position const& pos) {
384 CODI_UNUSED(pos);
385 }
386
388 /*******************************************************************************/
391
393 template<typename Lhs>
395 Base::setTag(value.cast().getTapeData().tag);
396 Base::verifyRegisterValue(value); // verification is mainly for the properties
397 }
398
400 template<typename Lhs>
404
406 void setActive() {
407 active = true;
408 }
409
411 void setPassive() {
412 active = false;
413 }
414
416 bool isActive() const {
417 return active;
418 }
419
421 bool isActive(Identifier const& identifier) const {
422 return identifier != getPassiveIndex();
423 }
424
425 void evaluate() {}
426
429
431 void reset(bool resetAdjoints = true) {
432 CODI_UNUSED(resetAdjoints);
433 }
434
436 template<typename Stream = std::ostream>
437 void printStatistics(Stream& out = std::cout) const {
438 CODI_UNUSED(out);
439 }
440
442 template<typename Stream = std::ostream>
443 void printTableHeader(Stream& out = std::cout) const {
444 CODI_UNUSED(out);
445 }
446
448 template<typename Stream = std::ostream>
449 void printTableRow(Stream& out = std::cout) const {
450 CODI_UNUSED(out);
451 }
452
455 return TapeValues("TagTapeReverse");
456 }
457
459 };
460}
#define CODI_DD(Type, Default)
Abbreviation for CODI_DECLARE_DEFAULT.
Definition macros.hpp:97
uint8_t ArgumentSize
Type for the number of arguments in statements.
Definition config.h:117
typename TraitsImplementation< Type >::PassiveReal PassiveReal
The original computation type that was used in the application.
Definition realTraits.hpp:123
CoDiPack - Code Differentiation Package.
Definition codi.hpp:98
TapeParameters
Configuration options for a tape.
Definition tapeParameters.hpp:52
inlinevoid CODI_UNUSED(Args const &...)
Disable unused warnings for an arbitrary number of arguments.
Definition macros.hpp:55
AdjointsManagement
Policies for management of the tape's interal adjoints.
Definition tapeParameters.hpp:100
@ Automatic
Manage internal adjoints automatically, including locking, bounds checking, and resizing.
Definition tapeParameters.hpp:102
Empty Position with no nested data.
Definition position.hpp:47
User-defined evaluation functions for the taping process.
Definition externalFunction.hpp:118
Full tape interface that supports all features of CoDiPack.
Definition fullTapeInterface.hpp:89
static Index constexpr InactiveIndex
Default inactive index for all index managers.
Definition indexManagerInterface.hpp:87
static Index constexpr InvalidIndex
Default invalid index for all index mangers (max value for unsigned types).
Definition indexManagerInterface.hpp:88
Base class for all CoDiPack lvalue expression.
Definition lhsExpressionInterface.hpp:63
TapeData const & getTapeData() const
Get the data of the tape stored in this lhs expression.
inlineImpl & cast()
Cast to the implementation.
Definition lhsExpressionInterface.hpp:103
Data for a tag.
Definition tagData.hpp:56
Tag tag
Current tag of the value.
Definition tagData.hpp:61
inlinevoid setTag(Tag &tag) const
Definition tagTapeBase.hpp:499
static bool constexpr AllowJacobianOptimization
Definition tagTapeBase.hpp:203
ValidationIndicator< Real, Tag > vi
Definition tagTapeBase.hpp:134
void destroyTapeData(Real &value, ActiveTypeTapeData &data)
Definition tagTapeBase.hpp:214
inlinevoid handleError(ValidationIndicator< Real, Tag > &vi) const
Definition tagTapeBase.hpp:479
inlinevoid verifyRegisterValue(LhsExpressionInterface< Real, Gradient, Impl, Lhs > &value)
Definition tagTapeBase.hpp:438
inlineIdentifier const & getIdentifier(ActiveTypeTapeData const &data)
Definition tagTapeBase.hpp:184
static Tag constexpr PassiveTag
Definition tagTapeBase.hpp:111
void initTapeData(Real &value, ActiveTypeTapeData &data)
Definition tagTapeBase.hpp:207
inlinevoid store(AggregatedActiveType< Aggregated, Type, Lhs > &lhs, ExpressionInterface< Aggregated, Rhs > const &rhs)
Definition tagTapeBase.hpp:220
inlinevoid verifyLhsWrite(Real const &lhsValue, ActiveTypeTapeData const &lhsData, Real const &rhsValue, ValidationIndicator< Real, Tag > &vi)
Definition tagTapeBase.hpp:426
void swap(Impl &other)
Definition tagTapeBase.hpp:167
Required definition for event system.
Definition tagTapeReverse.hpp:63
int Index
Required definition for event system.
Definition tagTapeReverse.hpp:65
Required definition for event system.
Definition tagTapeReverse.hpp:61
TagTapeReverse()
Constructor.
Definition tagTapeReverse.hpp:89
void resetHard()
Do nothing.
Definition tagTapeReverse.hpp:178
void deleteAdjointVector()
Do nothing.
Definition tagTapeReverse.hpp:180
void clearAdjoints(Position const &start, Position const &end)
Do nothing.
Definition tagTapeReverse.hpp:310
bool hasParameter(TapeParameters parameter) const
Do nothing.
Definition tagTapeReverse.hpp:144
void evaluate()
Do nothing.
Definition tagTapeReverse.hpp:425
Real const & primal(Identifier const &identifier) const
Do nothing.
Definition tagTapeReverse.hpp:377
void deleteVectorAccess(VectorAccessInterface< Real, Identifier > *access)
Do nothing.
Definition tagTapeReverse.hpp:168
void printTableRow(Stream &out=std::cout) const
Do nothing.
Definition tagTapeReverse.hpp:449
void resizeAdjointVector()
Do nothing.
Definition tagTapeReverse.hpp:181
void deleteData()
Do nothing.
Definition tagTapeReverse.hpp:129
void setPassive()
Set tape to passive.
Definition tagTapeReverse.hpp:411
Identifier getInvalidIndex() const
-1 id.
Definition tagTapeReverse.hpp:265
void evaluateForward(Position const &start, Position const &end, Adjoint *data)
Do nothing.
Definition tagTapeReverse.hpp:109
Real & primal(Identifier const &identifier)
Do nothing.
Definition tagTapeReverse.hpp:371
TapeValues getTapeValues() const
Do nothing.
Definition tagTapeReverse.hpp:454
void setParameter(TapeParameters parameter, size_t value)
Do nothing.
Definition tagTapeReverse.hpp:151
TagData< Tag > ActiveTypeTapeData
See TapeTypesInterface.
Definition tagTapeReverse.hpp:71
int Identifier
See TapeTypesInterface.
Definition tagTapeReverse.hpp:70
Gradient const & getGradient(Identifier const &identifier, AdjointsManagement adjointsManagement=AdjointsManagement::Automatic) const
Verify tag.
Definition tagTapeReverse.hpp:228
VectorAccessInterface< Real, Identifier > * createVectorAccessCustomAdjoints(Adjoint *data)
Do nothing.
Definition tagTapeReverse.hpp:162
bool isActive() const
Check if tape is active.
Definition tagTapeReverse.hpp:416
Gradient & gradient(Identifier const &identifier, AdjointsManagement adjointsManagement=AdjointsManagement::Automatic)
Verify tag.
Definition tagTapeReverse.hpp:236
void setActive()
Set tape to active.
Definition tagTapeReverse.hpp:406
void endUseAdjointVector()
Do nothing.
Definition tagTapeReverse.hpp:183
Position getPosition() const
Do nothing.
Definition tagTapeReverse.hpp:315
void clearAdjoints()
Do nothing.
Definition tagTapeReverse.hpp:428
void pushJacobiManual(Real const &jacobian, Real const &value, ActiveTypeTapeData const &index)
Do nothing.
Definition tagTapeReverse.hpp:286
size_t getParameter(TapeParameters parameter) const
Do nothing.
Definition tagTapeReverse.hpp:137
Identifier getPassiveIndex() const
Zero id.
Definition tagTapeReverse.hpp:260
static bool constexpr LinearIndexHandling
Behave as linear index handler.
Definition tagTapeReverse.hpp:257
void revertPrimals(Position const &pos)
Do nothing.
Definition tagTapeReverse.hpp:383
void pushExternalFunction(ExternalFunction< TagTapeReverse > const &extFunc)
Do nothing.
Definition tagTapeReverse.hpp:199
void evaluatePrimal()
Do nothing.
Definition tagTapeReverse.hpp:357
T_Real Real
See TagTapeReverse.
Definition tagTapeReverse.hpp:57
void registerOutput(LhsExpressionInterface< Real, Gradient, TagTapeReverse, Lhs > &value)
Verify tag.
Definition tagTapeReverse.hpp:401
void setPrimal(Identifier const &identifier, Real const &gradient)
Do nothing.
Definition tagTapeReverse.hpp:360
static bool constexpr HasPrimalValues
No primal values.
Definition tagTapeReverse.hpp:348
Real registerExternalFunctionOutput(LhsExpressionInterface< Real, Gradient, TagTapeReverse, Lhs > &value)
Verifies tag properties.
Definition tagTapeReverse.hpp:192
void evaluateForward()
Do nothing.
Definition tagTapeReverse.hpp:214
void reset(bool resetAdjoints=true)
Do nothing.
Definition tagTapeReverse.hpp:431
Real const & getPrimal(Identifier const &identifier) const
Do nothing.
Definition tagTapeReverse.hpp:365
Position getZeroPosition() const
Do nothing.
Definition tagTapeReverse.hpp:320
void beginUseAdjointVector()
Do nothing.
Definition tagTapeReverse.hpp:182
void storeManual(Real const &lhsValue, ActiveTypeTapeData &lhsIndex, Config::ArgumentSize const &size)
Set tag on lhs.
Definition tagTapeReverse.hpp:291
void swap(TagTapeReverse &other)
Swap members.
Definition tagTapeReverse.hpp:173
std::set< TapeParameters > const & getAvailableParameters() const
Empty set.
Definition tagTapeReverse.hpp:132
void evaluateKeepState(Position const &start, Position const &end)
Do nothing.
Definition tagTapeReverse.hpp:335
Gradient const & gradient(Identifier const &identifier, AdjointsManagement adjointsManagement=AdjointsManagement::Automatic) const
Verify tag.
Definition tagTapeReverse.hpp:244
void evaluate(Position const &start, Position const &end, Adjoint *data)
Do nothing.
Definition tagTapeReverse.hpp:103
void writeToFile(std::string const &filename) const
Do nothing.
Definition tagTapeReverse.hpp:119
void evaluate(Position const &start, Position const &end)
Do nothing.
Definition tagTapeReverse.hpp:305
T_Tag Tag
See TagTapeReverse.
Definition tagTapeReverse.hpp:58
RealTraits::PassiveReal< Real > PassiveReal
Basic computation type.
Definition tagTapeReverse.hpp:74
void setGradient(Identifier const &identifier, Gradient const &gradient, AdjointsManagement adjointsManagement=AdjointsManagement::Automatic)
Verify tag.
Definition tagTapeReverse.hpp:222
void deactivateValue(LhsExpressionInterface< Real, Gradient, TagTapeReverse, Lhs > &value)
Set tag to passive.
Definition tagTapeReverse.hpp:276
void evaluateForward(Position const &start, Position const &end)
Do nothing.
Definition tagTapeReverse.hpp:209
VectorAccessInterface< Real, Identifier > * createVectorAccess()
Do nothing.
Definition tagTapeReverse.hpp:156
void resetTo(Position const &pos, bool resetAdjoints=true)
Do nothing.
Definition tagTapeReverse.hpp:325
void evaluateForwardKeepState(Position const &start, Position const &end)
Do nothing.
Definition tagTapeReverse.hpp:339
void evaluatePrimal(Position const &start, Position const &end)
Do nothing.
Definition tagTapeReverse.hpp:352
void registerInput(LhsExpressionInterface< Real, Gradient, TagTapeReverse, Lhs > &value)
Verify value properties.
Definition tagTapeReverse.hpp:394
void printStatistics(Stream &out=std::cout) const
Do nothing.
Definition tagTapeReverse.hpp:437
bool isActive(Identifier const &identifier) const
Default check.
Definition tagTapeReverse.hpp:421
bool isIdentifierActive(Identifier const &index) const
Verify tag.
Definition tagTapeReverse.hpp:270
TagTapeBase< T_Real, T_Tag, T_Real, TagTapeReverse > Base
Base class abbreviation.
Definition tagTapeReverse.hpp:76
Real Gradient
See TapeTypesInterface.
Definition tagTapeReverse.hpp:69
static bool constexpr RequiresPrimalRestore
No primal values.
Definition tagTapeReverse.hpp:349
EmptyPosition Position
See TapeTypesInterface.
Definition tagTapeReverse.hpp:72
void readFromFile(std::string const &filename)
Do nothing.
Definition tagTapeReverse.hpp:124
void printTableHeader(Stream &out=std::cout) const
Do nothing.
Definition tagTapeReverse.hpp:443
Tape information that can be printed in a pretty print format or a table format.
Definition tapeValues.hpp:75
Unified access to the adjoint vector and primal vector in a tape evaluation.
Definition vectorAccessInterface.hpp:94