CoDiPack  3.1.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-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 <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;
92 typename IndexManager::ActiveTypeIndexData;
93
95 template<typename Impl>
96 using Adjoints = CODI_DD(CODI_T(T_Adjoints<Gradient, Identifier, Impl>),
98
99 static bool constexpr IsLinearIndexHandler = IndexManager::IsLinear;
100 static bool constexpr IsStaticIndexHandler =
101 IndexManager::NeedsStaticStorage;
102
105 using StatementChunk = typename std::conditional<IsLinearIndexHandler, Chunk1<Config::ArgumentSize>,
108
111
113 };
114
131 template<typename T_TapeTypes, typename T_Impl>
132 struct JacobianBaseTape : public CommonTapeImplementation<T_TapeTypes, T_Impl> {
133 public:
134
138 using Impl = CODI_DD(T_Impl, CODI_DEFAULT_TAPE);
139
141 friend Base;
142
143 using Real = typename TapeTypes::Real;
144 using Gradient = typename TapeTypes::Gradient;
145 using IndexManager = typename TapeTypes::IndexManager;
146 using Identifier = typename TapeTypes::Identifier;
147 using ActiveTypeTapeData = typename TapeTypes::ActiveTypeTapeData;
148
149 using StatementData = typename TapeTypes::StatementData;
150 using JacobianData = typename TapeTypes::JacobianData;
151
152 using Adjoints = typename TapeTypes::template Adjoints<Impl>;
153
155
156 using NestedPosition = typename JacobianData::Position;
157 using Position = typename Base::Position;
158
160 template<typename AdjointVector>
162
163 static bool constexpr AllowJacobianOptimization = true;
164 static bool constexpr HasPrimalValues = false;
165
166 static bool constexpr LinearIndexHandling =
167 TapeTypes::IsLinearIndexHandler;
168 static bool constexpr RequiresPrimalRestore = false;
169
170 protected:
171
172#if CODI_RemoveDuplicateJacobianArguments
175#endif
176
180
182
183 private:
184
185 CODI_INLINE Impl const& cast() const {
186 return static_cast<Impl const&>(*this);
187 }
188
189 CODI_INLINE Impl& cast() {
190 return static_cast<Impl&>(*this);
191 }
192
193 protected:
194
195 /*******************************************************************************/
198
200 template<typename... Args>
201 static void internalEvaluateForward_EvalStatements(Args&&... args);
202
204 template<typename... Args>
205 static void internalEvaluateReverse_EvalStatements(Args&&... args);
206
208 void pushStmtData(Identifier const& index, Config::ArgumentSize const& numberOfArguments);
209
211
212 public:
213
216 : Base(),
218 jacobianSorter(),
219#endif
220 indexManager(0), // Reserve the zero index.
221 statementData(Config::ChunkSize),
222 jacobianData(std::max(Config::ChunkSize, Config::MaxArgumentSize)), // Chunk must be large enough to store
223 // data for all arguments of one
224 // statement.
225 adjoints(1) // Ensure that adjoint[0] exists, see its use in gradient() const.
226
227 {
228 statementData.setNested(&indexManager.get());
229 jacobianData.setNested(&statementData);
230
232
237 }
238
239 /*******************************************************************************/
242
246 if (AdjointsManagement::Automatic == adjointsManagement) {
247 checkAdjointSize(identifier);
248 }
249
250 codiAssert(identifier < (Identifier)adjoints.size());
251
252 return adjoints[identifier];
253 }
254
257 Identifier const& identifier, AdjointsManagement adjointsManagement = AdjointsManagement::Automatic) const {
258 codiAssert(identifier < (Identifier)adjoints.size());
259
260 if (AdjointsManagement::Automatic == adjointsManagement && identifier >= (Identifier)adjoints.size()) {
261 return adjoints[0];
262 } else {
263 return adjoints[identifier];
264 }
265 }
266
268 /*******************************************************************************/
271
273 template<typename Real>
275 CODI_UNUSED(value);
276
277 indexManager.get().initIndex(data);
278 }
279
281 template<typename Real>
283 CODI_UNUSED(value);
284
285 indexManager.get().template freeIndex<Impl>(data);
286 }
287
289
290 protected:
291
293 struct PushJacobianLogic : public JacobianComputationLogic<PushJacobianLogic> {
294 public:
296 template<typename Node, typename DataVector>
297 CODI_INLINE void handleJacobianOnActive(Node const& node, Real jacobian, DataVector& dataVector,
298 IndexManager const& indexManager) {
299 indexManager.validateRhsIndex(node.getTapeData());
300
301 if (CODI_ENABLE_CHECK(Config::CheckZeroIndex, 0 != node.getIdentifier())) {
304 dataVector.pushData(jacobian, node.getIdentifier());
305 }
306 }
307 }
308 }
309
311 template<typename Type, typename DataVector>
313 DataVector& dataVector, IndexManager const& indexManager) {
314 CODI_UNUSED(dataVector);
315 indexManager.validateRhsIndex(node.getTapeData());
316
318 // Do a delayed push for these leaf nodes, accumulate the jacobian in the local member.
319 node.jacobian += jacobian;
320 }
321 }
322 };
323
325 struct PushDelayedJacobianLogic : public ForEachLeafLogic<PushDelayedJacobianLogic> {
326 public:
327
329 template<typename Type, typename DataVector>
330 // indexManager should be a const&, for some reason gcc did not preferred this overload to the ellipsis one.
331 CODI_INLINE void handleActive(ReferenceActiveType<Type> const& node, DataVector& dataVector,
333 indexManager.validateRhsIndex(node.getTapeData());
334 if (CODI_ENABLE_CHECK(Config::CheckZeroIndex, 0 != node.getIdentifier())) {
336 dataVector.pushData(node.jacobian, node.getIdentifier());
337
338 // Reset the jacobian here such that it is not pushed multiple times and ready for the next store.
339 node.jacobian = Real();
340 }
341 }
342 }
343
345 };
346
348 template<typename Rhs>
350 PushJacobianLogic pushJacobianLogic;
351 PushDelayedJacobianLogic pushDelayedJacobianLogic;
352
353#if CODI_RemoveDuplicateJacobianArguments
354 auto& insertVector = jacobianSorter;
355#else
356 auto& insertVector = jacobianData;
357#endif
358
359 pushJacobianLogic.eval(rhs.cast(), Real(1.0), insertVector, indexManager.get());
360 pushDelayedJacobianLogic.eval(rhs.cast(), insertVector, indexManager.get());
361
362#if CODI_RemoveDuplicateJacobianArguments
363 jacobianSorter.storeData(jacobianData);
364#endif
365 }
366
367 public:
368
370
373 template<typename Aggregated, typename Type, typename Lhs, typename Rhs>
376 using AggregatedTraits = RealTraits::AggregatedTypeTraits<Aggregated>;
377
378 int constexpr Elements = AggregatedTraits::Elements;
379
380 bool freeAndUpdate = true;
381
384
386
387 statementData.reserveItems(Elements);
388
389 // Push the Jacobians
390 typename JacobianData::InternalPosHandle jacobianStart = jacobianData.reserveItems(MaxArgs * Elements);
391 std::array<size_t, Elements> numberOfArguments;
392 size_t totalNumberOfArguments = 0;
395
396 size_t newTotalNumberOfArguments = jacobianData.getPushedDataCount(jacobianStart);
397 numberOfArguments[i.value] = newTotalNumberOfArguments - totalNumberOfArguments;
398 totalNumberOfArguments = newTotalNumberOfArguments;
399 });
400
401 if (0 != totalNumberOfArguments) {
402 freeAndUpdate = false;
403
404 // This implementation avoids the creation of self reference adjoint equations. See paper (TODO: add when
405 // released.) Section 4.1 for a detailed description. In short: For e.g. a = a * b with complex numbers
406 // the adjoint assignment of a.i modifies \bar a.r which is used in the adjoint assignment of a.r. This is
407 // wrong since the original value of \bar a.r needs to be used. If now self references are present, this
408 // problem does not arise.
409
410 // Create new identifiers to prevent self references.
411 std::array<ActiveTypeTapeData, Elements> identifiers = {};
413 if (CODI_ENABLE_CHECK(Config::CheckEmptyStatements, 0 != numberOfArguments[i.value])) {
414 indexManager.get().template assignIndex<Impl>(identifiers[i.value]);
415 }
416 });
417
418 // Update all lhs entries
419 Aggregated real = rhs.cast().getValue();
420 size_t eventJacobianOffset = 0;
421
423 indexManager.get().template freeIndex<Impl>(lhs.values[i.value].getTapeData());
424
425 if (CODI_ENABLE_CHECK(Config::CheckEmptyStatements, 0 != numberOfArguments[i.value])) {
426 lhs.values[i.value].getTapeData() = identifiers[i.value];
427 cast().pushStmtData(lhs.values[i.value].getIdentifier(),
428 (Config::ArgumentSize)numberOfArguments[i.value]);
429
431 Real* jacobians;
432 Identifier* rhsIdentifiers;
433 jacobianData.getDataPointers(jacobians, rhsIdentifiers);
434 jacobians -= totalNumberOfArguments;
435 rhsIdentifiers -= totalNumberOfArguments;
436
438 cast(), lhs.values[i.value].getIdentifier(),
439 AggregatedTraits::template arrayAccess<i.value>(real), numberOfArguments[i.value],
440 &rhsIdentifiers[eventJacobianOffset], &jacobians[eventJacobianOffset]);
441
442 eventJacobianOffset += numberOfArguments[i.value];
443 }
444 }
445
446 lhs.values[i.value].value() = AggregatedTraits::template arrayAccess<i.value>(real);
447 });
448 }
449 }
450
451 if (freeAndUpdate) {
452 Aggregated real = rhs.cast().getValue();
453
455 lhs.values[i.value].value() = AggregatedTraits::template arrayAccess<i.value>(real);
456 indexManager.get().template freeIndex<Impl>(lhs.values[i.value].getTapeData());
457 });
458 }
459 }
460
463 template<typename Aggregated, typename Type, typename Lhs, typename Rhs>
466 using AggregatedTraits = RealTraits::AggregatedTypeTraits<Aggregated>;
467
468 int constexpr Elements = AggregatedTraits::Elements;
469
471 if (IndexManager::CopyNeedsStatement || !Config::CopyOptimization) {
472 store(lhs, static_cast<ExpressionInterface<Aggregated, Rhs> const&>(rhs));
473 return;
474 } else {
476 indexManager.get().template copyIndex<Impl>(lhs.values[i.value].getTapeData(),
477 rhs.values[i.value].getTapeData());
478 });
479 }
480 } else {
482 indexManager.get().template freeIndex<Impl>(lhs.values[i.value].getTapeData());
483 });
484 }
485
487 lhs.values[i.value].value() = rhs.values[i.value].getValue();
488 });
489 }
490
492 template<typename Lhs, typename Rhs>
496 size_t constexpr MaxArgs = ExpressionTraits::NumberOfActiveTypeArguments<Rhs>::template eval<Rhs>();
497
499
500 statementData.reserveItems(1);
501 typename JacobianData::InternalPosHandle jacobianStart = jacobianData.reserveItems(MaxArgs);
502
503 pushJacobians(rhs);
504
505 size_t numberOfArguments = jacobianData.getPushedDataCount(jacobianStart);
506 if (CODI_ENABLE_CHECK(Config::CheckEmptyStatements, 0 != numberOfArguments)) {
507 indexManager.get().template assignIndex<Impl>(lhs.cast().getTapeData());
508 cast().pushStmtData(lhs.cast().getIdentifier(), (Config::ArgumentSize)numberOfArguments);
509
511 Real* jacobians;
512 Identifier* rhsIdentifiers;
513 jacobianData.getDataPointers(jacobians, rhsIdentifiers);
514 jacobians -= numberOfArguments;
515 rhsIdentifiers -= numberOfArguments;
516
518 rhs.cast().getValue(), numberOfArguments,
519 rhsIdentifiers, jacobians);
520 }
521 } else {
522 indexManager.get().template freeIndex<Impl>(lhs.cast().getTapeData());
523 }
524 } else {
525 indexManager.get().template freeIndex<Impl>(lhs.cast().getTapeData());
526 }
527
528 lhs.cast().value() = rhs.cast().getValue();
529 }
530
533 template<typename Lhs, typename Rhs>
537 if (IndexManager::CopyNeedsStatement || !Config::CopyOptimization) {
538 store<Lhs, Rhs>(lhs, static_cast<ExpressionInterface<Real, Rhs> const&>(rhs));
539 return;
540 } else {
541 indexManager.get().template copyIndex<Impl>(lhs.cast().getTapeData(), rhs.cast().getTapeData());
542 }
543 } else {
544 indexManager.get().template freeIndex<Impl>(lhs.cast().getTapeData());
545 }
546
547 lhs.cast().value() = rhs.cast().getValue();
548 }
549
552 template<typename Lhs>
554 indexManager.get().template freeIndex<Impl>(lhs.cast().getTapeData());
555
556 lhs.cast().value() = rhs;
557 }
558
560 /*******************************************************************************
561 * Protected helper function for ReverseTapeInterface
562 */
563
564 protected:
565
567 template<typename Lhs>
569 bool unusedIndex) {
570 if (TapeTypes::IsLinearIndexHandler) {
571 statementData.reserveItems(1);
572 }
573
574 if (unusedIndex) {
575 indexManager.get().template assignUnusedIndex<Impl>(value.cast().getTapeData());
576 } else {
577 indexManager.get().template assignIndex<Impl>(value.cast().getTapeData());
578 }
579
580 if (TapeTypes::IsLinearIndexHandler) {
581 cast().pushStmtData(value.cast().getIdentifier(), Config::StatementInputTag);
582 }
583 }
584
585 public:
586
587 /*******************************************************************************/
590
592 template<typename Lhs>
594 cast().internalRegisterInput(value, true);
595 EventSystem<Impl>::notifyTapeRegisterInputListeners(cast(), value.cast().value(), value.cast().getIdentifier());
596 }
597
600 if (AdjointsManagement::Automatic == adjointsManagement) {
601 adjoints.beginUse();
602 }
603
604 adjoints.zeroAll(indexManager.get().getLargestCreatedIndex());
605
606 if (AdjointsManagement::Automatic == adjointsManagement) {
607 adjoints.endUse();
608 }
609 }
610
612
613 protected:
614
617 std::string name;
618 if (TapeTypes::IsLinearIndexHandler) {
619 name = "CoDi Tape Statistics ( JacobianLinearTape )";
620 } else {
621 name = "CoDi Tape Statistics ( JacobianReuseTape )";
622 }
623 TapeValues values = TapeValues(name);
624
625 size_t nAdjoints = indexManager.get().getLargestCreatedIndex();
626 double memoryAdjoints = static_cast<double>(nAdjoints) * static_cast<double>(sizeof(Gradient));
627
628 bool constexpr globalAdjoints = InternalAdjointVectorTraits::IsGlobal<Adjoints>::value;
629 TapeValues::LocalReductionOperation constexpr operation =
630 globalAdjoints ? TapeValues::LocalReductionOperation::Max : TapeValues::LocalReductionOperation::Sum;
631
632 values.addSection("Adjoint vector");
633 values.addUnsignedLongEntry("Number of adjoints", nAdjoints, operation);
634 values.addDoubleEntry("Memory allocated", memoryAdjoints, operation, true, true);
635
636 values.addSection("Index manager");
637 indexManager.get().addToTapeValues(values);
638
639 values.addSection("Statement entries");
640 statementData.addToTapeValues(values);
641 values.addSection("Jacobian entries");
642 jacobianData.addToTapeValues(values);
643
644 return values;
645 }
646
647 /******************************************************************************
648 * Protected helper function for CustomAdjointVectorEvaluationTapeInterface
649 */
650
651 protected:
652
654 template<typename AdjointVector>
656 AdjointVector& CODI_RESTRICT adjointVector,
658 Config::ArgumentSize const& CODI_RESTRICT numberOfArguments, size_t& CODI_RESTRICT curJacobianPos,
659 Real const* CODI_RESTRICT const rhsJacobians, Identifier const* CODI_RESTRICT const rhsIdentifiers) {
660 size_t endJacobianPos = curJacobianPos - numberOfArguments;
661
663 while (endJacobianPos < curJacobianPos) CODI_Likely {
664 curJacobianPos -= 1;
665 adjointVector[rhsIdentifiers[curJacobianPos]] += rhsJacobians[curJacobianPos] * lhsAdjoint;
666 }
667 } else CODI_Unlikely {
668 curJacobianPos = endJacobianPos;
669 }
670 }
671
673 CODI_WRAP_FUNCTION_TEMPLATE(Wrap_internalEvaluateReverse_EvalStatements,
675
677 template<typename AdjointVector>
678 CODI_INLINE static void incrementTangents(AdjointVector const& CODI_RESTRICT adjointVector,
680 Config::ArgumentSize const& numberOfArguments,
681 size_t& CODI_RESTRICT curJacobianPos,
682 Real const* CODI_RESTRICT const rhsJacobians,
683 Identifier const* CODI_RESTRICT const rhsIdentifiers) {
684 size_t endJacobianPos = curJacobianPos + numberOfArguments;
685
686 while (curJacobianPos < endJacobianPos) CODI_Likely {
687 lhsAdjoint += rhsJacobians[curJacobianPos] * adjointVector[rhsIdentifiers[curJacobianPos]];
688 curJacobianPos += 1;
689 }
690 }
691
693 CODI_WRAP_FUNCTION_TEMPLATE(Wrap_internalEvaluateForward_EvalStatements,
695
696 public:
697
700
701 using Base::evaluate;
702
704 template<typename AdjointVector>
705 CODI_NO_INLINE void evaluate(Position const& start, Position const& end, AdjointVector&& data) {
706 VectorAccess<AdjointVector> adjointWrapper(data);
707
709 cast(), start, end, &adjointWrapper, EventHints::EvaluationKind::Reverse, EventHints::Endpoint::Begin);
710
711 Wrap_internalEvaluateReverse_EvalStatements<AdjointVector> evalFunc;
712 Base::llfByteData.evaluateReverse(start, end, evalFunc, cast(), std::forward<AdjointVector>(data));
713
714 EventSystem<Impl>::notifyTapeEvaluateListeners(cast(), start, end, &adjointWrapper,
715 EventHints::EvaluationKind::Reverse, EventHints::Endpoint::End);
716 }
717
719 template<typename AdjointVector>
720 CODI_NO_INLINE void evaluateForward(Position const& start, Position const& end, AdjointVector&& data) {
721 VectorAccess<AdjointVector> adjointWrapper(data);
722
724 cast(), start, end, &adjointWrapper, EventHints::EvaluationKind::Forward, EventHints::Endpoint::Begin);
725
726 Wrap_internalEvaluateForward_EvalStatements<AdjointVector> evalFunc;
727 Base::llfByteData.evaluateForward(start, end, evalFunc, cast(), std::forward<AdjointVector>(data));
728
729 EventSystem<Impl>::notifyTapeEvaluateListeners(cast(), start, end, &adjointWrapper,
730 EventHints::EvaluationKind::Forward, EventHints::Endpoint::End);
731 }
732
735 return adjoints.data();
736 }
737
739 /*******************************************************************************/
742
744 CODI_INLINE void swap(Impl& other) {
745 // Index manager does not need to be swapped, it is either static or swapped with the vector data.
746 // Vectors are swapped recursively in the base class.
747
748 adjoints.swap(other.adjoints);
749
750 Base::swap(other);
751 }
752
755 adjoints.resize(1);
756 }
757
760 checkAdjointSize(indexManager.get().getLargestCreatedIndex());
761 }
762
765 adjoints.beginUse();
766 }
767
770 adjoints.endUse();
771 }
772
774 size_t getParameter(TapeParameters parameter) const {
775 switch (parameter) {
777 return adjoints.size();
778 break;
780 return jacobianData.getDataSize();
781 break;
783 return indexManager.get().getLargestCreatedIndex();
784 break;
786 return statementData.getDataSize();
787 default:
788 return Base::getParameter(parameter);
789 break;
790 }
791 }
792
794 void setParameter(TapeParameters parameter, size_t value) {
795 switch (parameter) {
797 adjoints.resize(value);
798 break;
800 jacobianData.resize(value);
801 break;
803 CODI_EXCEPTION("Tried to set a get only parameter.");
804 break;
806 statementData.resize(value);
807 break;
808 default:
809 Base::setParameter(parameter, value);
810 break;
811 }
812 }
813
817 }
818
820 template<typename AdjointVector>
824
827 template<typename Adjoint>
831
834 delete access;
835 }
836
838 /*******************************************************************************/
841
843 template<typename Lhs>
845 cast().internalRegisterInput(value, false);
846
847 return Real();
848 }
849
851 /*******************************************************************************/
854
856
858 void evaluateForward(Position const& start, Position const& end,
860 if (AdjointsManagement::Automatic == adjointsManagement) {
861 checkAdjointSize(indexManager.get().getLargestCreatedIndex());
862 adjoints.beginUse();
863 }
864
865 codiAssert(indexManager.get().getLargestCreatedIndex() < (Identifier)adjoints.size());
866
867 cast().evaluateForward(start, end, adjoints.data());
868
869 if (AdjointsManagement::Automatic == adjointsManagement) {
870 adjoints.endUse();
871 }
872 }
873
875 /*******************************************************************************/
878
880 void pushJacobianManual(Real const& jacobian, Real const& value, ActiveTypeTapeData const& data) {
881 CODI_UNUSED(value);
882
883 cast().incrementManualPushCounter();
884
885 jacobianData.pushData(jacobian, indexManager.get().getIndex(data));
886
888 if (this->manualPushCounter == this->manualPushGoal) {
889 // emit statement event
890 Real* jacobians;
891 Identifier* rhsIdentifiers;
892 jacobianData.getDataPointers(jacobians, rhsIdentifiers);
893 jacobians -= this->manualPushGoal;
894 rhsIdentifiers -= this->manualPushGoal;
895
898 rhsIdentifiers, jacobians);
899 }
900 }
901 }
902
904 void storeManual(Real const& lhsValue, ActiveTypeTapeData& lhsData, Config::ArgumentSize const& size) {
905 CODI_UNUSED(lhsValue);
906 Impl& impl = cast();
907
909
910 statementData.reserveItems(1);
911 jacobianData.reserveItems(size);
912
913 indexManager.get().template assignIndex<Impl>(lhsData);
914 impl.pushStmtData(indexManager.get().getIndex(lhsData), (Config::ArgumentSize)size);
915
916 impl.initializeManualPushData(lhsValue, indexManager.get().getIndex(lhsData), size);
917 }
918
920 /*******************************************************************************/
923
927 void createStatementManual(Real const& lhsValue, Identifier& lhsIndex, Config::ArgumentSize const& size,
928 Real const* jacobians, Identifier const* rhsIdentifiers) {
929 CODI_UNUSED(lhsValue);
930 Impl& impl = cast();
931
932 statementData.reserveItems(1);
933
934 if (Config::StatementInputTag == size && TapeTypes::IsLinearIndexHandler) CODI_Unlikely {
935 impl.pushStmtData(lhsIndex, (Config::ArgumentSize)size);
936 } else CODI_Likely {
937 jacobianData.reserveItems(size);
938 impl.pushStmtData(lhsIndex, (Config::ArgumentSize)size);
939 impl.initializeManualPushData(lhsValue, lhsIndex, size);
940 // Record the rhs of the statement.
941 for (size_t rhsCount = 0; rhsCount < size; rhsCount++) {
942 cast().incrementManualPushCounter();
943 jacobianData.pushData(jacobians[rhsCount], rhsIdentifiers[rhsCount]);
944 }
945 }
946 }
947
948 using Base::writeTape;
949
952 template<typename Type>
954 Position const& end) {
955 Impl& impl = cast();
956 writer->start(impl);
957 Base::llfByteData.evaluateForward(start, end, Impl::template internalWriteTape<Type>, writer);
958 writer->finish();
959 }
960
962 /*******************************************************************************/
965
968 return indexManager.get();
969 }
970
972 /*******************************************************************************/
975
978 statementData.reserveItems(1);
979
980 Base::internalStoreLowLevelFunction(token, size, data);
981
984 indexManager.get().template assignIndex<Impl>(lhsData);
985 }
986 cast().pushStmtData(indexManager.get().getIndex(lhsData), Config::StatementLowLevelFunctionTag);
987 }
988
990 /*******************************************************************************/
993
995 CODI_INLINE void evaluate(Position const& start, Position const& end,
997 if (AdjointsManagement::Automatic == adjointsManagement) {
998 checkAdjointSize(indexManager.get().getLargestCreatedIndex());
999 adjoints.beginUse();
1000 }
1001
1002 codiAssert(indexManager.get().getLargestCreatedIndex() < (Identifier)adjoints.size());
1003
1004 evaluate(start, end, adjoints.data());
1005
1006 if (AdjointsManagement::Automatic == adjointsManagement) {
1007 adjoints.endUse();
1008 }
1009 }
1010
1012 /*******************************************************************************/
1015
1017 void evaluateKeepState(Position const& start, Position const& end,
1019 evaluate(start, end, adjointsManagement);
1020 }
1021
1023 template<typename AdjointVector>
1024 void evaluateKeepState(Position const& start, Position const& end, AdjointVector&& data) {
1025 evaluate(start, end, std::forward<AdjointVector>(data));
1026 }
1027
1029 void evaluateForwardKeepState(Position const& start, Position const& end,
1031 evaluateForward(start, end, adjointsManagement);
1032 }
1033
1035 template<typename AdjointVector>
1036 void evaluateForwardKeepState(Position const& start, Position const& end, AdjointVector&& data) {
1037 evaluateForward(start, end, std::forward<AdjointVector>(data));
1038 }
1039
1041 /*******************************************************************************/
1044
1046
1048 void evaluatePrimal(Position const& start, Position const& end) {
1049 CODI_UNUSED(start, end);
1050
1051 CODI_EXCEPTION("Accessing primal evaluation of an Jacobian tape.");
1052 }
1053
1055 Real& primal(Identifier const& identifier) {
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 Real const& primal(Identifier const& identifier) const {
1066 CODI_UNUSED(identifier);
1067
1068 CODI_EXCEPTION("Accessing primal vector of an Jacobian tape.");
1069
1070 static Real temp;
1071 return temp;
1072 }
1073
1076 CODI_EXCEPTION("Accessing primal vector of an Jacobian tape.");
1077
1078 return nullptr;
1079 }
1080
1082
1083 private:
1084
1085 CODI_INLINE void checkAdjointSize(Identifier const& identifier) {
1086 if (identifier >= (Identifier)adjoints.size()) {
1087 internalResizeAdjointsVector();
1088 }
1089 }
1090
1091 CODI_NO_INLINE void internalResizeAdjointsVector() {
1092 // overallocate as next multiple of Config::ChunkSize
1093 adjoints.resize(
1094 getNextMultiple(indexManager.get().getLargestCreatedIndex() + 1, (Identifier)Config::ChunkSize));
1095 }
1096 };
1097}
#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:97
#define CODI_ENABLE_CHECK(option, condition)
Definition macros.hpp:62
#define CODI_WRAP_FUNCTION_TEMPLATE(NAME, FUNC)
Wrap a function in a function object. Used for performance optimizations.
Definition macros.hpp:178
#define CODI_T(...)
Abbreviation for CODI_TEMPLATE.
Definition macros.hpp:117
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:97
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: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
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:519
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:202
Real manualPushLhsValue
For storeManual, remember the value assigned to the lhs.
Definition commonTapeImplementation.hpp:160
void setParameter(TapeParameters parameter, size_t value)
Definition commonTapeImplementation.hpp:484
void evaluateForward(AdjointsManagement adjointsManagement=AdjointsManagement::Automatic)
Definition commonTapeImplementation.hpp:652
size_t manualPushCounter
Count the pushes after storeManual, to identify the last push.
Definition commonTapeImplementation.hpp:163
Identifier manualPushLhsIdentifier
For storeManual, remember the identifier assigned to the lhs.
Definition commonTapeImplementation.hpp:161
bool isActive() const
Definition commonTapeImplementation.hpp:322
size_t manualPushGoal
Store the number of expected pushes after a storeManual call.
Definition commonTapeImplementation.hpp:162
void init(typename ImplTapeTypes::NestedData *nested)
Initialize the base class.
Definition commonTapeImplementation.hpp:823
std::set< TapeParameters > options
All options.
Definition commonTapeImplementation.hpp:155
void writeTape(std::unique_ptr< TapeWriterInterface< Type > > writer)
Definition commonTapeImplementation.hpp:665
void evaluate(AdjointsManagement adjointsManagement=AdjointsManagement::Automatic)
Definition commonTapeImplementation.hpp:295
void swap(Impl &other)
Definition commonTapeImplementation.hpp:393
typename CommonTapeTypes< ImplTapeTypes >::Position Position
Definition commonTapeImplementation.hpp:147
LowLevelFunctionByteData llfByteData
Byte data for low level functions.
Definition commonTapeImplementation.hpp:158
CommonTapeImplementation()
Definition commonTapeImplementation.hpp:234
size_t getParameter(TapeParameters parameter) const
Definition commonTapeImplementation.hpp:456
void evaluatePrimal()
Definition commonTapeImplementation.hpp:798
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:258
static size_t constexpr value
See NumberOfActiveTypeArguments.
Definition expressionTraits.hpp:272
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:325
inlinevoid handleActive(ReferenceActiveType< Type > const &node, DataVector &dataVector, IndexManager &indexManager)
Specialization for ReferenceActiveType nodes. Pushes the delayed Jacobian.
Definition jacobianBaseTape.hpp:331
Pushes Jacobians and indices to the tape.
Definition jacobianBaseTape.hpp:293
inlinevoid handleJacobianOnActive(Node const &node, Real jacobian, DataVector &dataVector, IndexManager const &indexManager)
General implementation. Checks for invalid and passive values/Jacobians.
Definition jacobianBaseTape.hpp:297
inlinevoid handleJacobianOnActive(ReferenceActiveType< Type > const &node, Real jacobian, DataVector &dataVector, IndexManager const &indexManager)
Specialization for ReferenceActiveType nodes. Delays Jacobian push.
Definition jacobianBaseTape.hpp:312
inlineTapeValues internalGetTapeValues() const
Adds data from all streams, the size of the adjoint vector and index manager data.
Definition jacobianBaseTape.hpp:616
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:1017
IndexManager & getIndexManager()
Returns a reference to the Index Manager.
Definition jacobianBaseTape.hpp:967
JacobianData jacobianData
Definition jacobianBaseTape.hpp:179
typename Base::Position Position
See TapeTypesInterface.
Definition jacobianBaseTape.hpp:157
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:655
size_t getParameter(TapeParameters parameter) const
See Parameters functions.
Definition jacobianBaseTape.hpp:774
inlinevoid pushJacobians(ExpressionInterface< Real, Rhs > const &rhs)
Push Jacobians and delayed Jacobians to the tape.
Definition jacobianBaseTape.hpp:349
typename TapeTypes::Gradient Gradient
See TapeTypesInterface.
Definition jacobianBaseTape.hpp:144
inlinevoid initTapeData(Real &value, ActiveTypeTapeData &data)
< Has to be called for each tape data, after it is allocated.
Definition jacobianBaseTape.hpp:274
typename TapeTypes::JacobianData JacobianData
See JacobianTapeTypes.
Definition jacobianBaseTape.hpp:150
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:493
void resizeAdjointVector()
Explicitly trigger resizing of the adjoint vector. See Adjoint vector management.
Definition jacobianBaseTape.hpp:759
StatementData statementData
Definition jacobianBaseTape.hpp:178
Adjoints adjoints
Definition jacobianBaseTape.hpp:181
void beginUseAdjointVector()
Declare that the adjoint vector is being used. See Adjoint vector management.
Definition jacobianBaseTape.hpp:764
Real const & primal(Identifier const &identifier) const
Not implemented, raises an exception.
Definition jacobianBaseTape.hpp:1065
inlinevoid swap(Impl &other)
Swap all data with an other tape.
Definition jacobianBaseTape.hpp:744
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:145
friend Base
Definition jacobianBaseTape.hpp:141
inlinevoid pushLowLevelFunction(Config::LowLevelFunctionToken token, size_t size, ByteDataView &data)
Push a low level function to the tape.
Definition jacobianBaseTape.hpp:977
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:1024
typename TapeTypes::template Adjoints< Impl > Adjoints
See JacobianTapeTypes.
Definition jacobianBaseTape.hpp:152
VectorAccess< decltype(adjoints.data())> * createVectorAccess()
See Adjoint vector access.
Definition jacobianBaseTape.hpp:815
VectorAccess< AdjointVector > * createVectorAccessCustomAdjoints(AdjointVector &&data)
Definition jacobianBaseTape.hpp:821
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:678
void endUseAdjointVector()
Declare that the adjoint vector is no longer used. See Adjoint vector management.
Definition jacobianBaseTape.hpp:769
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:754
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:858
inlinevoid destroyTapeData(Real &value, ActiveTypeTapeData &data)
Has to be called for each tape data, before it is deallocated.
Definition jacobianBaseTape.hpp:282
inlinevoid internalRegisterInput(LhsExpressionInterface< Real, Gradient, Impl, Lhs > &value, bool unusedIndex)
Add a new input to the tape.
Definition jacobianBaseTape.hpp:568
typename TapeTypes::Real Real
See TapeTypesInterface.
Definition jacobianBaseTape.hpp:143
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:995
typename TapeTypes::StatementData StatementData
See JacobianTapeTypes.
Definition jacobianBaseTape.hpp:149
inlineGradient & gradient(Identifier const &identifier, AdjointsManagement adjointsManagement=AdjointsManagement::Automatic)
Reference access to gradient.
Definition jacobianBaseTape.hpp:244
T_Impl Impl
See JacobianBaseTape.
Definition jacobianBaseTape.hpp:138
Real & primal(Identifier const &identifier)
Not implemented, raises an exception.
Definition jacobianBaseTape.hpp:1055
JacobianBaseTape()
Constructor.
Definition jacobianBaseTape.hpp:215
typename TapeTypes::ActiveTypeTapeData ActiveTypeTapeData
See TapeTypesInterface.
Definition jacobianBaseTape.hpp:147
AdjointVectorAccess< Real, Identifier, AdjointVector > VectorAccess
Vector access type generated by this tape.
Definition jacobianBaseTape.hpp:161
CommonTapeImplementation< T_TapeTypes, T_Impl > Base
Base class abbreviation.
Definition jacobianBaseTape.hpp:140
Real * getPrimalVector()
Not implemented, raises an exception.
Definition jacobianBaseTape.hpp:1075
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:1036
void setParameter(TapeParameters parameter, size_t value)
See Parameters functions.
Definition jacobianBaseTape.hpp:794
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:720
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:705
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:534
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:374
typename JacobianData::Position NestedPosition
See JacobianTapeTypes.
Definition jacobianBaseTape.hpp:156
static bool constexpr HasPrimalValues
Definition jacobianBaseTape.hpp:164
void storeManual(Real const &lhsValue, ActiveTypeTapeData &lhsData, Config::ArgumentSize const &size)
Definition jacobianBaseTape.hpp:904
static bool constexpr RequiresPrimalRestore
Definition jacobianBaseTape.hpp:168
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:1029
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:553
static bool constexpr AllowJacobianOptimization
Definition jacobianBaseTape.hpp:163
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:464
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:953
VectorAccess< Adjoint * > * createVectorAccessCustomAdjoints(Adjoint *data)
Definition jacobianBaseTape.hpp:828
void createStatementManual(Real const &lhsValue, Identifier &lhsIndex, Config::ArgumentSize const &size, Real const *jacobians, Identifier const *rhsIdentifiers)
Definition jacobianBaseTape.hpp:927
void evaluatePrimal(Position const &start, Position const &end)
Not implemented, raises an exception.
Definition jacobianBaseTape.hpp:1048
static bool constexpr LinearIndexHandling
Definition jacobianBaseTape.hpp:166
Real registerExternalFunctionOutput(LhsExpressionInterface< Real, Gradient, Impl, Lhs > &value)
Definition jacobianBaseTape.hpp:844
void pushJacobianManual(Real const &jacobian, Real const &value, ActiveTypeTapeData const &data)
Definition jacobianBaseTape.hpp:880
RealTraits::PassiveReal< Real > PassiveReal
Basic computation type.
Definition jacobianBaseTape.hpp:154
T_TapeTypes TapeTypes
See JacobianBaseTape.
Definition jacobianBaseTape.hpp:136
inlinevoid clearAdjoints(AdjointsManagement adjointsManagement=AdjointsManagement::Automatic)
Clear all adjoint values, that is, set them to zero.
Definition jacobianBaseTape.hpp:599
MemberStore< IndexManager, Impl, TapeTypes::IsStaticIndexHandler > indexManager
Definition jacobianBaseTape.hpp:177
typename TapeTypes::Identifier Identifier
See TapeTypesInterface.
Definition jacobianBaseTape.hpp:146
void deleteVectorAccess(VectorAccessInterface< Real, Identifier > *access)
See Adjoint vector access.
Definition jacobianBaseTape.hpp:833
inlineGradient const & gradient(Identifier const &identifier, AdjointsManagement adjointsManagement=AdjointsManagement::Automatic) const
Constant reference access to gradient.
Definition jacobianBaseTape.hpp:256
inlinevoid registerInput(LhsExpressionInterface< Real, Gradient, Impl, Lhs > &value)
Definition jacobianBaseTape.hpp:593
Definition jacobianComputationLogic.hpp:54
inlinevoid pushStmtData(Identifier const &index, Config::ArgumentSize const &numberOfArguments)
Add statement specific data to the data streams.
Definition jacobianLinearTape.hpp:126
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:105
Chunk2< Real, Identifier > JacobianChunk
Jacobian chunks is <Jacobian, rhs index>.
Definition jacobianBaseTape.hpp:109
typename IndexManager::ActiveTypeIndexData ActiveTypeTapeData
Take the active real data from the index manager.
Definition jacobianBaseTape.hpp:91
Data< JacobianChunk, StatementData > JacobianData
Jacobian data vector.
Definition jacobianBaseTape.hpp:110
Data< StatementChunk, IndexManager > StatementData
Statement data vector.
Definition jacobianBaseTape.hpp:107
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:99
T_Adjoints< Gradient, Identifier, Impl > Adjoints
See JacobianTapeTypes.
Definition jacobianBaseTape.hpp:96
typename IndexManager::Index Identifier
See IndexManagerInterface.
Definition jacobianBaseTape.hpp:90
JacobianData NestedData
See TapeTypesInterface.
Definition jacobianBaseTape.hpp:112
static bool constexpr IsStaticIndexHandler
True if the index manager must be stored statically in the tape.
Definition jacobianBaseTape.hpp:100
Base class for all CoDiPack lvalue expression.
Definition lhsExpressionInterface.hpp:63
inlineImpl & cast()
Cast to the implementation.
Definition lhsExpressionInterface.hpp:103
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:233
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:177
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