CoDiPack  3.0.0
A Code Differentiation Package
SciComp TU Kaiserslautern
Loading...
Searching...
No Matches
jacobianBaseTape.hpp
1/*
2 * CoDiPack, a Code Differentiation Package
3 *
4 * Copyright (C) 2015-2025 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 <cmath>
39#include <fstream>
40#include <type_traits>
41
42#include "../config.h"
43#include "../expressions/aggregate/aggregatedActiveType.hpp"
44#include "../expressions/aggregate/arrayAccessExpression.hpp"
45#include "../expressions/lhsExpressionInterface.hpp"
46#include "../expressions/logic/compileTimeTraversalLogic.hpp"
47#include "../expressions/logic/helpers/forEachLeafLogic.hpp"
48#include "../expressions/logic/helpers/jacobianComputationLogic.hpp"
49#include "../expressions/logic/traversalLogic.hpp"
50#include "../expressions/referenceActiveType.hpp"
51#include "../misc/macros.hpp"
52#include "../misc/mathUtility.hpp"
53#include "../misc/memberStore.hpp"
54#include "../traits/adjointVectorTraits.hpp"
55#include "../traits/computationTraits.hpp"
56#include "../traits/expressionTraits.hpp"
57#include "commonTapeImplementation.hpp"
58#include "data/chunk.hpp"
59#include "data/chunkedData.hpp"
60#include "indices/indexManagerInterface.hpp"
61#include "io/tapeReaderWriterInterface.hpp"
62#include "misc/adjointVectorAccess.hpp"
63#include "misc/duplicateJacobianRemover.hpp"
64#include "misc/localAdjoints.hpp"
65
67namespace codi {
68
78 template<typename T_Real, typename T_Gradient, typename T_IndexManager, template<typename, typename> class T_Data,
79 template<typename, typename, typename> class T_Adjoints = LocalAdjoints>
81 public:
82
83 using Real = CODI_DD(T_Real, double);
84 using Gradient = CODI_DD(T_Gradient, double);
86 template<typename Chunk, typename Nested>
87 using Data = CODI_DD(CODI_T(T_Data<Chunk, Nested>),
89
90 using Identifier = typename IndexManager::Index;
91
93 template<typename Impl>
94 using Adjoints = CODI_DD(CODI_T(T_Adjoints<Gradient, Identifier, Impl>),
96
97 static bool constexpr IsLinearIndexHandler = IndexManager::IsLinear;
98 static bool constexpr IsStaticIndexHandler =
99 IndexManager::NeedsStaticStorage;
100
103 using StatementChunk = typename std::conditional<IsLinearIndexHandler, Chunk1<Config::ArgumentSize>,
106
109
111 };
112
129 template<typename T_TapeTypes, typename T_Impl>
130 struct JacobianBaseTape : public CommonTapeImplementation<T_TapeTypes, T_Impl> {
131 public:
132
136 using Impl = CODI_DD(T_Impl, CODI_DEFAULT_TAPE);
137
139 friend Base;
140
141 using Real = typename TapeTypes::Real;
142 using Gradient = typename TapeTypes::Gradient;
143 using IndexManager = typename TapeTypes::IndexManager;
144 using Identifier = typename TapeTypes::Identifier;
145
146 using StatementData = typename TapeTypes::StatementData;
147 using JacobianData = typename TapeTypes::JacobianData;
148
149 using Adjoints = typename TapeTypes::template Adjoints<Impl>;
150
152
153 using NestedPosition = typename JacobianData::Position;
154 using Position = typename Base::Position;
155
157 template<typename AdjointVector>
159
160 static bool constexpr AllowJacobianOptimization = true;
161 static bool constexpr HasPrimalValues = false;
162
163 static bool constexpr LinearIndexHandling =
164 TapeTypes::IsLinearIndexHandler;
165 static bool constexpr RequiresPrimalRestore = false;
166
167 protected:
168
169#if CODI_RemoveDuplicateJacobianArguments
172#endif
173
177
179
180 private:
181
182 CODI_INLINE Impl const& cast() const {
183 return static_cast<Impl const&>(*this);
184 }
185
186 CODI_INLINE Impl& cast() {
187 return static_cast<Impl&>(*this);
188 }
189
190 protected:
191
192 /*******************************************************************************/
195
197 template<typename... Args>
198 static void internalEvaluateForward_EvalStatements(Args&&... args);
199
201 template<typename... Args>
202 static void internalEvaluateReverse_EvalStatements(Args&&... args);
203
205 void pushStmtData(Identifier const& index, Config::ArgumentSize const& numberOfArguments);
206
208
209 public:
210
213 : Base(),
215 jacobianSorter(),
216#endif
217 indexManager(0), // Reserve the zero index.
218 statementData(Config::ChunkSize),
219 jacobianData(std::max(Config::ChunkSize, Config::MaxArgumentSize)), // Chunk must be large enough to store
220 // data for all arguments of one
221 // statement.
222 adjoints(1) // Ensure that adjoint[0] exists, see its use in gradient() const.
223
224 {
225 statementData.setNested(&indexManager.get());
226 jacobianData.setNested(&statementData);
227
229
234 }
235
236 /*******************************************************************************/
239
243 if (AdjointsManagement::Automatic == adjointsManagement) {
244 checkAdjointSize(identifier);
245 }
246
247 codiAssert(identifier < (Identifier)adjoints.size());
248
249 return adjoints[identifier];
250 }
251
254 Identifier const& identifier, AdjointsManagement adjointsManagement = AdjointsManagement::Automatic) const {
255 codiAssert(identifier < (Identifier)adjoints.size());
256
257 if (AdjointsManagement::Automatic == adjointsManagement && identifier >= (Identifier)adjoints.size()) {
258 return adjoints[0];
259 } else {
260 return adjoints[identifier];
261 }
262 }
263
265 /*******************************************************************************/
268
270 template<typename Real>
271 CODI_INLINE void initIdentifier(Real& value, Identifier& identifier) {
272 CODI_UNUSED(value);
273
274 identifier = IndexManager::InactiveIndex;
275 }
276
278 template<typename Real>
279 CODI_INLINE void destroyIdentifier(Real& value, Identifier& identifier) {
280 CODI_UNUSED(value);
281
282 indexManager.get().template freeIndex<Impl>(identifier);
283 }
284
286
287 protected:
288
290 struct PushJacobianLogic : public JacobianComputationLogic<PushJacobianLogic> {
291 public:
293 template<typename Node, typename DataVector>
294 CODI_INLINE void handleJacobianOnActive(Node const& node, Real jacobian, DataVector& dataVector) {
295 if (CODI_ENABLE_CHECK(Config::CheckZeroIndex, 0 != node.getIdentifier())) {
298 dataVector.pushData(jacobian, node.getIdentifier());
299 }
300 }
301 }
302 }
303
305 template<typename Type, typename DataVector>
307 DataVector& dataVector) {
308 CODI_UNUSED(dataVector);
309
311 // Do a delayed push for these leaf nodes, accumulate the jacobian in the local member.
312 node.jacobian += jacobian;
313 }
314 }
315 };
316
318 struct PushDelayedJacobianLogic : public ForEachLeafLogic<PushDelayedJacobianLogic> {
319 public:
320
322 template<typename Type, typename DataVector>
323 CODI_INLINE void handleActive(ReferenceActiveType<Type> const& node, DataVector& dataVector) {
324 if (CODI_ENABLE_CHECK(Config::CheckZeroIndex, 0 != node.getIdentifier())) {
326 dataVector.pushData(node.jacobian, node.getIdentifier());
327
328 // Reset the jacobian here such that it is not pushed multiple times and ready for the next store.
329 node.jacobian = Real();
330 }
331 }
332 }
333
335 };
336
338 template<typename Rhs>
340 PushJacobianLogic pushJacobianLogic;
341 PushDelayedJacobianLogic pushDelayedJacobianLogic;
342
343#if CODI_RemoveDuplicateJacobianArguments
344 auto& insertVector = jacobianSorter;
345#else
346 auto& insertVector = jacobianData;
347#endif
348
349 pushJacobianLogic.eval(rhs.cast(), Real(1.0), insertVector);
350 pushDelayedJacobianLogic.eval(rhs.cast(), insertVector);
351
352#if CODI_RemoveDuplicateJacobianArguments
353 jacobianSorter.storeData(jacobianData);
354#endif
355 }
356
357 public:
358
360
363 template<typename Aggregated, typename Type, typename Lhs, typename Rhs>
366 using AggregatedTraits = RealTraits::AggregatedTypeTraits<Aggregated>;
367
368 int constexpr Elements = AggregatedTraits::Elements;
369
370 bool freeAndUpdate = true;
371
374
376
377 statementData.reserveItems(Elements);
378
379 // Push the Jacobians
380 typename JacobianData::InternalPosHandle jacobianStart = jacobianData.reserveItems(MaxArgs * Elements);
381 std::array<size_t, Elements> numberOfArguments;
382 size_t totalNumberOfArguments = 0;
385
386 size_t newTotalNumberOfArguments = jacobianData.getPushedDataCount(jacobianStart);
387 numberOfArguments[i.value] = newTotalNumberOfArguments - totalNumberOfArguments;
388 totalNumberOfArguments = newTotalNumberOfArguments;
389 });
390
391 if (0 != totalNumberOfArguments) {
392 freeAndUpdate = false;
393
394 // This implementation avoids the creation of self reference adjoint equations. See paper (TODO: add when
395 // released.) Section 4.1 for a detailed description. In short: For e.g. a = a * b with complex numbers
396 // the adjoint assignment of a.i modifies \bar a.r which is used in the adjoint assignment of a.r. This is
397 // wrong since the original value of \bar a.r needs to be used. If now self references are present, this
398 // problem does not arise.
399
400 // Create new identifiers to prevent self references.
401 std::array<Identifier, Elements> identifiers = {};
403 if (CODI_ENABLE_CHECK(Config::CheckEmptyStatements, 0 != numberOfArguments[i.value])) {
404 indexManager.get().template assignIndex<Impl>(identifiers[i.value]);
405 }
406 });
407
408 // Update all lhs entries
409 Aggregated real = rhs.cast().getValue();
410 size_t eventJacobianOffset = 0;
411
413 indexManager.get().template freeIndex<Impl>(lhs.values[i.value].getIdentifier());
414
415 if (CODI_ENABLE_CHECK(Config::CheckEmptyStatements, 0 != numberOfArguments[i.value])) {
416 lhs.values[i.value].getIdentifier() = identifiers[i.value];
417 cast().pushStmtData(lhs.values[i.value].getIdentifier(),
418 (Config::ArgumentSize)numberOfArguments[i.value]);
419
421 Real* jacobians;
422 Identifier* rhsIdentifiers;
423 jacobianData.getDataPointers(jacobians, rhsIdentifiers);
424 jacobians -= totalNumberOfArguments;
425 rhsIdentifiers -= totalNumberOfArguments;
426
428 cast(), lhs.values[i.value].getIdentifier(),
429 AggregatedTraits::template arrayAccess<i.value>(real), numberOfArguments[i.value],
430 &rhsIdentifiers[eventJacobianOffset], &jacobians[eventJacobianOffset]);
431
432 eventJacobianOffset += numberOfArguments[i.value];
433 }
434 }
435
436 lhs.values[i.value].value() = AggregatedTraits::template arrayAccess<i.value>(real);
437 });
438 }
439 }
440
441 if (freeAndUpdate) {
442 Aggregated real = rhs.cast().getValue();
443
445 lhs.values[i.value].value() = AggregatedTraits::template arrayAccess<i.value>(real);
446 indexManager.get().template freeIndex<Impl>(lhs.values[i.value].getIdentifier());
447 });
448 }
449 }
450
453 template<typename Aggregated, typename Type, typename Lhs, typename Rhs>
456 using AggregatedTraits = RealTraits::AggregatedTypeTraits<Aggregated>;
457
458 int constexpr Elements = AggregatedTraits::Elements;
459
461 if (IndexManager::CopyNeedsStatement || !Config::CopyOptimization) {
462 store(lhs, static_cast<ExpressionInterface<Aggregated, Rhs> const&>(rhs));
463 return;
464 } else {
466 indexManager.get().template copyIndex<Impl>(lhs.values[i.value].getIdentifier(),
467 rhs.values[i.value].getIdentifier());
468 });
469 }
470 } else {
472 indexManager.get().template freeIndex<Impl>(lhs.values[i.value].getIdentifier());
473 });
474 }
475
477 lhs.values[i.value].value() = rhs.values[i.value].getValue();
478 });
479 }
480
482 template<typename Lhs, typename Rhs>
486 size_t constexpr MaxArgs = ExpressionTraits::NumberOfActiveTypeArguments<Rhs>::template eval<Rhs>();
487
489
490 statementData.reserveItems(1);
491 typename JacobianData::InternalPosHandle jacobianStart = jacobianData.reserveItems(MaxArgs);
492
493 pushJacobians(rhs);
494
495 size_t numberOfArguments = jacobianData.getPushedDataCount(jacobianStart);
496 if (CODI_ENABLE_CHECK(Config::CheckEmptyStatements, 0 != numberOfArguments)) {
497 indexManager.get().template assignIndex<Impl>(lhs.cast().getIdentifier());
498 cast().pushStmtData(lhs.cast().getIdentifier(), (Config::ArgumentSize)numberOfArguments);
499
501 Real* jacobians;
502 Identifier* rhsIdentifiers;
503 jacobianData.getDataPointers(jacobians, rhsIdentifiers);
504 jacobians -= numberOfArguments;
505 rhsIdentifiers -= numberOfArguments;
506
508 rhs.cast().getValue(), numberOfArguments,
509 rhsIdentifiers, jacobians);
510 }
511 } else {
512 indexManager.get().template freeIndex<Impl>(lhs.cast().getIdentifier());
513 }
514 } else {
515 indexManager.get().template freeIndex<Impl>(lhs.cast().getIdentifier());
516 }
517
518 lhs.cast().value() = rhs.cast().getValue();
519 }
520
523 template<typename Lhs, typename Rhs>
527 if (IndexManager::CopyNeedsStatement || !Config::CopyOptimization) {
528 store<Lhs, Rhs>(lhs, static_cast<ExpressionInterface<Real, Rhs> const&>(rhs));
529 return;
530 } else {
531 indexManager.get().template copyIndex<Impl>(lhs.cast().getIdentifier(), rhs.cast().getIdentifier());
532 }
533 } else {
534 indexManager.get().template freeIndex<Impl>(lhs.cast().getIdentifier());
535 }
536
537 lhs.cast().value() = rhs.cast().getValue();
538 }
539
542 template<typename Lhs>
544 indexManager.get().template freeIndex<Impl>(lhs.cast().getIdentifier());
545
546 lhs.cast().value() = rhs;
547 }
548
550 /*******************************************************************************
551 * Protected helper function for ReverseTapeInterface
552 */
553
554 protected:
555
557 template<typename Lhs>
559 bool unusedIndex) {
560 if (TapeTypes::IsLinearIndexHandler) {
561 statementData.reserveItems(1);
562 }
563
564 if (unusedIndex) {
565 indexManager.get().template assignUnusedIndex<Impl>(value.cast().getIdentifier());
566 } else {
567 indexManager.get().template assignIndex<Impl>(value.cast().getIdentifier());
568 }
569
570 if (TapeTypes::IsLinearIndexHandler) {
571 cast().pushStmtData(value.cast().getIdentifier(), Config::StatementInputTag);
572 }
573 }
574
575 public:
576
577 /*******************************************************************************/
580
582 template<typename Lhs>
584 cast().internalRegisterInput(value, true);
585 EventSystem<Impl>::notifyTapeRegisterInputListeners(cast(), value.cast().value(), value.cast().getIdentifier());
586 }
587
590 if (AdjointsManagement::Automatic == adjointsManagement) {
591 adjoints.beginUse();
592 }
593
594 adjoints.zeroAll(indexManager.get().getLargestCreatedIndex());
595
596 if (AdjointsManagement::Automatic == adjointsManagement) {
597 adjoints.endUse();
598 }
599 }
600
602
603 protected:
604
607 std::string name;
608 if (TapeTypes::IsLinearIndexHandler) {
609 name = "CoDi Tape Statistics ( JacobianLinearTape )";
610 } else {
611 name = "CoDi Tape Statistics ( JacobianReuseTape )";
612 }
613 TapeValues values = TapeValues(name);
614
615 size_t nAdjoints = indexManager.get().getLargestCreatedIndex();
616 double memoryAdjoints = static_cast<double>(nAdjoints) * static_cast<double>(sizeof(Gradient));
617
618 bool constexpr globalAdjoints = InternalAdjointVectorTraits::IsGlobal<Adjoints>::value;
619 TapeValues::LocalReductionOperation constexpr operation =
620 globalAdjoints ? TapeValues::LocalReductionOperation::Max : TapeValues::LocalReductionOperation::Sum;
621
622 values.addSection("Adjoint vector");
623 values.addUnsignedLongEntry("Number of adjoints", nAdjoints, operation);
624 values.addDoubleEntry("Memory allocated", memoryAdjoints, operation, true, true);
625
626 values.addSection("Index manager");
627 indexManager.get().addToTapeValues(values);
628
629 values.addSection("Statement entries");
630 statementData.addToTapeValues(values);
631 values.addSection("Jacobian entries");
632 jacobianData.addToTapeValues(values);
633
634 return values;
635 }
636
637 /******************************************************************************
638 * Protected helper function for CustomAdjointVectorEvaluationTapeInterface
639 */
640
641 protected:
642
644 template<typename AdjointVector>
646 AdjointVector& CODI_RESTRICT adjointVector,
648 Config::ArgumentSize const& CODI_RESTRICT numberOfArguments, size_t& CODI_RESTRICT curJacobianPos,
649 Real const* CODI_RESTRICT const rhsJacobians, Identifier const* CODI_RESTRICT const rhsIdentifiers) {
650 size_t endJacobianPos = curJacobianPos - numberOfArguments;
651
653 while (endJacobianPos < curJacobianPos) CODI_Likely {
654 curJacobianPos -= 1;
655 adjointVector[rhsIdentifiers[curJacobianPos]] += rhsJacobians[curJacobianPos] * lhsAdjoint;
656 }
657 } else CODI_Unlikely {
658 curJacobianPos = endJacobianPos;
659 }
660 }
661
663 CODI_WRAP_FUNCTION_TEMPLATE(Wrap_internalEvaluateReverse_EvalStatements,
665
667 template<typename AdjointVector>
668 CODI_INLINE static void incrementTangents(AdjointVector const& CODI_RESTRICT adjointVector,
670 Config::ArgumentSize const& numberOfArguments,
671 size_t& CODI_RESTRICT curJacobianPos,
672 Real const* CODI_RESTRICT const rhsJacobians,
673 Identifier const* CODI_RESTRICT const rhsIdentifiers) {
674 size_t endJacobianPos = curJacobianPos + numberOfArguments;
675
676 while (curJacobianPos < endJacobianPos) CODI_Likely {
677 lhsAdjoint += rhsJacobians[curJacobianPos] * adjointVector[rhsIdentifiers[curJacobianPos]];
678 curJacobianPos += 1;
679 }
680 }
681
683 CODI_WRAP_FUNCTION_TEMPLATE(Wrap_internalEvaluateForward_EvalStatements,
685
686 public:
687
690
691 using Base::evaluate;
692
694 template<typename AdjointVector>
695 CODI_NO_INLINE void evaluate(Position const& start, Position const& end, AdjointVector&& data) {
696 VectorAccess<AdjointVector> adjointWrapper(data);
697
699 cast(), start, end, &adjointWrapper, EventHints::EvaluationKind::Reverse, EventHints::Endpoint::Begin);
700
701 Wrap_internalEvaluateReverse_EvalStatements<AdjointVector> evalFunc;
702 Base::llfByteData.evaluateReverse(start, end, evalFunc, cast(), std::forward<AdjointVector>(data));
703
704 EventSystem<Impl>::notifyTapeEvaluateListeners(cast(), start, end, &adjointWrapper,
705 EventHints::EvaluationKind::Reverse, EventHints::Endpoint::End);
706 }
707
709 template<typename AdjointVector>
710 CODI_NO_INLINE void evaluateForward(Position const& start, Position const& end, AdjointVector&& data) {
711 VectorAccess<AdjointVector> adjointWrapper(data);
712
714 cast(), start, end, &adjointWrapper, EventHints::EvaluationKind::Forward, EventHints::Endpoint::Begin);
715
716 Wrap_internalEvaluateForward_EvalStatements<AdjointVector> evalFunc;
717 Base::llfByteData.evaluateForward(start, end, evalFunc, cast(), std::forward<AdjointVector>(data));
718
719 EventSystem<Impl>::notifyTapeEvaluateListeners(cast(), start, end, &adjointWrapper,
720 EventHints::EvaluationKind::Forward, EventHints::Endpoint::End);
721 }
722
725 return adjoints.data();
726 }
727
729 /*******************************************************************************/
732
734 CODI_INLINE void swap(Impl& other) {
735 // Index manager does not need to be swapped, it is either static or swapped with the vector data.
736 // Vectors are swapped recursively in the base class.
737
738 adjoints.swap(other.adjoints);
739
740 Base::swap(other);
741 }
742
745 adjoints.resize(1);
746 }
747
750 checkAdjointSize(indexManager.get().getLargestCreatedIndex());
751 }
752
755 adjoints.beginUse();
756 }
757
760 adjoints.endUse();
761 }
762
764 size_t getParameter(TapeParameters parameter) const {
765 switch (parameter) {
767 return adjoints.size();
768 break;
770 return jacobianData.getDataSize();
771 break;
773 return indexManager.get().getLargestCreatedIndex();
774 break;
776 return statementData.getDataSize();
777 default:
778 return Base::getParameter(parameter);
779 break;
780 }
781 }
782
784 void setParameter(TapeParameters parameter, size_t value) {
785 switch (parameter) {
787 adjoints.resize(value);
788 break;
790 jacobianData.resize(value);
791 break;
793 CODI_EXCEPTION("Tried to set a get only parameter.");
794 break;
796 statementData.resize(value);
797 break;
798 default:
799 Base::setParameter(parameter, value);
800 break;
801 }
802 }
803
807 }
808
810 template<typename AdjointVector>
814
817 template<typename Adjoint>
821
824 delete access;
825 }
826
828 /*******************************************************************************/
831
833 template<typename Lhs>
835 cast().internalRegisterInput(value, false);
836
837 return Real();
838 }
839
841 /*******************************************************************************/
844
846
848 void evaluateForward(Position const& start, Position const& end,
850 if (AdjointsManagement::Automatic == adjointsManagement) {
851 checkAdjointSize(indexManager.get().getLargestCreatedIndex());
852 adjoints.beginUse();
853 }
854
855 codiAssert(indexManager.get().getLargestCreatedIndex() < (Identifier)adjoints.size());
856
857 cast().evaluateForward(start, end, adjoints.data());
858
859 if (AdjointsManagement::Automatic == adjointsManagement) {
860 adjoints.endUse();
861 }
862 }
863
865 /*******************************************************************************/
868
870 void pushJacobianManual(Real const& jacobian, Real const& value, Identifier const& index) {
871 CODI_UNUSED(value);
872
873 cast().incrementManualPushCounter();
874
875 jacobianData.pushData(jacobian, index);
876
878 if (this->manualPushCounter == this->manualPushGoal) {
879 // emit statement event
880 Real* jacobians;
881 Identifier* rhsIdentifiers;
882 jacobianData.getDataPointers(jacobians, rhsIdentifiers);
883 jacobians -= this->manualPushGoal;
884 rhsIdentifiers -= this->manualPushGoal;
885
888 rhsIdentifiers, jacobians);
889 }
890 }
891 }
892
894 void storeManual(Real const& lhsValue, Identifier& lhsIndex, Config::ArgumentSize const& size) {
895 CODI_UNUSED(lhsValue);
896 Impl& impl = cast();
897
899
900 statementData.reserveItems(1);
901 jacobianData.reserveItems(size);
902
903 indexManager.get().template assignIndex<Impl>(lhsIndex);
904 impl.pushStmtData(lhsIndex, (Config::ArgumentSize)size);
905
906 impl.initializeManualPushData(lhsValue, lhsIndex, size);
907 }
908
910 /*******************************************************************************/
913
917 void createStatementManual(Real const& lhsValue, Identifier& lhsIndex, Config::ArgumentSize const& size,
918 Real const* jacobians, Identifier const* rhsIdentifiers) {
919 CODI_UNUSED(lhsValue);
920 Impl& impl = cast();
921
922 statementData.reserveItems(1);
923
924 if (Config::StatementInputTag == size && TapeTypes::IsLinearIndexHandler) CODI_Unlikely {
925 impl.pushStmtData(lhsIndex, (Config::ArgumentSize)size);
926 } else CODI_Likely {
927 jacobianData.reserveItems(size);
928 impl.pushStmtData(lhsIndex, (Config::ArgumentSize)size);
929 impl.initializeManualPushData(lhsValue, lhsIndex, size);
930 // Record the rhs of the statement.
931 for (size_t rhsCount = 0; rhsCount < size; rhsCount++) {
932 cast().incrementManualPushCounter();
933 jacobianData.pushData(jacobians[rhsCount], rhsIdentifiers[rhsCount]);
934 }
935 }
936 }
937
938 using Base::writeTape;
939
942 template<typename Type>
944 Position const& end) {
945 Impl& impl = cast();
946 writer->start(impl);
947 Base::llfByteData.evaluateForward(start, end, Impl::template internalWriteTape<Type>, writer);
948 writer->finish();
949 }
950
952 /*******************************************************************************/
955
958 return indexManager.get();
959 }
960
962 /*******************************************************************************/
965
968 statementData.reserveItems(1);
969
970 Base::internalStoreLowLevelFunction(token, size, data);
971
972 Identifier lhsIndex = Identifier();
974 indexManager.get().template assignIndex<Impl>(lhsIndex);
975 }
976 cast().pushStmtData(lhsIndex, Config::StatementLowLevelFunctionTag);
977 }
978
980 /*******************************************************************************/
983
985 CODI_INLINE void evaluate(Position const& start, Position const& end,
987 if (AdjointsManagement::Automatic == adjointsManagement) {
988 checkAdjointSize(indexManager.get().getLargestCreatedIndex());
989 adjoints.beginUse();
990 }
991
992 codiAssert(indexManager.get().getLargestCreatedIndex() < (Identifier)adjoints.size());
993
994 evaluate(start, end, adjoints.data());
995
996 if (AdjointsManagement::Automatic == adjointsManagement) {
997 adjoints.endUse();
998 }
999 }
1000
1002 /*******************************************************************************/
1005
1007 void evaluateKeepState(Position const& start, Position const& end,
1009 evaluate(start, end, adjointsManagement);
1010 }
1011
1013 template<typename AdjointVector>
1014 void evaluateKeepState(Position const& start, Position const& end, AdjointVector&& data) {
1015 evaluate(start, end, std::forward<AdjointVector>(data));
1016 }
1017
1019 void evaluateForwardKeepState(Position const& start, Position const& end,
1021 evaluateForward(start, end, adjointsManagement);
1022 }
1023
1025 template<typename AdjointVector>
1026 void evaluateForwardKeepState(Position const& start, Position const& end, AdjointVector&& data) {
1027 evaluateForward(start, end, std::forward<AdjointVector>(data));
1028 }
1029
1031 /*******************************************************************************/
1034
1036
1038 void evaluatePrimal(Position const& start, Position const& end) {
1039 CODI_UNUSED(start, end);
1040
1041 CODI_EXCEPTION("Accessing primal evaluation of an Jacobian tape.");
1042 }
1043
1045 Real& primal(Identifier const& identifier) {
1046 CODI_UNUSED(identifier);
1047
1048 CODI_EXCEPTION("Accessing primal vector of an Jacobian tape.");
1049
1050 static Real temp;
1051 return temp;
1052 }
1053
1055 Real const& primal(Identifier const& identifier) const {
1056 CODI_UNUSED(identifier);
1057
1058 CODI_EXCEPTION("Accessing primal vector of an Jacobian tape.");
1059
1060 static Real temp;
1061 return temp;
1062 }
1063
1065
1066 private:
1067
1068 CODI_INLINE void checkAdjointSize(Identifier const& identifier) {
1069 if (identifier >= (Identifier)adjoints.size()) {
1070 internalResizeAdjointsVector();
1071 }
1072 }
1073
1074 CODI_NO_INLINE void internalResizeAdjointsVector() {
1075 // overallocate as next multiple of Config::ChunkSize
1076 adjoints.resize(
1077 getNextMultiple(indexManager.get().getLargestCreatedIndex() + 1, (Identifier)Config::ChunkSize));
1078 }
1079 };
1080}
#define CODI_Unlikely
Declare unlikely evaluation of an execution path.
Definition config.h:408
#define CODI_LAMBDA_INLINE
See codi::Config::ForcedInlines.
Definition config.h:473
#define CODI_NO_INLINE
See codi::Config::AvoidedInlines.
Definition config.h:426
#define CODI_INLINE
See codi::Config::ForcedInlines.
Definition config.h:469
#define CODI_Likely
Declare likely evaluation of an execution path.
Definition config.h:406
#define CODI_RESTRICT
See codi::Config::Restrict.
Definition config.h:491
#define CODI_RemoveDuplicateJacobianArguments
See codi::Config::RemoveDuplicateJacobianArguments.
Definition config.h:229
#define codiAssert(x)
See codi::Config::EnableAssert.
Definition config.h:441
#define CODI_DD(Type, Default)
Abbreviation for CODI_DECLARE_DEFAULT.
Definition macros.hpp:96
#define CODI_ENABLE_CHECK(option, condition)
Definition macros.hpp:61
#define CODI_WRAP_FUNCTION_TEMPLATE(NAME, FUNC)
Wrap a function in a function object. Used for performance optimizations.
Definition macros.hpp:176
#define CODI_T(...)
Abbreviation for CODI_TEMPLATE.
Definition macros.hpp:116
typename GradientImplementation< AdjointVector >::Gradient Gradient
Deduce the entry type from an adjoint vector type, usually identical to the gradient type of a tape.
Definition adjointVectorTraits.hpp:92
Configuration options for CoDiPack.
Definition config.h:65
uint16_t LowLevelFunctionToken
Token type for low level functions in the tapes.
Definition config.h:108
const bool CheckEmptyStatements
Tapes push statements only if at least one Jacobian was pushed.
Definition config.h:154
size_t constexpr ChunkSize
Default size of chunks (ChunkBase) used in ChunkedData in reverse tape implementations.
Definition config.h:94
bool constexpr CheckZeroIndex
Ignore active types that are not dependent on any input value in Jacobian tapes.
Definition config.h:178
bool constexpr IgnoreInvalidJacobians
Ignore invalid Jacobians like NaN or Inf.
Definition config.h:240
bool constexpr CheckTapeActivity
Makes it possible to ignore certain code parts. If turned of everything will be recorded.
Definition config.h:170
size_t constexpr StatementLowLevelFunctionTag
Statement tag for low level functions.
Definition config.h:126
bool constexpr CheckJacobianIsZero
Ignore Jacobians that are zero in Jacobian based tapes.
Definition config.h:162
size_t constexpr MaxArgumentSize
Maximum number of arguments in a statement.
Definition config.h:120
bool constexpr StatementEvents
Enable statement events. Disabled by default.
Definition config.h:328
bool constexpr CopyOptimization
Do not store copy statements like a = b; if the identity handler allows it.
Definition config.h:186
uint8_t ArgumentSize
Type for the number of arguments in statements.
Definition config.h:117
size_t constexpr StatementInputTag
Tag for statements that are inputs. Used in linear index management context.
Definition config.h:123
bool constexpr SkipZeroAdjointEvaluation
Do not perform a reverse evaluation of a statement if the seeding adjoint is zero.
Definition config.h:256
inlinebool isTotalFinite(Type const &v)
Function for checking if all values of the type are finite.
Definition realTraits.hpp:139
inlinebool isTotalZero(Type const &v)
Function for checking if the value of the type is completely zero.
Definition realTraits.hpp:145
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:94
IntegralType getNextMultiple(IntegralType const &targetSize, IntegralType const &chunkSize)
Helper function for overallocation in multiples of a given chunk size.
Definition mathUtility.hpp:49
TapeParameters
Configuration options for a tape.
Definition tapeParameters.hpp:52
@ LargestIdentifier
[A: R] Largest identifier distributed by the index manger.
Definition tapeParameters.hpp:60
@ JacobianSize
[A: RW] Allocated number of entries in the argument Jacobian vector in Jacobian tapes.
Definition tapeParameters.hpp:59
@ StatementSize
[A: RW] Allocated number of entries in the statement vector in all tapes.
Definition tapeParameters.hpp:66
@ AdjointSize
Definition tapeParameters.hpp:53
inlinevoid static_for(F func, Args &&... args)
Static for with i = 0 .. (N - 1). See CompileTimeLoop for details.
Definition compileTimeLoop.hpp:110
typename ArrayAccessExpressionImpl< Aggregated, element >::template Expression< Arg > ArrayAccessExpression
Expression that performs a[element] in a compile time context.
Definition arrayAccessExpression.hpp:98
inlineauto real(ExpressionInterface< std::complex< Real >, Arg > const &arg)
Function overload for FUNCTION.
Definition allOperators.hpp:75
inlinevoid CODI_UNUSED(Args const &...)
Disable unused warnings for an arbitrary number of arguments.
Definition macros.hpp:54
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
ChunkedData< Chunk, NestedData > DefaultChunkedData
ChunkData DataInterface used in all regular tapes.
Definition chunkedData.hpp:520
inlineauto max(ExpressionInterface< Real, ArgA > const &argA, ExpressionInterface< Real, ArgB > const &argB)
Function overload for FUNCTION.
Definition binaryOperators.hpp:73
Implementation of VectorAccessInterface for adjoint vectors.
Definition adjointVectorAccess.hpp:61
InnerActiveType values[Elements]
Array representation.
Definition aggregatedActiveType.hpp:75
Represents a concrete aggregated lvalue int the CoDiPack expression tree.
Definition aggregatedActiveType.hpp:164
Definition byteDataView.hpp:51
Definition chunk.hpp:283
inlinevoid internalStoreLowLevelFunction(Config::LowLevelFunctionToken token, size_t size, ByteDataView &dataView)
Definition commonTapeImplementation.hpp:494
inlinevoid initializeManualPushData(Real const &lhsValue, Identifier const &lhsIndex, size_t size)
Initialize all manual push data, including the counter. Check that a previous manual store is complet...
Definition commonTapeImplementation.hpp:200
Real manualPushLhsValue
For storeManual, remember the value assigned to the lhs.
Definition commonTapeImplementation.hpp:158
void setParameter(TapeParameters parameter, size_t value)
Definition commonTapeImplementation.hpp:459
void evaluateForward(AdjointsManagement adjointsManagement=AdjointsManagement::Automatic)
Definition commonTapeImplementation.hpp:611
size_t manualPushCounter
Count the pushes after storeManual, to identify the last push.
Definition commonTapeImplementation.hpp:161
Identifier manualPushLhsIdentifier
For storeManual, remember the identifier assigned to the lhs.
Definition commonTapeImplementation.hpp:159
bool isActive() const
Definition commonTapeImplementation.hpp:320
size_t manualPushGoal
Store the number of expected pushes after a storeManual call.
Definition commonTapeImplementation.hpp:160
void init(typename ImplTapeTypes::NestedData *nested)
Initialize the base class.
Definition commonTapeImplementation.hpp:770
std::set< TapeParameters > options
All options.
Definition commonTapeImplementation.hpp:153
void writeTape(std::unique_ptr< TapeWriterInterface< Type > > writer)
Definition commonTapeImplementation.hpp:624
void evaluate(AdjointsManagement adjointsManagement=AdjointsManagement::Automatic)
Definition commonTapeImplementation.hpp:293
void swap(Impl &other)
Definition commonTapeImplementation.hpp:368
typename CommonTapeTypes< ImplTapeTypes >::Position Position
Definition commonTapeImplementation.hpp:145
LowLevelFunctionByteData llfByteData
Byte data for low level functions.
Definition commonTapeImplementation.hpp:156
CommonTapeImplementation()
Definition commonTapeImplementation.hpp:232
size_t getParameter(TapeParameters parameter) const
Definition commonTapeImplementation.hpp:431
void evaluatePrimal()
Definition commonTapeImplementation.hpp:745
Data stream interface for tape data. Encapsulates data that is written e.g. for each statement or arg...
Definition dataInterface.hpp:149
Combines entries of Jacobians with the same identifier.
Definition duplicateJacobianRemover.hpp:58
inlinevoid storeData(Vec &vec)
Definition duplicateJacobianRemover.hpp:98
static inlinevoid notifyTapeRegisterInputListeners(Tape &tape, Real &value, Identifier &identifier)
Invoke callbacks for TapeRegisterInput events.
Definition eventSystem.hpp:424
static inlinevoid notifyTapeEvaluateListeners(Tape &tape, Position const &start, Position const &end, VectorAccess *adjoint, EventHints::EvaluationKind evalKind, EventHints::Endpoint endpoint)
Invoke callbacks for TapeEvaluate events.
Definition eventSystem.hpp:486
static inlinevoid notifyStatementStoreOnTapeListeners(Tape &tape, Identifier const &lhsIdentifier, Real const &newValue, size_t numActiveVariables, Identifier const *rhsIdentifiers, Real const *jacobians)
Invoke callbacks for StatementStoreOnTape events.
Definition eventSystem.hpp:676
Base class for all CoDiPack expressions.
Definition expressionInterface.hpp:60
inlineImpl const & cast() const
Cast to the implementation.
Definition expressionInterface.hpp:76
Counts the number of nodes that inherit from LhsExpressionInterface in the expression.
Definition expressionTraits.hpp:226
static size_t constexpr value
See NumberOfActiveTypeArguments.
Definition expressionTraits.hpp:240
Implement logic for leaf nodes only.
Definition forEachLeafLogic.hpp:60
Indices enable the mapping of primal values to their adjoint counterparts.
Definition indexManagerInterface.hpp:78
Whether the adjoint vector is global, that is, shared among different tapes.
Definition adjointVectorTraits.hpp:50
Abstracts the internal set of adjoint variables provided as part of the tape.
Definition internalAdjointsInterface.hpp:80
Pushes all delayed Jacobians.
Definition jacobianBaseTape.hpp:318
inlinevoid handleActive(ReferenceActiveType< Type > const &node, DataVector &dataVector)
Specialization for ReferenceActiveType nodes. Pushes the delayed Jacobian.
Definition jacobianBaseTape.hpp:323
Pushes Jacobians and indices to the tape.
Definition jacobianBaseTape.hpp:290
inlinevoid handleJacobianOnActive(ReferenceActiveType< Type > const &node, Real jacobian, DataVector &dataVector)
Specialization for ReferenceActiveType nodes. Delays Jacobian push.
Definition jacobianBaseTape.hpp:306
inlinevoid handleJacobianOnActive(Node const &node, Real jacobian, DataVector &dataVector)
General implementation. Checks for invalid and passive values/Jacobians.
Definition jacobianBaseTape.hpp:294
inlineTapeValues internalGetTapeValues() const
Adds data from all streams, the size of the adjoint vector and index manager data.
Definition jacobianBaseTape.hpp:606
void evaluateKeepState(Position const &start, Position const &end, AdjointsManagement adjointsManagement=AdjointsManagement::Automatic)
Perform a tape evaluation but restore the state afterwards such that it is the same as when the evalu...
Definition jacobianBaseTape.hpp:1007
IndexManager & getIndexManager()
Returns a reference to the Index Manager.
Definition jacobianBaseTape.hpp:957
JacobianData jacobianData
Definition jacobianBaseTape.hpp:176
typename Base::Position Position
See TapeTypesInterface.
Definition jacobianBaseTape.hpp:154
inlinestatic void incrementAdjoints(AdjointVector &adjointVector, AdjointVectorTraits::Gradient< AdjointVector > const &lhsAdjoint, Config::ArgumentSize const &numberOfArguments, size_t &curJacobianPos, Real const *const rhsJacobians, Identifier const *const rhsIdentifiers)
Performs the AD reverse equation for a statement.
Definition jacobianBaseTape.hpp:645
size_t getParameter(TapeParameters parameter) const
See Parameters functions.
Definition jacobianBaseTape.hpp:764
inlinevoid pushJacobians(ExpressionInterface< Real, Rhs > const &rhs)
Push Jacobians and delayed Jacobians to the tape.
Definition jacobianBaseTape.hpp:339
typename TapeTypes::Gradient Gradient
See TapeTypesInterface.
Definition jacobianBaseTape.hpp:142
typename TapeTypes::JacobianData JacobianData
See JacobianTapeTypes.
Definition jacobianBaseTape.hpp:147
static void internalEvaluateReverse_EvalStatements(Args &&... args)
Perform a reverse evaluation of the tape. Arguments are from the recursive eval methods of the DataIn...
inlinevoid store(LhsExpressionInterface< Real, Gradient, Impl, Lhs > &lhs, ExpressionInterface< Real, Rhs > const &rhs)
Has to be called by an AD variable every time it is assigned.
Definition jacobianBaseTape.hpp:483
void resizeAdjointVector()
Explicitly trigger resizing of the adjoint vector. See Adjoint vector management.
Definition jacobianBaseTape.hpp:749
StatementData statementData
Definition jacobianBaseTape.hpp:175
Adjoints adjoints
Definition jacobianBaseTape.hpp:178
void beginUseAdjointVector()
Declare that the adjoint vector is being used. See Adjoint vector management.
Definition jacobianBaseTape.hpp:754
Real const & primal(Identifier const &identifier) const
Not implemented, raises an exception.
Definition jacobianBaseTape.hpp:1055
inlinevoid swap(Impl &other)
Swap all data with an other tape.
Definition jacobianBaseTape.hpp:734
void pushStmtData(Identifier const &index, Config::ArgumentSize const &numberOfArguments)
Add statement specific data to the data streams.
typename TapeTypes::IndexManager IndexManager
See JacobianTapeTypes.
Definition jacobianBaseTape.hpp:143
friend Base
Definition jacobianBaseTape.hpp:139
inlinevoid pushLowLevelFunction(Config::LowLevelFunctionToken token, size_t size, ByteDataView &data)
Push a low level function to the tape.
Definition jacobianBaseTape.hpp:967
void evaluateKeepState(Position const &start, Position const &end, AdjointVector &&data)
Perform a tape evaluation but restore the state afterwards such that it is the same as when the evalu...
Definition jacobianBaseTape.hpp:1014
typename TapeTypes::template Adjoints< Impl > Adjoints
See JacobianTapeTypes.
Definition jacobianBaseTape.hpp:149
VectorAccess< decltype(adjoints.data())> * createVectorAccess()
See Adjoint vector access.
Definition jacobianBaseTape.hpp:805
VectorAccess< AdjointVector > * createVectorAccessCustomAdjoints(AdjointVector &&data)
Definition jacobianBaseTape.hpp:811
inlinestatic void incrementTangents(AdjointVector const &adjointVector, AdjointVectorTraits::Gradient< AdjointVector > &lhsAdjoint, Config::ArgumentSize const &numberOfArguments, size_t &curJacobianPos, Real const *const rhsJacobians, Identifier const *const rhsIdentifiers)
Performs the AD forward equation for a statement.
Definition jacobianBaseTape.hpp:668
void endUseAdjointVector()
Declare that the adjoint vector is no longer used. See Adjoint vector management.
Definition jacobianBaseTape.hpp:759
static void internalEvaluateForward_EvalStatements(Args &&... args)
Perform a forward evaluation of the tape. Arguments are from the recursive eval methods of the DataIn...
void deleteAdjointVector()
Delete the adjoint vector. See Adjoint vector management.
Definition jacobianBaseTape.hpp:744
void evaluateForward(Position const &start, Position const &end, AdjointsManagement adjointsManagement=AdjointsManagement::Automatic)
Perform a forward evaluation of a part of the tape. It has to hold start <= end.
Definition jacobianBaseTape.hpp:848
inlinevoid internalRegisterInput(LhsExpressionInterface< Real, Gradient, Impl, Lhs > &value, bool unusedIndex)
Add a new input to the tape.
Definition jacobianBaseTape.hpp:558
typename TapeTypes::Real Real
See TapeTypesInterface.
Definition jacobianBaseTape.hpp:141
inlinevoid evaluate(Position const &start, Position const &end, AdjointsManagement adjointsManagement=AdjointsManagement::Automatic)
Perform a reverse evaluation for a part of the tape. It hast to hold start >= end.
Definition jacobianBaseTape.hpp:985
typename TapeTypes::StatementData StatementData
See JacobianTapeTypes.
Definition jacobianBaseTape.hpp:146
inlineGradient & gradient(Identifier const &identifier, AdjointsManagement adjointsManagement=AdjointsManagement::Automatic)
Reference access to gradient.
Definition jacobianBaseTape.hpp:241
T_Impl Impl
See JacobianBaseTape.
Definition jacobianBaseTape.hpp:136
Real & primal(Identifier const &identifier)
Not implemented, raises an exception.
Definition jacobianBaseTape.hpp:1045
JacobianBaseTape()
Constructor.
Definition jacobianBaseTape.hpp:212
AdjointVectorAccess< Real, Identifier, AdjointVector > VectorAccess
Vector access type generated by this tape.
Definition jacobianBaseTape.hpp:158
CommonTapeImplementation< T_TapeTypes, T_Impl > Base
Base class abbreviation.
Definition jacobianBaseTape.hpp:138
void evaluateForwardKeepState(Position const &start, Position const &end, AdjointVector &&data)
Perform a tape evaluation but restore the state afterwards such that it is the same as when the evalu...
Definition jacobianBaseTape.hpp:1026
void setParameter(TapeParameters parameter, size_t value)
See Parameters functions.
Definition jacobianBaseTape.hpp:784
void evaluateForward(Position const &start, Position const &end, AdjointVector &&data)
Perform a reverse evaluation for a part of the tape. It hast to hold start >= end.
Definition jacobianBaseTape.hpp:710
void evaluate(Position const &start, Position const &end, AdjointVector &&data)
Perform a reverse evaluation for a part of the tape. It hast to hold start >= end.
Definition jacobianBaseTape.hpp:695
inlinevoid store(LhsExpressionInterface< Real, Gradient, Impl, Lhs > &lhs, LhsExpressionInterface< Real, Gradient, Impl, Rhs > const &rhs)
Has to be called by an AD variable every time it is assigned.
Definition jacobianBaseTape.hpp:524
inlinevoid store(AggregatedActiveType< Aggregated, Type, Lhs > &lhs, ExpressionInterface< Aggregated, Rhs > const &rhs)
Has to be called by an AD variable every time it is assigned.
Definition jacobianBaseTape.hpp:364
typename JacobianData::Position NestedPosition
See JacobianTapeTypes.
Definition jacobianBaseTape.hpp:153
static bool constexpr HasPrimalValues
Definition jacobianBaseTape.hpp:161
inlinevoid initIdentifier(Real &value, Identifier &identifier)
Definition jacobianBaseTape.hpp:271
static bool constexpr RequiresPrimalRestore
Definition jacobianBaseTape.hpp:165
void evaluateForwardKeepState(Position const &start, Position const &end, AdjointsManagement adjointsManagement=AdjointsManagement::Automatic)
Perform a tape evaluation but restore the state afterwards such that it is the same as when the evalu...
Definition jacobianBaseTape.hpp:1019
inlinevoid store(LhsExpressionInterface< Real, Gradient, Impl, Lhs > &lhs, Real const &rhs)
Has to be called by an AD variable every time it is assigned.
Definition jacobianBaseTape.hpp:543
static bool constexpr AllowJacobianOptimization
Definition jacobianBaseTape.hpp:160
inlinevoid store(AggregatedActiveType< Aggregated, Type, Lhs > &lhs, AggregatedActiveType< Aggregated, Type, Rhs > const &rhs)
Has to be called by an AD variable every time it is assigned.
Definition jacobianBaseTape.hpp:454
void storeManual(Real const &lhsValue, Identifier &lhsIndex, Config::ArgumentSize const &size)
Definition jacobianBaseTape.hpp:894
void writeTape(codi::TapeWriterInterface< Type > *writer, Position const &start, Position const &end)
For full or partial tapes using a pointer to the writer.
Definition jacobianBaseTape.hpp:943
VectorAccess< Adjoint * > * createVectorAccessCustomAdjoints(Adjoint *data)
Definition jacobianBaseTape.hpp:818
void pushJacobianManual(Real const &jacobian, Real const &value, Identifier const &index)
Definition jacobianBaseTape.hpp:870
void createStatementManual(Real const &lhsValue, Identifier &lhsIndex, Config::ArgumentSize const &size, Real const *jacobians, Identifier const *rhsIdentifiers)
Definition jacobianBaseTape.hpp:917
void evaluatePrimal(Position const &start, Position const &end)
Not implemented, raises an exception.
Definition jacobianBaseTape.hpp:1038
static bool constexpr LinearIndexHandling
Definition jacobianBaseTape.hpp:163
Real registerExternalFunctionOutput(LhsExpressionInterface< Real, Gradient, Impl, Lhs > &value)
Definition jacobianBaseTape.hpp:834
RealTraits::PassiveReal< Real > PassiveReal
Basic computation type.
Definition jacobianBaseTape.hpp:151
T_TapeTypes TapeTypes
See JacobianBaseTape.
Definition jacobianBaseTape.hpp:134
inlinevoid clearAdjoints(AdjointsManagement adjointsManagement=AdjointsManagement::Automatic)
Clear all adjoint values, that is, set them to zero.
Definition jacobianBaseTape.hpp:589
inlinevoid destroyIdentifier(Real &value, Identifier &identifier)
Has to be called for each identifier, before it is deallocated.
Definition jacobianBaseTape.hpp:279
MemberStore< IndexManager, Impl, TapeTypes::IsStaticIndexHandler > indexManager
Definition jacobianBaseTape.hpp:174
typename TapeTypes::Identifier Identifier
See TapeTypesInterface.
Definition jacobianBaseTape.hpp:144
void deleteVectorAccess(VectorAccessInterface< Real, Identifier > *access)
See Adjoint vector access.
Definition jacobianBaseTape.hpp:823
inlineGradient const & gradient(Identifier const &identifier, AdjointsManagement adjointsManagement=AdjointsManagement::Automatic) const
Constant reference access to gradient.
Definition jacobianBaseTape.hpp:253
inlinevoid registerInput(LhsExpressionInterface< Real, Gradient, Impl, Lhs > &value)
Definition jacobianBaseTape.hpp:583
Definition jacobianComputationLogic.hpp:54
inlinevoid pushStmtData(Identifier const &index, Config::ArgumentSize const &numberOfArguments)
Add statement specific data to the data streams.
Definition jacobianLinearTape.hpp:125
Type definitions for the Jacobian tapes.
Definition jacobianBaseTape.hpp:80
T_Real Real
See JacobianTapeTypes.
Definition jacobianBaseTape.hpp:83
typename std::conditional< IsLinearIndexHandler, Chunk1< Config::ArgumentSize >, Chunk2< Identifier, Config::ArgumentSize > >::type StatementChunk
Definition jacobianBaseTape.hpp:103
Chunk2< Real, Identifier > JacobianChunk
Jacobian chunks is <Jacobian, rhs index>.
Definition jacobianBaseTape.hpp:107
Data< JacobianChunk, StatementData > JacobianData
Jacobian data vector.
Definition jacobianBaseTape.hpp:108
Data< StatementChunk, IndexManager > StatementData
Statement data vector.
Definition jacobianBaseTape.hpp:105
T_Data< Chunk, Nested > Data
See JacobianTapeTypes.
Definition jacobianBaseTape.hpp:87
T_Gradient Gradient
See JacobianTapeTypes.
Definition jacobianBaseTape.hpp:84
T_IndexManager IndexManager
See JacobianTapeTypes.
Definition jacobianBaseTape.hpp:85
static bool constexpr IsLinearIndexHandler
True if the index manager is linear.
Definition jacobianBaseTape.hpp:97
T_Adjoints< Gradient, Identifier, Impl > Adjoints
See JacobianTapeTypes.
Definition jacobianBaseTape.hpp:94
typename IndexManager::Index Identifier
See IndexManagerInterface.
Definition jacobianBaseTape.hpp:90
JacobianData NestedData
See TapeTypesInterface.
Definition jacobianBaseTape.hpp:110
static bool constexpr IsStaticIndexHandler
True if the index manager must be stored statically in the tape.
Definition jacobianBaseTape.hpp:98
Base class for all CoDiPack lvalue expression.
Definition lhsExpressionInterface.hpp:63
inlineImpl & cast()
Cast to the implementation.
Definition lhsExpressionInterface.hpp:99
Adjoint variables owned by a tape instance.
Definition localAdjoints.hpp:54
Defines a member that can either be static or local to the struct.
Definition memberStore.hpp:56
Methods that access inner values of aggregated types that contain CoDiPack active types.
Definition realTraits.hpp:226
Holds a reference to an ActiveType for manual optimization of common arguments.
Definition referenceActiveType.hpp:61
Interface for the definition of tape types.
Definition commonTapeImplementation.hpp:64
Tape information that can be printed in a pretty print format or a table format.
Definition tapeValues.hpp:75
void addUnsignedLongEntry(std::string const &name, unsigned long const &value, LocalReductionOperation operation=LocalReductionOperation::Sum)
Add unsigned long entry.
Definition tapeValues.hpp:163
void addDoubleEntry(std::string const &name, double const &value, LocalReductionOperation operation=LocalReductionOperation::Sum, bool usedMem=false, bool allocatedMem=false)
Add double entry. If it is a memory entry, it should be in bytes.
Definition tapeValues.hpp:137
void addSection(std::string const &name)
Add section. All further entries are added under this section.
Definition tapeValues.hpp:158
The interface used by all the tape writers. The tape writers are used to generate text,...
Definition tapeReaderWriterInterface.hpp:129
virtual void start(Tape &tape)
Destructor.
Definition tapeReaderWriterInterface.hpp:144
virtual void finish()
After all the statements have been written, the finish method finalizes the writing process.
Definition tapeReaderWriterInterface.hpp:178
inlinevoid node(Node const &node, Args &&... args)
Definition traversalLogic.hpp:87
Unified access to the adjoint vector and primal vector in a tape evaluation.
Definition vectorAccessInterface.hpp:94