CoDiPack  2.2.0
A Code Differentiation Package
SciComp TU Kaiserslautern
Loading...
Searching...
No Matches
primalValueBaseTape.hpp
1/*
2 * CoDiPack, a Code Differentiation Package
3 *
4 * Copyright (C) 2015-2024 Chair for Scientific Computing (SciComp), University of Kaiserslautern-Landau
5 * Homepage: http://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 <functional>
40#include <type_traits>
41#include <utility>
42
43#include "../config.h"
44#include "../expressions/lhsExpressionInterface.hpp"
45#include "../expressions/logic/compileTimeTraversalLogic.hpp"
46#include "../expressions/logic/constructStaticContext.hpp"
47#include "../expressions/logic/helpers/forEachLeafLogic.hpp"
48#include "../expressions/logic/helpers/jacobianComputationLogic.hpp"
49#include "../expressions/logic/traversalLogic.hpp"
50#include "../misc/macros.hpp"
51#include "../misc/mathUtility.hpp"
52#include "../misc/memberStore.hpp"
53#include "../traits/expressionTraits.hpp"
54#include "commonTapeImplementation.hpp"
55#include "data/chunk.hpp"
56#include "data/chunkedData.hpp"
57#include "indices/indexManagerInterface.hpp"
58#include "misc/primalAdjointVectorAccess.hpp"
59#include "statementEvaluators/statementEvaluatorInterface.hpp"
60#include "statementEvaluators/statementEvaluatorTapeInterface.hpp"
61
63namespace codi {
64
75 template<typename T_Real, typename T_Gradient, typename T_IndexManager, template<typename> class T_StatementEvaluator,
76 template<typename, typename> class T_Data>
78 public:
79
80 using Real = CODI_DD(T_Real, double);
81 using Gradient = CODI_DD(T_Gradient, double);
83 using StatementEvaluator = CODI_DD(CODI_T(T_StatementEvaluator<Real>),
85 template<typename Chunk, typename Nested>
86 using Data = CODI_DD(CODI_T(T_Data<Chunk, Nested>),
88
89 using Identifier = typename IndexManager::Index;
91
92 constexpr static bool IsLinearIndexHandler = IndexManager::IsLinear;
93 constexpr static bool IsStaticIndexHandler =
94 IndexManager::NeedsStaticStorage;
95
96 using EvalHandle = typename StatementEvaluator::Handle;
97
101 typename std::conditional<IsLinearIndexHandler, Chunk2<Config::ArgumentSize, EvalHandle>,
104
107
110
113
115 };
116
133 template<typename T_TapeTypes, typename T_Impl>
134 struct PrimalValueBaseTape : public CommonTapeImplementation<T_TapeTypes, T_Impl>,
135 public StatementEvaluatorTapeInterface<typename T_TapeTypes::Real>,
136 public StatementEvaluatorInnerTapeInterface<typename T_TapeTypes::Real> {
137 public:
138
140 using TapeTypes = CODI_DD(T_TapeTypes,
145
147 friend Base;
148
149 using Real = typename TapeTypes::Real;
150 using Gradient = typename TapeTypes::Gradient;
151 using IndexManager = typename TapeTypes::IndexManager;
152 using StatementEvaluator = typename TapeTypes::StatementEvaluator;
153 using Identifier = typename TapeTypes::Identifier;
154
155 using EvalHandle = typename TapeTypes::EvalHandle;
156
157 using StatementData = typename TapeTypes::StatementData;
158 using RhsIdentifierData = typename TapeTypes::RhsIdentifierData;
159 using PassiveValueData = typename TapeTypes::PassiveValueData;
160 using ConstantValueData = typename TapeTypes::ConstantValueData;
161
163
164 using NestedPosition = typename ConstantValueData::Position;
165 using Position = typename Base::Position;
166
167 template<typename Adjoint>
170
171 static bool constexpr AllowJacobianOptimization = false;
172 static bool constexpr HasPrimalValues = true;
173 static bool constexpr LinearIndexHandling =
174 TapeTypes::IsLinearIndexHandler;
175 static bool constexpr RequiresPrimalRestore =
176 !TapeTypes::IsLinearIndexHandler;
177
178 protected:
179
181
187
188 std::vector<Gradient> adjoints;
189 std::vector<Real> primals;
190 std::vector<Real> primalsCopy;
191
192 private:
193
194 CODI_INLINE Impl const& cast() const {
195 return static_cast<Impl const&>(*this);
196 }
197
198 CODI_INLINE Impl& cast() {
199 return static_cast<Impl&>(*this);
200 }
201
202 protected:
203
204 /*******************************************************************************/
207
209 template<typename... Args>
210 static void internalEvaluateForward_EvalStatements(Args&&... args);
211
213 template<typename... Args>
214 static void internalEvaluatePrimal_EvalStatements(Args&&... args);
215
217 template<typename... Args>
218 static void internalEvaluateReverse_EvalStatements(Args&&... args);
219
222
224 void pushStmtData(Identifier const& index, Config::ArgumentSize const& numberOfPassiveArguments,
225 Real const& oldPrimalValue, EvalHandle evalHandle);
226
228
229 public:
230
233 : Base(),
234 indexManager(Config::MaxArgumentSize), // Reserve first items for passive values.
235 statementData(Config::ChunkSize),
236 // The following chunks must be large enough to store data for all arguments of one statement.
237 rhsIdentiferData(std::max(Config::ChunkSize, Config::MaxArgumentSize)),
238 passiveValueData(std::max(Config::ChunkSize, Config::MaxArgumentSize)),
239 constantValueData(std::max(Config::ChunkSize, Config::MaxArgumentSize)),
240 adjoints(1), // Ensure that adjoint[0] exists, see its use in gradient() const.
241 primals(0),
242 primalsCopy(0) {
243 checkPrimalSize(true);
244
245 statementData.setNested(&indexManager.get());
249
251
259 }
260
261 /*******************************************************************************/
264
270 if (AdjointsManagement::Automatic == adjointsManagement) {
271 checkAdjointSize(identifier);
272 }
273
274 codiAssert(identifier < (Identifier)adjoints.size());
275
276 return adjoints[identifier];
277 }
278
283 Identifier const& identifier, AdjointsManagement adjointsManagement = AdjointsManagement::Automatic) const {
284 codiAssert(identifier < (Identifier)adjoints.size());
285
286 if (AdjointsManagement::Automatic == adjointsManagement && identifier >= (Identifier)adjoints.size()) {
287 return adjoints[0];
288 } else {
289 return adjoints[identifier];
290 }
291 }
292
294 /*******************************************************************************/
297
299 template<typename Real>
300 CODI_INLINE void initIdentifier(Real& value, Identifier& identifier) {
301 CODI_UNUSED(value);
302
303 identifier = IndexManager::InactiveIndex;
304 }
305
307 template<typename Real>
308 CODI_INLINE void destroyIdentifier(Real& value, Identifier& identifier) {
309 CODI_UNUSED(value);
310
311 indexManager.get().template freeIndex<Impl>(identifier);
312 }
313
315
316 protected:
317
319 struct CountActiveArguments : public ForEachLeafLogic<CountActiveArguments> {
320 public:
321
323 template<typename Node>
325 if (CODI_ENABLE_CHECK(Config::CheckZeroIndex, IndexManager::InactiveIndex != node.getIdentifier())) {
327 }
328 }
329 };
330
332 struct PushIdentfierPassiveAndConstant : public ForEachLeafLogic<PushIdentfierPassiveAndConstant> {
333 public:
334
336 template<typename Node>
352
354 template<typename Node>
357 size_t& curPassiveArgument) {
359
360 using ConversionOperator = typename Node::template ConversionOperator<PassiveReal>;
361
362 constantValueData.pushData(ConversionOperator::toDataStore(node.getValue()));
363 }
364 };
365
367 struct JacobianExtractionLogic : public JacobianComputationLogic<JacobianExtractionLogic> {
368 private:
369 size_t pos;
370
371 public:
372
375
377 template<typename Node, typename Jacobian>
379 Real* jacobians) {
380 rhsIdentifiers[pos] = node.getIdentifier();
381 jacobians[pos] = ComputationTraits::adjointConversion<Real>(jacobianExpr);
382 pos++;
383 }
384 };
385
386 public:
387
389
391 template<typename Lhs, typename Rhs>
395 CountActiveArguments countActiveArguments;
397 size_t constexpr MaxActiveArgs = ExpressionTraits::NumberOfActiveTypeArguments<Rhs>::value;
398 size_t constexpr MaxConstantArgs = ExpressionTraits::NumberOfConstantTypeArguments<Rhs>::value;
399
400 codiAssert(MaxActiveArgs < Config::MaxArgumentSize);
401 codiAssert(MaxConstantArgs < Config::MaxArgumentSize);
402
403 size_t activeArguments = 0;
404 countActiveArguments.eval(rhs.cast(), activeArguments);
405
406 if (CODI_ENABLE_CHECK(Config::CheckEmptyStatements, 0 != activeArguments)) {
407 statementData.reserveItems(1);
408 rhsIdentiferData.reserveItems(MaxActiveArgs);
409 passiveValueData.reserveItems(MaxActiveArgs - activeArguments);
410 constantValueData.reserveItems(MaxConstantArgs);
411
412 size_t passiveArguments = 0;
413 pushAll.eval(rhs.cast(), rhsIdentiferData, passiveValueData, constantValueData, passiveArguments);
414
415 bool generatedNewIndex = indexManager.get().template assignIndex<Impl>(lhs.cast().getIdentifier());
416 checkPrimalSize(generatedNewIndex);
417
418 Real& primalEntry = primals[lhs.cast().getIdentifier()];
419 cast().pushStmtData(lhs.cast().getIdentifier(), passiveArguments, primalEntry,
420 StatementEvaluator::template createHandle<Impl, Impl, Rhs>());
421
422 primalEntry = rhs.cast().getValue();
423
425 JacobianExtractionLogic getRhsIdentifiersAndJacobians;
426 std::array<Identifier, MaxActiveArgs> rhsIdentifiers;
427 std::array<Real, MaxActiveArgs> jacobians;
428 getRhsIdentifiersAndJacobians.eval(rhs.cast(), Real(1.0), rhsIdentifiers.data(), jacobians.data());
429
431 rhs.cast().getValue(), MaxActiveArgs,
432 rhsIdentifiers.data(), jacobians.data());
433 }
434 } else {
435 indexManager.get().template freeIndex<Impl>(lhs.cast().getIdentifier());
436 }
437 } else {
438 indexManager.get().template freeIndex<Impl>(lhs.cast().getIdentifier());
439 }
440
441 lhs.cast().value() = rhs.cast().getValue();
442 }
443
446 template<typename Lhs, typename Rhs>
450 if (IndexManager::CopyNeedsStatement || !Config::CopyOptimization) {
451 store<Lhs, Rhs>(lhs, static_cast<ExpressionInterface<Real, Rhs> const&>(rhs));
452 return;
453 } else {
454 indexManager.get().template copyIndex<Impl>(lhs.cast().getIdentifier(), rhs.cast().getIdentifier());
455 }
456 } else {
457 indexManager.get().template freeIndex<Impl>(lhs.cast().getIdentifier());
458 }
459
460 lhs.cast().value() = rhs.cast().getValue();
461 }
462
465 template<typename Lhs>
467 indexManager.get().template freeIndex<Impl>(lhs.cast().getIdentifier());
468
469 lhs.cast().value() = rhs;
470 }
471
473 /*******************************************************************************
474 * Protected helper function for ReverseTapeInterface
475 */
476
477 protected:
478
480 template<typename Lhs>
482 bool unusedIndex) {
483 if (TapeTypes::IsLinearIndexHandler) {
484 statementData.reserveItems(1);
485 }
486
487 bool generatedNewIndex;
488 if (unusedIndex) {
489 generatedNewIndex = indexManager.get().template assignUnusedIndex<Impl>(value.cast().getIdentifier());
490 } else {
491 generatedNewIndex = indexManager.get().template assignIndex<Impl>(value.cast().getIdentifier());
492 }
493 checkPrimalSize(generatedNewIndex);
494
495 Real& primalEntry = primals[value.cast().getIdentifier()];
496 if (TapeTypes::IsLinearIndexHandler) {
497 cast().pushStmtData(value.cast().getIdentifier(), Config::StatementInputTag, primalEntry,
498 StatementEvaluator::template createHandle<Impl, Impl, Lhs>());
499 }
500
501 Real oldValue = primalEntry;
502 primalEntry = value.cast().value();
503
504 return oldValue;
505 }
506
507 public:
508
511
513 template<typename Lhs>
518
523 CODI_UNUSED(adjointsManagement);
524
525 for (Gradient& gradient : adjoints) {
526 gradient = Gradient();
527 }
528 }
529
533 CODI_INLINE void reset(bool resetAdjoints = true,
535 for (Real& primal : primals) {
536 primal = Real();
537 }
538
539 Base::reset(resetAdjoints, adjointsManagement);
540 }
541
543
544 protected:
545
549 std::string name;
550 if (TapeTypes::IsLinearIndexHandler) {
551 name = "CoDi Tape Statistics ( PrimalValueLinearTape )";
552 } else {
553 name = "CoDi Tape Statistics ( PrimalValueReuseTape )";
554 }
555 TapeValues values = TapeValues(name);
556
557 size_t nAdjoints = indexManager.get().getLargestCreatedIndex();
558 double memoryAdjoints = static_cast<double>(nAdjoints) * static_cast<double>(sizeof(Gradient));
559
560 size_t nPrimals = indexManager.get().getLargestCreatedIndex();
561 double memoryPrimals = static_cast<double>(nPrimals) * static_cast<double>(sizeof(Real));
562
563 values.addSection("Adjoint vector");
564 values.addUnsignedLongEntry("Number of adjoints", nAdjoints);
565 values.addDoubleEntry("Memory allocated", memoryAdjoints, true, true);
566
567 values.addSection("Primal vector");
568 values.addUnsignedLongEntry("Number of primals", nPrimals);
569 values.addDoubleEntry("Memory allocated", memoryPrimals, true, true);
570
571 values.addSection("Index manager");
572 indexManager.get().addToTapeValues(values);
573
574 values.addSection("Statement entries");
575 statementData.addToTapeValues(values);
576 values.addSection("Rhs identifiers entries");
577 rhsIdentiferData.addToTapeValues(values);
578 values.addSection("Passive value entries");
579 passiveValueData.addToTapeValues(values);
580 values.addSection("Constant value entries");
581 constantValueData.addToTapeValues(values);
582
583 return values;
584 }
585
586 /******************************************************************************
587 * Protected helper function for CustomAdjointVectorEvaluationTapeInterface
588 */
589
591 template<typename Adjoint>
593 CODI_UNUSED(vectorAccess, data);
594
595#if CODI_VariableAdjointInterfaceInPrimalTapes
596 return vectorAccess;
597#else
598 CODI_STATIC_ASSERT(CODI_T(std::is_same<Adjoint, Gradient>::value),
599 "Please enable 'CODI_VariableAdjointInterfaceInPrimalTapes' in order"
600 " to use custom adjoint vectors in the primal value tapes.");
601
602 return data;
603#endif
604 }
605
607 struct IncrementForwardLogic : public JacobianComputationLogic<IncrementForwardLogic> {
608 public:
609
611 template<typename Node>
613 ADJOINT_VECTOR_TYPE* adjointVector) {
615
617#if CODI_VariableAdjointInterfaceInPrimalTapes
618 adjointVector->updateTangentWithLhs(node.getIdentifier(), jacobian);
619#else
620 lhsTangent += jacobian * adjointVector[node.getIdentifier()];
621#endif
622 }
623 }
624 };
625
627 CODI_WRAP_FUNCTION(Wrap_internalEvaluateForward_EvalStatements, Impl::internalEvaluateForward_EvalStatements);
628
630 template<bool copyPrimal, typename Adjoint>
631 CODI_NO_INLINE void internalEvaluateForward(Position const& start, Position const& end, Adjoint* data) {
632 std::vector<Real> primalsCopy(0);
633 Real* primalData = primals.data();
634
635 if (copyPrimal) {
637 primalData = primalsCopy.data();
638 }
639
640 VectorAccess<Adjoint> vectorAccess(data, primalData);
641
642 ADJOINT_VECTOR_TYPE* dataVector = selectAdjointVector(&vectorAccess, data);
643
645 cast(), start, end, &vectorAccess, EventHints::EvaluationKind::Forward, EventHints::Endpoint::Begin);
646
648 Base::llfByteData.evaluateForward(start, end, evalFunc, cast(), primalData, dataVector);
649
650 EventSystem<Impl>::notifyTapeEvaluateListeners(cast(), start, end, &vectorAccess,
651 EventHints::EvaluationKind::Forward, EventHints::Endpoint::End);
652 }
653
655 struct IncrementReversalLogic : public JacobianComputationLogic<IncrementReversalLogic> {
656 public:
657
659 template<typename Node>
661 ADJOINT_VECTOR_TYPE* adjointVector) {
663
665#if CODI_VariableAdjointInterfaceInPrimalTapes
666 adjointVector->updateAdjointWithLhs(node.getIdentifier(), jacobian);
667#else
668 adjointVector[node.getIdentifier()] += jacobian * lhsAdjoint;
669#endif
670 }
671 }
672 };
673
675 CODI_WRAP_FUNCTION(Wrap_internalEvaluateReverse_EvalStatements, Impl::internalEvaluateReverse_EvalStatements);
676
678 template<bool copyPrimal, typename Adjoint>
679 CODI_INLINE void internalEvaluateReverse(Position const& start, Position const& end, Adjoint* data) {
680 Real* primalData = primals.data();
681
682 if (copyPrimal) {
684 primalData = primalsCopy.data();
685 }
686
687 VectorAccess<Adjoint> vectorAccess(data, primalData);
688
689 ADJOINT_VECTOR_TYPE* dataVector = selectAdjointVector(&vectorAccess, data);
690
692 cast(), start, end, &vectorAccess, EventHints::EvaluationKind::Reverse, EventHints::Endpoint::Begin);
693
695 Base::llfByteData.evaluateReverse(start, end, evalFunc, cast(), primalData, dataVector);
696
697 EventSystem<Impl>::notifyTapeEvaluateListeners(cast(), start, end, &vectorAccess,
698 EventHints::EvaluationKind::Reverse, EventHints::Endpoint::End);
699 }
700
701 public:
702
705
706 using Base::evaluate;
707
709 template<typename Adjoint>
710 CODI_INLINE void evaluate(Position const& start, Position const& end, Adjoint* data) {
711 internalEvaluateReverse<!TapeTypes::IsLinearIndexHandler>(start, end, data);
712 }
713
715 template<typename Adjoint>
716 CODI_INLINE void evaluateForward(Position const& start, Position const& end, Adjoint* data) {
717 internalEvaluateForward<!TapeTypes::IsLinearIndexHandler>(start, end, data);
718 }
719
721 /*******************************************************************************/
724
726 CODI_INLINE void swap(Impl& other) {
727 // Index manager does not need to be swapped, it is either static or swapped with the vector data.
728 // Vectors are swapped recursively in the base class.
729
730 std::swap(adjoints, other.adjoints);
731 std::swap(primals, other.primals);
732
733 Base::swap(other);
734
735 // Ensure that the primals vector of both tapes are sized according to the index manager.
736 checkPrimalSize(true);
737 other.checkPrimalSize(true);
738 }
739
742 adjoints.resize(1);
743 }
744
747 checkAdjointSize(indexManager.get().getLargestCreatedIndex());
748 }
749
753
757
759 size_t getParameter(TapeParameters parameter) const {
760 switch (parameter) {
762 return adjoints.size();
763 break;
765 return constantValueData.getDataSize();
766 break;
768 return indexManager.get().getLargestCreatedIndex();
769 break;
771 return passiveValueData.getDataSize();
772 break;
774 return rhsIdentiferData.getDataSize();
775 break;
777 return primals.size();
778 break;
780 return statementData.getDataSize();
781 default:
782 return Base::getParameter(parameter);
783 break;
784 }
785 }
786
788 void setParameter(TapeParameters parameter, size_t value) {
789 switch (parameter) {
791 adjoints.resize(value);
792 break;
794 constantValueData.resize(value);
795 break;
797 CODI_EXCEPTION("Tried to set a get only option.");
798 break;
800 passiveValueData.resize(value);
801 break;
803 rhsIdentiferData.resize(value);
804 break;
806 primals.resize(value);
807 break;
809 return statementData.resize(value);
810 default:
811 Base::setParameter(parameter, value);
812 break;
813 }
814 }
815
820
822 template<typename Adjoint>
824 return new VectorAccess<Adjoint>(data, primals.data());
825 }
826
829 delete access;
830 }
831
833 /*******************************************************************************/
836
838 template<typename Lhs>
842
844 /*******************************************************************************/
847
849
853 void evaluateForward(Position const& start, Position const& end,
855 if (AdjointsManagement::Automatic == adjointsManagement) {
856 checkAdjointSize(indexManager.get().getLargestCreatedIndex());
857 }
858
859 codiAssert(indexManager.get().getLargestCreatedIndex() < (Identifier)adjoints.size());
860
861 cast().evaluateForward(start, end, adjoints.data());
862 }
863
865 /******************************************************************************
866 * Protected helper function for ManualStatementPushTapeInterface
867 */
868
869 protected:
870
873 template<size_t T_size>
875 public:
876
877 static size_t constexpr size = T_size;
878
879 /*******************************************************************************/
882
884 template<typename Expr, typename... Args>
885 static Real statementEvaluateForward(Args&&... args) {
886 CODI_UNUSED(args...);
887 CODI_EXCEPTION("Forward evaluation of jacobian statement not possible.");
888 }
889
891 template<typename Expr, typename... Args>
892 static Real statementEvaluatePrimal(Args&&... args) {
893 CODI_UNUSED(args...);
894 CODI_EXCEPTION("Primal evaluation of jacobian statement not possible.");
895 }
896
898 template<typename Expr>
899 static void statementEvaluateReverse(Real* primalVector, ADJOINT_VECTOR_TYPE* adjointVector,
900 Gradient lhsAdjoint, Config::ArgumentSize numberOfPassiveArguments,
901 size_t& curConstantPos, PassiveReal const* const constantValues,
902 size_t& curPassivePos, Real const* const passiveValues,
903 size_t& curRhsIdentifiersPos, Identifier const* const rhsIdentifiers) {
904 CODI_UNUSED(primalVector, curConstantPos, constantValues);
905
906 size_t endPos = curRhsIdentifiersPos - numberOfPassiveArguments;
907
908 bool const lhsZero = evalJacobianReverse(adjointVector, lhsAdjoint, curPassivePos, passiveValues,
909 curRhsIdentifiersPos, rhsIdentifiers, endPos);
910
911 if (Config::SkipZeroAdjointEvaluation && lhsZero) {
912 curPassivePos -= numberOfPassiveArguments;
913 curRhsIdentifiersPos -= numberOfPassiveArguments;
914 }
915 }
916
918 /*******************************************************************************/
921
923 template<typename Expr, typename... Args>
924 static Real statementEvaluateForwardInner(Args&&... args) {
925 CODI_UNUSED(args...);
926 CODI_EXCEPTION("Forward evaluation of jacobian statement not possible.");
927
928 return Real();
929 }
930
932 template<typename Expr, typename... Args>
933 static Real statementEvaluatePrimalInner(Args&&... args) {
934 CODI_UNUSED(args...);
935 CODI_EXCEPTION("Primal evaluation of jacobian statement not possible.");
936
937 return Real();
938 }
939
941 template<typename Expr>
942 static void statementEvaluateReverseInner(Real* primalVector, ADJOINT_VECTOR_TYPE* adjointVector,
943 Gradient lhsAdjoint, size_t& curConstantPos,
944 PassiveReal const* const constantValues,
945 size_t& curRhsIdentifiersPos,
946 Identifier const* const rhsIdentifiers) {
947 CODI_UNUSED(primalVector, curConstantPos, constantValues);
948
949 size_t passivePos = size;
950 size_t rhsPos = curRhsIdentifiersPos + size;
951 size_t endPos = curRhsIdentifiersPos;
952
953 evalJacobianReverse(adjointVector, lhsAdjoint, passivePos, primalVector, rhsPos, rhsIdentifiers, endPos);
954 }
955
957
958 private:
959
960 static bool evalJacobianReverse(ADJOINT_VECTOR_TYPE* adjointVector, Gradient lhsAdjoint,
961 size_t& curPassivePos, Real const* const passiveValues,
962 size_t& curRhsIdentifiersPos, Identifier const* const rhsIdentifiers,
963 size_t endRhsIdentifiersPos) {
964#if CODI_VariableAdjointInterfaceInPrimalTapes
965 CODI_UNUSED(lhsAdjoint);
966 bool const lhsZero = adjointVector->isLhsZero();
967#else
968 bool const lhsZero = RealTraits::isTotalZero(lhsAdjoint);
969#endif
970
972 while (curRhsIdentifiersPos > endRhsIdentifiersPos) {
973 curPassivePos -= 1;
974 curRhsIdentifiersPos -= 1;
975
976 Real const& jacobian = passiveValues[curPassivePos];
977#if CODI_VariableAdjointInterfaceInPrimalTapes
978 adjointVector->updateAdjointWithLhs(rhsIdentifiers[curRhsIdentifiersPos], jacobian);
979#else
980 adjointVector[rhsIdentifiers[curRhsIdentifiersPos]] += jacobian * lhsAdjoint;
981#endif
982 }
983 }
984
985 return lhsZero;
986 }
987 };
988
989 public:
990
991 /*******************************************************************************/
994
996 void pushJacobianManual(Real const& jacobian, Real const& value, Identifier const& index) {
997 CODI_UNUSED(value);
998
999 cast().incrementManualPushCounter();
1000
1001 passiveValueData.pushData(jacobian);
1002 rhsIdentiferData.pushData(index);
1003
1005 if (this->manualPushCounter == this->manualPushGoal) {
1006 // emit statement event
1007 Real* jacobians;
1008 Identifier* rhsIdentifiers;
1009 passiveValueData.getDataPointers(jacobians);
1010 rhsIdentiferData.getDataPointers(rhsIdentifiers);
1011 jacobians -= this->manualPushGoal;
1012 rhsIdentifiers -= this->manualPushGoal;
1013
1016 rhsIdentifiers, jacobians);
1017 }
1018 }
1019 }
1020
1022 void storeManual(Real const& lhsValue, Identifier& lhsIndex, Config::ArgumentSize const& size) {
1023 CODI_UNUSED(lhsValue);
1024
1026
1027 statementData.reserveItems(1);
1028 rhsIdentiferData.reserveItems(size);
1029 passiveValueData.reserveItems(size);
1030
1031 indexManager.get().template assignIndex<Impl>(lhsIndex);
1032 Real& primalEntry = primals[lhsIndex];
1033 cast().pushStmtData(lhsIndex, size, primalEntry, PrimalValueBaseTape::jacobianExpressions[size]);
1034
1035 primalEntry = lhsValue;
1036
1037 cast().initializeManualPushData(lhsValue, lhsIndex, size);
1038 }
1039
1041 /*******************************************************************************/
1044
1047 statementData.reserveItems(1);
1048
1049 Base::internalStoreLowLevelFunction(token, size, data);
1050
1051 Identifier lhsIndex = Identifier();
1052 if (LinearIndexHandling) {
1053 indexManager.get().template assignIndex<Impl>(lhsIndex);
1054 }
1055 cast().pushStmtData(lhsIndex, Config::StatementLowLevelFunctionTag, Real(), EvalHandle());
1056 }
1057
1059 /*******************************************************************************/
1062
1066 CODI_INLINE void evaluate(Position const& start, Position const& end,
1068 if (AdjointsManagement::Automatic == adjointsManagement) {
1069 checkAdjointSize(indexManager.get().getLargestCreatedIndex());
1070 }
1071
1072 codiAssert(indexManager.get().getLargestCreatedIndex() < (Identifier)adjoints.size());
1073
1074 evaluate(start, end, adjoints.data());
1075 }
1076
1080 CODI_INLINE void resetTo(Position const& pos, bool resetAdjoints = true,
1082 cast().internalResetPrimalValues(pos);
1083
1084 Base::resetTo(pos, resetAdjoints, adjointsManagement);
1085 }
1086
1088 /*******************************************************************************/
1091
1095 void evaluateKeepState(Position const& start, Position const& end,
1097 if (AdjointsManagement::Automatic == adjointsManagement) {
1098 checkAdjointSize(indexManager.get().getLargestCreatedIndex());
1099 }
1100
1101 codiAssert(indexManager.get().getLargestCreatedIndex() < (Identifier)adjoints.size());
1102
1103 internalEvaluateReverse<false>(start, end, adjoints.data());
1104
1105 if (!TapeTypes::IsLinearIndexHandler) {
1106 evaluatePrimal(end, start);
1107 }
1108 }
1109
1113 void evaluateForwardKeepState(Position const& start, Position const& end,
1115 if (AdjointsManagement::Automatic == adjointsManagement) {
1116 checkAdjointSize(indexManager.get().getLargestCreatedIndex());
1117 }
1118
1119 codiAssert(indexManager.get().getLargestCreatedIndex() < (Identifier)adjoints.size());
1120
1121 if (!TapeTypes::IsLinearIndexHandler) {
1122 cast().internalResetPrimalValues(end);
1123 }
1124
1125 internalEvaluateForward<false>(start, end, adjoints.data());
1126 }
1127
1128 protected:
1129
1130 /******************************************************************************
1131 * Protected helper function for PrimalEvaluationTapeInterface
1132 */
1133
1135 CODI_WRAP_FUNCTION(Wrap_internalEvaluatePrimal_EvalStatements, Impl::internalEvaluatePrimal_EvalStatements);
1136
1137 public:
1138
1140 /*******************************************************************************/
1143
1145
1147 CODI_NO_INLINE void evaluatePrimal(Position const& start, Position const& end) {
1148 // TODO: implement primal value only accessor
1150
1151 EventSystem<Impl>::notifyTapeEvaluateListeners(cast(), start, end, &primalAdjointAccess,
1152 EventHints::EvaluationKind::Primal, EventHints::Endpoint::Begin);
1153
1155 Base::llfByteData.evaluateForward(start, end, evalFunc, cast(), primals.data());
1156
1157 EventSystem<Impl>::notifyTapeEvaluateListeners(cast(), start, end, &primalAdjointAccess,
1158 EventHints::EvaluationKind::Primal, EventHints::Endpoint::End);
1159 }
1160
1162 Real& primal(Identifier const& identifier) {
1163 return primals[identifier];
1164 }
1165
1167 Real const& primal(Identifier const& identifier) const {
1168 return primals[identifier];
1169 }
1170
1172 /*******************************************************************************/
1175
1177 template<typename Rhs>
1178 static Real statementEvaluateForwardInner(Real* primalVector, ADJOINT_VECTOR_TYPE* adjointVector,
1179 Gradient& lhsTangent, size_t& curConstantPos,
1180 PassiveReal const* const constantValues, size_t& curRhsIdentifiersPos,
1181 Identifier const* const rhsIdentifiers) {
1183 using StaticRhs = typename Constructor::ResultType;
1184
1185 StaticRhs staticsRhs = Constructor::construct(primalVector, &rhsIdentifiers[curRhsIdentifiersPos],
1186 &constantValues[curConstantPos]);
1187
1188 IncrementForwardLogic incrementForward;
1189
1190 incrementForward.eval(staticsRhs, Real(1.0), lhsTangent, adjointVector);
1191 return staticsRhs.getValue();
1192 }
1193
1195 template<typename Func>
1196 static Real statementEvaluateForwardFull(Func const& evalInner, size_t const& maxActiveArgs,
1197 size_t const& maxConstantArgs, Real* primalVector,
1198 ADJOINT_VECTOR_TYPE* adjointVector, Gradient& lhsTangent,
1199 Config::ArgumentSize numberOfPassiveArguments, size_t& curConstantPos,
1200 PassiveReal const* const constantValues, size_t& curPassivePos,
1201 Real const* const passiveValues, size_t& curRhsIdentifiersPos,
1202 Identifier const* const rhsIdentifiers) {
1203 for (Config::ArgumentSize curPos = 0; curPos < numberOfPassiveArguments; curPos += 1) {
1204 primalVector[curPos] = passiveValues[curPassivePos + curPos];
1205 }
1206
1207 Real ret = evalInner(primalVector, adjointVector, lhsTangent, curConstantPos, constantValues,
1208 curRhsIdentifiersPos, rhsIdentifiers);
1209
1210 // Adapt vector positions.
1211 curConstantPos += maxConstantArgs;
1212 curPassivePos += numberOfPassiveArguments;
1213 curRhsIdentifiersPos += maxActiveArgs;
1214
1215 return ret;
1216 }
1217
1219 template<typename Rhs>
1220 static Real statementEvaluatePrimalInner(Real* primalVector, size_t& curConstantPos,
1221 PassiveReal const* const constantValues, size_t& curRhsIdentifiersPos,
1222 Identifier const* const rhsIdentifiers) {
1224 using StaticRhs = typename Constructor::ResultType;
1225
1226 StaticRhs staticsRhs = Constructor::construct(primalVector, &rhsIdentifiers[curRhsIdentifiersPos],
1227 &constantValues[curConstantPos]);
1228
1229 return staticsRhs.getValue();
1230 }
1231
1233 template<typename Func>
1234 static Real statementEvaluatePrimalFull(Func const& evalInner, size_t const& maxActiveArgs,
1235 size_t const& maxConstantArgs, Real* primalVector,
1236 Config::ArgumentSize numberOfPassiveArguments, size_t& curConstantPos,
1237 PassiveReal const* const constantValues, size_t& curPassivePos,
1238 Real const* const passiveValues, size_t& curRhsIdentifiersPos,
1239 Identifier const* const rhsIdentifiers) {
1240 for (Config::ArgumentSize curPos = 0; curPos < numberOfPassiveArguments; curPos += 1) {
1241 primalVector[curPos] = passiveValues[curPassivePos + curPos];
1242 }
1243
1244 Real ret = evalInner(primalVector, curConstantPos, constantValues, curRhsIdentifiersPos, rhsIdentifiers);
1245
1246 // Adapt vector positions.
1247 curConstantPos += maxConstantArgs;
1248 curPassivePos += numberOfPassiveArguments;
1249 curRhsIdentifiersPos += maxActiveArgs;
1250
1251 return ret;
1252 }
1253
1255 template<typename Rhs>
1256 CODI_INLINE static void statementEvaluateReverseInner(Real* primalVector, ADJOINT_VECTOR_TYPE* adjointVector,
1257 Gradient lhsAdjoint, size_t& curConstantPos,
1258 PassiveReal const* const constantValues,
1259 size_t& curRhsIdentifiersPos,
1260 Identifier const* const rhsIdentifiers) {
1262 using StaticRhs = typename Constructor::ResultType;
1263
1264 StaticRhs staticsRhs = Constructor::construct(primalVector, &rhsIdentifiers[curRhsIdentifiersPos],
1265 &constantValues[curConstantPos]);
1266
1267 IncrementReversalLogic incrementReverse;
1268
1269 incrementReverse.eval(staticsRhs, Real(1.0), const_cast<Gradient const&>(lhsAdjoint), adjointVector);
1270 }
1271
1273 template<typename Func>
1275 Func const& evalInner, size_t const& maxActiveArgs, size_t const& maxConstantArgs, Real* primalVector,
1276 ADJOINT_VECTOR_TYPE* adjointVector, Gradient lhsAdjoint, Config::ArgumentSize numberOfPassiveArguments,
1277 size_t& curConstantPos, PassiveReal const* const constantValues, size_t& curPassivePos,
1278 Real const* const passiveValues, size_t& curRhsIdentifiersPos, Identifier const* const rhsIdentifiers) {
1279 // Adapt vector positions.
1280 curConstantPos -= maxConstantArgs;
1281 curPassivePos -= numberOfPassiveArguments;
1282 curRhsIdentifiersPos -= maxActiveArgs;
1283
1284#if CODI_VariableAdjointInterfaceInPrimalTapes
1285 if (CODI_ENABLE_CHECK(Config::SkipZeroAdjointEvaluation, !adjointVector->isLhsZero())) CODI_Likely {
1286#else
1288#endif
1289 for (Config::ArgumentSize curPos = 0; curPos < numberOfPassiveArguments; curPos += 1) {
1290 primalVector[curPos] = passiveValues[curPassivePos + curPos];
1291 }
1292
1293 evalInner(primalVector, adjointVector, lhsAdjoint, curConstantPos, constantValues, curRhsIdentifiersPos,
1294 rhsIdentifiers);
1295 }
1296 }
1297
1299 /*******************************************************************************/
1302
1304 template<typename Rhs>
1305 static Real statementEvaluateForward(Real* primalVector, ADJOINT_VECTOR_TYPE* adjointVector, Gradient& lhsTangent,
1306 Config::ArgumentSize numberOfPassiveArguments, size_t& curConstantPos,
1307 PassiveReal const* const constantValues, size_t& curPassivePos,
1308 Real const* const passiveValues, size_t& curRhsIdentifiersPos,
1309 Identifier const* const rhsIdentifiers) {
1310 size_t constexpr MaxActiveArgs = ExpressionTraits::NumberOfActiveTypeArguments<Rhs>::value;
1311 size_t constexpr MaxConstantArgs = ExpressionTraits::NumberOfConstantTypeArguments<Rhs>::value;
1312
1313 return statementEvaluateForwardFull(statementEvaluateForwardInner<Rhs>, MaxActiveArgs, MaxConstantArgs,
1314 primalVector, adjointVector, lhsTangent, numberOfPassiveArguments,
1315 curConstantPos, constantValues, curPassivePos, passiveValues,
1316 curRhsIdentifiersPos, rhsIdentifiers);
1317 }
1318
1320 template<typename Rhs>
1321 static Real statementEvaluatePrimal(Real* primalVector, Config::ArgumentSize numberOfPassiveArguments,
1322 size_t& curConstantPos, PassiveReal const* const constantValues,
1323 size_t& curPassivePos, Real const* const passiveValues,
1324 size_t& curRhsIdentifiersPos, Identifier const* const rhsIdentifiers) {
1325 size_t constexpr MaxActiveArgs = ExpressionTraits::NumberOfActiveTypeArguments<Rhs>::value;
1326 size_t constexpr MaxConstantArgs = ExpressionTraits::NumberOfConstantTypeArguments<Rhs>::value;
1327
1328 return statementEvaluatePrimalFull(statementEvaluatePrimalInner<Rhs>, MaxActiveArgs, MaxConstantArgs,
1329 primalVector, numberOfPassiveArguments, curConstantPos, constantValues,
1330 curPassivePos, passiveValues, curRhsIdentifiersPos, rhsIdentifiers);
1331 }
1332
1334 template<typename Rhs>
1335 CODI_INLINE static void statementEvaluateReverse(Real* primalVector, ADJOINT_VECTOR_TYPE* adjointVector,
1336 Gradient lhsAdjoint,
1337 Config::ArgumentSize numberOfPassiveArguments,
1338 size_t& curConstantPos, PassiveReal const* const constantValues,
1339 size_t& curPassivePos, Real const* const passiveValues,
1340 size_t& curRhsIdentifiersPos,
1341 Identifier const* const rhsIdentifiers) {
1342 size_t constexpr maxActiveArgs = ExpressionTraits::NumberOfActiveTypeArguments<Rhs>::value;
1343 size_t constexpr maxConstantArgs = ExpressionTraits::NumberOfConstantTypeArguments<Rhs>::value;
1344 statementEvaluateReverseFull(statementEvaluateReverseInner<Rhs>, maxActiveArgs, maxConstantArgs, primalVector,
1345 adjointVector, lhsAdjoint, numberOfPassiveArguments, curConstantPos,
1346 constantValues, curPassivePos, passiveValues, curRhsIdentifiersPos,
1347 rhsIdentifiers);
1348 }
1349
1350 private:
1351
1352 CODI_INLINE void checkAdjointSize(Identifier const& identifier) {
1353 if (identifier >= (Identifier)adjoints.size()) {
1354 resizeAdjointsVector();
1355 }
1356 }
1357
1358 CODI_INLINE void checkPrimalSize(bool generatedNewIndex) {
1359 if (generatedNewIndex && indexManager.get().getLargestCreatedIndex() >= (Identifier)primals.size()) {
1360 resizePrimalVector();
1361 }
1362 }
1363
1364 CODI_NO_INLINE void resizeAdjointsVector() {
1365 // overallocate as next multiple of Config::ChunkSize
1366 adjoints.resize(getNextMultiple((size_t)indexManager.get().getLargestCreatedIndex() + 1, Config::ChunkSize));
1367 }
1368
1369 CODI_NO_INLINE void resizePrimalVector() {
1370 // overallocate as next multiple of Config::ChunkSize
1371 primals.resize(getNextMultiple((size_t)indexManager.get().getLargestCreatedIndex() + 1, Config::ChunkSize));
1372 }
1373 };
1374
1376 template<size_t size>
1378
1380 template<size_t size>
1382 static size_t constexpr value = size;
1383 };
1384
1386 template<size_t size>
1388 static size_t constexpr value = 0;
1389 };
1390
1391#define CREATE_EXPRESSION(size) \
1392 TapeTypes::StatementEvaluator::template createHandle<Impl, typename Impl::template JacobianStatementGenerator<size>, \
1393 JacobianExpression<size>>()
1394
1396 template<typename TapeTypes, typename Impl>
1397 const CODI_DD(typename TapeTypes::EvalHandle,
1399 CREATE_EXPRESSION(0), CREATE_EXPRESSION(1), CREATE_EXPRESSION(2), CREATE_EXPRESSION(3),
1400 CREATE_EXPRESSION(4), CREATE_EXPRESSION(5), CREATE_EXPRESSION(6), CREATE_EXPRESSION(7),
1401 CREATE_EXPRESSION(8), CREATE_EXPRESSION(9), CREATE_EXPRESSION(10), CREATE_EXPRESSION(11),
1402 CREATE_EXPRESSION(12), CREATE_EXPRESSION(13), CREATE_EXPRESSION(14), CREATE_EXPRESSION(15),
1403 CREATE_EXPRESSION(16), CREATE_EXPRESSION(17), CREATE_EXPRESSION(18), CREATE_EXPRESSION(19),
1404 CREATE_EXPRESSION(20), CREATE_EXPRESSION(21), CREATE_EXPRESSION(22), CREATE_EXPRESSION(23),
1405 CREATE_EXPRESSION(24), CREATE_EXPRESSION(25), CREATE_EXPRESSION(26), CREATE_EXPRESSION(27),
1406 CREATE_EXPRESSION(28), CREATE_EXPRESSION(29), CREATE_EXPRESSION(30), CREATE_EXPRESSION(31),
1407 CREATE_EXPRESSION(32), CREATE_EXPRESSION(33), CREATE_EXPRESSION(34), CREATE_EXPRESSION(35),
1408 CREATE_EXPRESSION(36), CREATE_EXPRESSION(37), CREATE_EXPRESSION(38), CREATE_EXPRESSION(39),
1409 CREATE_EXPRESSION(40), CREATE_EXPRESSION(41), CREATE_EXPRESSION(42), CREATE_EXPRESSION(43),
1410 CREATE_EXPRESSION(44), CREATE_EXPRESSION(45), CREATE_EXPRESSION(46), CREATE_EXPRESSION(47),
1411 CREATE_EXPRESSION(48), CREATE_EXPRESSION(49), CREATE_EXPRESSION(50), CREATE_EXPRESSION(51),
1412 CREATE_EXPRESSION(52), CREATE_EXPRESSION(53), CREATE_EXPRESSION(54), CREATE_EXPRESSION(55),
1413 CREATE_EXPRESSION(56), CREATE_EXPRESSION(57), CREATE_EXPRESSION(58), CREATE_EXPRESSION(59),
1414 CREATE_EXPRESSION(60), CREATE_EXPRESSION(61), CREATE_EXPRESSION(62), CREATE_EXPRESSION(63),
1415 CREATE_EXPRESSION(64), CREATE_EXPRESSION(65), CREATE_EXPRESSION(66), CREATE_EXPRESSION(67),
1416 CREATE_EXPRESSION(68), CREATE_EXPRESSION(69), CREATE_EXPRESSION(70), CREATE_EXPRESSION(71),
1417 CREATE_EXPRESSION(72), CREATE_EXPRESSION(73), CREATE_EXPRESSION(74), CREATE_EXPRESSION(75),
1418 CREATE_EXPRESSION(76), CREATE_EXPRESSION(77), CREATE_EXPRESSION(78), CREATE_EXPRESSION(79),
1419 CREATE_EXPRESSION(80), CREATE_EXPRESSION(81), CREATE_EXPRESSION(82), CREATE_EXPRESSION(83),
1420 CREATE_EXPRESSION(84), CREATE_EXPRESSION(85), CREATE_EXPRESSION(86), CREATE_EXPRESSION(87),
1421 CREATE_EXPRESSION(88), CREATE_EXPRESSION(89), CREATE_EXPRESSION(90), CREATE_EXPRESSION(91),
1422 CREATE_EXPRESSION(92), CREATE_EXPRESSION(93), CREATE_EXPRESSION(94), CREATE_EXPRESSION(95),
1423 CREATE_EXPRESSION(96), CREATE_EXPRESSION(97), CREATE_EXPRESSION(98), CREATE_EXPRESSION(99),
1424 CREATE_EXPRESSION(100), CREATE_EXPRESSION(101), CREATE_EXPRESSION(102), CREATE_EXPRESSION(103),
1425 CREATE_EXPRESSION(104), CREATE_EXPRESSION(105), CREATE_EXPRESSION(106), CREATE_EXPRESSION(107),
1426 CREATE_EXPRESSION(108), CREATE_EXPRESSION(109), CREATE_EXPRESSION(110), CREATE_EXPRESSION(111),
1427 CREATE_EXPRESSION(112), CREATE_EXPRESSION(113), CREATE_EXPRESSION(114), CREATE_EXPRESSION(115),
1428 CREATE_EXPRESSION(116), CREATE_EXPRESSION(117), CREATE_EXPRESSION(118), CREATE_EXPRESSION(119),
1429 CREATE_EXPRESSION(120), CREATE_EXPRESSION(121), CREATE_EXPRESSION(122), CREATE_EXPRESSION(123),
1430 CREATE_EXPRESSION(124), CREATE_EXPRESSION(125), CREATE_EXPRESSION(126), CREATE_EXPRESSION(127),
1431 CREATE_EXPRESSION(128), CREATE_EXPRESSION(129), CREATE_EXPRESSION(130), CREATE_EXPRESSION(131),
1432 CREATE_EXPRESSION(132), CREATE_EXPRESSION(133), CREATE_EXPRESSION(134), CREATE_EXPRESSION(135),
1433 CREATE_EXPRESSION(136), CREATE_EXPRESSION(137), CREATE_EXPRESSION(138), CREATE_EXPRESSION(139),
1434 CREATE_EXPRESSION(140), CREATE_EXPRESSION(141), CREATE_EXPRESSION(142), CREATE_EXPRESSION(143),
1435 CREATE_EXPRESSION(144), CREATE_EXPRESSION(145), CREATE_EXPRESSION(146), CREATE_EXPRESSION(147),
1436 CREATE_EXPRESSION(148), CREATE_EXPRESSION(149), CREATE_EXPRESSION(150), CREATE_EXPRESSION(151),
1437 CREATE_EXPRESSION(152), CREATE_EXPRESSION(153), CREATE_EXPRESSION(154), CREATE_EXPRESSION(155),
1438 CREATE_EXPRESSION(156), CREATE_EXPRESSION(157), CREATE_EXPRESSION(158), CREATE_EXPRESSION(159),
1439 CREATE_EXPRESSION(160), CREATE_EXPRESSION(161), CREATE_EXPRESSION(162), CREATE_EXPRESSION(163),
1440 CREATE_EXPRESSION(164), CREATE_EXPRESSION(165), CREATE_EXPRESSION(166), CREATE_EXPRESSION(167),
1441 CREATE_EXPRESSION(168), CREATE_EXPRESSION(169), CREATE_EXPRESSION(170), CREATE_EXPRESSION(171),
1442 CREATE_EXPRESSION(172), CREATE_EXPRESSION(173), CREATE_EXPRESSION(174), CREATE_EXPRESSION(175),
1443 CREATE_EXPRESSION(176), CREATE_EXPRESSION(177), CREATE_EXPRESSION(178), CREATE_EXPRESSION(179),
1444 CREATE_EXPRESSION(180), CREATE_EXPRESSION(181), CREATE_EXPRESSION(182), CREATE_EXPRESSION(183),
1445 CREATE_EXPRESSION(184), CREATE_EXPRESSION(185), CREATE_EXPRESSION(186), CREATE_EXPRESSION(187),
1446 CREATE_EXPRESSION(188), CREATE_EXPRESSION(189), CREATE_EXPRESSION(190), CREATE_EXPRESSION(191),
1447 CREATE_EXPRESSION(192), CREATE_EXPRESSION(193), CREATE_EXPRESSION(194), CREATE_EXPRESSION(195),
1448 CREATE_EXPRESSION(196), CREATE_EXPRESSION(197), CREATE_EXPRESSION(198), CREATE_EXPRESSION(199),
1449 CREATE_EXPRESSION(200), CREATE_EXPRESSION(201), CREATE_EXPRESSION(202), CREATE_EXPRESSION(203),
1450 CREATE_EXPRESSION(204), CREATE_EXPRESSION(205), CREATE_EXPRESSION(206), CREATE_EXPRESSION(207),
1451 CREATE_EXPRESSION(208), CREATE_EXPRESSION(209), CREATE_EXPRESSION(210), CREATE_EXPRESSION(211),
1452 CREATE_EXPRESSION(212), CREATE_EXPRESSION(213), CREATE_EXPRESSION(214), CREATE_EXPRESSION(215),
1453 CREATE_EXPRESSION(216), CREATE_EXPRESSION(217), CREATE_EXPRESSION(218), CREATE_EXPRESSION(219),
1454 CREATE_EXPRESSION(220), CREATE_EXPRESSION(221), CREATE_EXPRESSION(222), CREATE_EXPRESSION(223),
1455 CREATE_EXPRESSION(224), CREATE_EXPRESSION(225), CREATE_EXPRESSION(226), CREATE_EXPRESSION(227),
1456 CREATE_EXPRESSION(228), CREATE_EXPRESSION(229), CREATE_EXPRESSION(230), CREATE_EXPRESSION(231),
1457 CREATE_EXPRESSION(232), CREATE_EXPRESSION(233), CREATE_EXPRESSION(234), CREATE_EXPRESSION(235),
1458 CREATE_EXPRESSION(236), CREATE_EXPRESSION(237), CREATE_EXPRESSION(238), CREATE_EXPRESSION(239),
1459 CREATE_EXPRESSION(240), CREATE_EXPRESSION(241), CREATE_EXPRESSION(242), CREATE_EXPRESSION(243),
1460 CREATE_EXPRESSION(244), CREATE_EXPRESSION(245), CREATE_EXPRESSION(246), CREATE_EXPRESSION(247),
1461 CREATE_EXPRESSION(248), CREATE_EXPRESSION(249), CREATE_EXPRESSION(250), CREATE_EXPRESSION(251),
1462 CREATE_EXPRESSION(252)};
1463
1464#undef CREATE_EXPRESSION
1465}
#define CODI_NO_INLINE
See codi::Config::AvoidedInlines.
Definition config.h:417
#define CODI_INLINE
See codi::Config::ForcedInlines.
Definition config.h:457
#define ADJOINT_VECTOR_TYPE
See codi::Config::VariableAdjointInterfaceInPrimalTapes.
Definition config.h:277
#define CODI_Likely
Declare likely evaluation of an execution path.
Definition config.h:397
#define codiAssert(x)
See codi::Config::EnableAssert.
Definition config.h:432
#define CODI_DD(Type, Default)
Abbreviation for CODI_DECLARE_DEFAULT.
Definition macros.hpp:94
#define CODI_ENABLE_CHECK(option, condition)
Definition macros.hpp:53
#define CODI_WRAP_FUNCTION(NAME, FUNC)
Wrap a function in a function object. Used for performance optimizations.
Definition macros.hpp:156
#define CODI_ANY
Used in default declarations of expression templates.
Definition macros.hpp:98
#define CODI_STATIC_ASSERT(cond, message)
Static assert in CoDiPack.
Definition macros.hpp:123
#define CODI_T(...)
Abbreviation for CODI_TEMPLATE.
Definition macros.hpp:111
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
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:319
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
bool isTotalFinite(Type const &v)
Function for checking if all values of the type are finite.
Definition realTraits.hpp:133
typename TraitsImplementation< Type >::PassiveReal PassiveReal
The original computation type, that was used in the application.
Definition realTraits.hpp:117
bool isTotalZero(Type const &v)
Function for checking if the value of the type is completely zero.
Definition realTraits.hpp:139
CoDiPack - Code Differentiation Package.
Definition codi.hpp:90
void CODI_UNUSED(Args const &...)
Disable unused warnings for an arbitrary number of arguments.
Definition macros.hpp:46
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
@ PassiveValuesSize
[A: RW] Allocated number of entries in the passive value vector in primal value tapes.
@ LargestIdentifier
[A: R] Largest identifier distributed by the index manger.
@ PrimalSize
[A: RW] Number of primal vector entries in primal value tapes.
@ StatementSize
[A: RW] Allocated number of entries in the statement vector in all tapes.
AdjointsManagement
Policies for management of the tape's interal adjoints.
Definition tapeParameters.hpp:98
@ Automatic
Manage internal adjoints automatically, including locking, bounds checking, and resizing.
Definition byteDataView.hpp:51
Definition chunk.hpp:185
Definition chunk.hpp:537
Data is stored chunk-wise in this DataInterface implementation. If a chunk runs out of space,...
Definition chunkedData.hpp:64
Implementation of all common tape functionality.
Definition commonTapeImplementation.hpp:130
Real manualPushLhsValue
For storeManual, remember the value assigned to the lhs.
Definition commonTapeImplementation.hpp:157
void setParameter(TapeParameters parameter, size_t value)
See Parameters functions.
Definition commonTapeImplementation.hpp:458
void evaluateForward(AdjointsManagement adjointsManagement=AdjointsManagement::Automatic)
Perform a forward evaluation of a part of the tape. It has to hold start <= end.
Definition commonTapeImplementation.hpp:591
size_t manualPushCounter
Count the pushes after storeManual, to identify the last push.
Definition commonTapeImplementation.hpp:160
Identifier manualPushLhsIdentifier
For storeManual, remember the identifier assigned to the lhs.
Definition commonTapeImplementation.hpp:158
bool isActive() const
Check if the tape is recording.
Definition commonTapeImplementation.hpp:319
size_t manualPushGoal
Store the number of expected pushes after a storeManual call.
Definition commonTapeImplementation.hpp:159
void init(typename ImplTapeTypes::NestedData *nested)
Initialize the base class.
Definition commonTapeImplementation.hpp:715
void reset(bool resetAdjoints=true, AdjointsManagement adjointsManagement=AdjointsManagement::Automatic)
Reset the tape to the initial state for a fresh recording.
Definition commonTapeImplementation.hpp:354
std::set< TapeParameters > options
All options.
Definition commonTapeImplementation.hpp:152
void evaluate(AdjointsManagement adjointsManagement=AdjointsManagement::Automatic)
Perform a full reverse evaluation of the tape.
Definition commonTapeImplementation.hpp:292
void swap(Impl &other)
Swap all data with an other tape.
Definition commonTapeImplementation.hpp:367
typename CommonTapeTypes< ImplTapeTypes >::Position Position
See TapeTypesInterface.
Definition commonTapeImplementation.hpp:144
LowLevelFunctionByteData llfByteData
Byte data for low level functions.
Definition commonTapeImplementation.hpp:155
void resetTo(Position const &pos, bool resetAdjoints=true, AdjointsManagement adjointsManagement=AdjointsManagement::Automatic)
Reset the tape to the provided position.
Definition commonTapeImplementation.hpp:668
size_t getParameter(TapeParameters parameter) const
See Parameters functions.
Definition commonTapeImplementation.hpp:430
void evaluatePrimal()
Perform a full (forward) reevaluation of the primals in the tape.
Definition commonTapeImplementation.hpp:690
void internalStoreLowLevelFunction(Config::LowLevelFunctionToken token, size_t size, ByteDataView &dataView)
Called by the implementing tapes to store a low level function. The size is reserved and allocated....
Definition commonTapeImplementation.hpp:493
Helper class for the construction of an expression in a different context.
Definition constructStaticContext.hpp:70
Data stream interface for tape data. Encapsulates data that is written e.g. for each statement or arg...
Definition dataInterface.hpp:149
static void 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
static void 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 void notifyTapeRegisterInputListeners(Tape &tape, Real &value, Identifier &identifier)
Invoke callbacks for TapeRegisterInput events.
Definition eventSystem.hpp:424
Base class for all CoDiPack expressions.
Definition expressionInterface.hpp:59
Impl const & cast() const
Cast to the implementation.
Definition expressionInterface.hpp:75
Counts the number of nodes that inherit from LhsExpressionInterface in the expression.
Definition expressionTraits.hpp:184
Counts the number of types that inherit from ConstantExpression in the expression.
Definition expressionTraits.hpp:210
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
Definition jacobianComputationLogic.hpp:53
void link(Child const &child, Root const &root, Jacobian const &jacobian, Args &&... args)
Definition jacobianComputationLogic.hpp:84
Specialized for NumberOfActiveTypeArguments and NumberOfConstantTypeArguments.
Definition primalValueBaseTape.hpp:1377
Default implementation of the Jacobian interface.
Definition jacobian.hpp:60
Base class for all CoDiPack lvalue expression.
Definition lhsExpressionInterface.hpp:63
Impl & cast()
Cast to the implementation.
Definition lhsExpressionInterface.hpp:99
Defines a member that can either be static or local to the struct.
Definition memberStore.hpp:56
Type & get()
Get a reference to the actual member.
Definition memberStore.hpp:76
Implementation of VectorAccessInterface for adjoint and primal vectors.
Definition primalAdjointVectorAccess.hpp:58
Count all arguments that have non-zero index.
Definition primalValueBaseTape.hpp:319
void handleActive(Node const &node, size_t &numberOfActiveArguments)
Called for leaf nodes which implement LhsExpressionInterface.
Definition primalValueBaseTape.hpp:324
Perform the adjoint update based on the configuration in codi::Config::VariableAdjointInterfaceInPrim...
Definition primalValueBaseTape.hpp:607
void handleJacobianOnActive(Node const &node, Real jacobian, Gradient &lhsTangent, Gradient *adjointVector)
Called for leaf nodes which implement LhsExpressionInterface.
Definition primalValueBaseTape.hpp:612
Perform the adjoint update based on the configuration in codi::Config::VariableAdjointInterfaceInPrim...
Definition primalValueBaseTape.hpp:655
void handleJacobianOnActive(Node const &node, Real jacobian, Gradient const &lhsAdjoint, Gradient *adjointVector)
See IncrementReversalLogic.
Definition primalValueBaseTape.hpp:660
Computes Jacobian entries for the event system.
Definition primalValueBaseTape.hpp:367
JacobianExtractionLogic()
Constructor.
Definition primalValueBaseTape.hpp:374
void handleJacobianOnActive(Node const &node, Jacobian jacobianExpr, Identifier *rhsIdentifiers, Real *jacobians)
Stores the identifiers and Jacobians.
Definition primalValueBaseTape.hpp:378
Definition primalValueBaseTape.hpp:874
static Real statementEvaluatePrimalInner(Args &&... args)
Throws exception.
Definition primalValueBaseTape.hpp:933
static Real statementEvaluateForwardInner(Args &&... args)
Throws exception.
Definition primalValueBaseTape.hpp:924
static Real statementEvaluateForward(Args &&... args)
Throws exception.
Definition primalValueBaseTape.hpp:885
static void statementEvaluateReverseInner(Real *primalVector, Gradient *adjointVector, Gradient lhsAdjoint, size_t &curConstantPos, PassiveReal const *const constantValues, size_t &curRhsIdentifiersPos, Identifier const *const rhsIdentifiers)
Evaluate expression in a reverse mode.
Definition primalValueBaseTape.hpp:942
static size_t constexpr size
See JacobianStatementGenerator.
Definition primalValueBaseTape.hpp:877
static void statementEvaluateReverse(Real *primalVector, Gradient *adjointVector, Gradient lhsAdjoint, Config::ArgumentSize numberOfPassiveArguments, size_t &curConstantPos, PassiveReal const *const constantValues, size_t &curPassivePos, Real const *const passiveValues, size_t &curRhsIdentifiersPos, Identifier const *const rhsIdentifiers)
Evaluate expression in a reverse mode.
Definition primalValueBaseTape.hpp:899
static Real statementEvaluatePrimal(Args &&... args)
Throws exception.
Definition primalValueBaseTape.hpp:892
Push all data for each argument.
Definition primalValueBaseTape.hpp:332
void handleActive(Node const &node, RhsIdentifierData &rhsIdentiferData, PassiveValueData &passiveValueData, ConstantValueData &constantValueData, size_t &curPassiveArgument)
Called for leaf nodes which implement LhsExpressionInterface.
Definition primalValueBaseTape.hpp:337
void handleConstant(Node const &node, RhsIdentifierData &rhsIdentiferData, PassiveValueData &passiveValueData, ConstantValueData &constantValueData, size_t &curPassiveArgument)
Called for leaf nodes which implement ConstantExpression.
Definition primalValueBaseTape.hpp:355
Additional wrapper that triggers compiler optimizations.
Definition primalValueBaseTape.hpp:627
Wrapper helper for improved compiler optimizations.
Definition primalValueBaseTape.hpp:1135
Additional wrapper that triggers compiler optimizations.
Definition primalValueBaseTape.hpp:675
Base class for all standard Primal value tape implementations.
Definition primalValueBaseTape.hpp:136
MemberStore< IndexManager, Impl, TapeTypes::IsStaticIndexHandler > indexManager
Index manager.
Definition primalValueBaseTape.hpp:182
typename ConstantValueData::Position NestedPosition
See PrimalValueTapeTypes.
Definition primalValueBaseTape.hpp:164
std::vector< Real > primalsCopy
Copy of primal values for AD evaluations.
Definition primalValueBaseTape.hpp:190
VectorAccess< Adjoint > * createVectorAccessCustomAdjoints(Adjoint *data)
See Adjoint vector access.
Definition primalValueBaseTape.hpp:823
typename TapeTypes::EvalHandle EvalHandle
See PrimalValueTapeTypes.
Definition primalValueBaseTape.hpp:155
static bool constexpr RequiresPrimalRestore
See PrimalEvaluationTapeInterface.
Definition primalValueBaseTape.hpp:175
void beginUseAdjointVector()
Declare that the adjoint vector is being used. See Adjoint vector management.
Definition primalValueBaseTape.hpp:752
static Real statementEvaluateForwardFull(Func const &evalInner, size_t const &maxActiveArgs, size_t const &maxConstantArgs, Real *primalVector, Gradient *adjointVector, Gradient &lhsTangent, Config::ArgumentSize numberOfPassiveArguments, size_t &curConstantPos, PassiveReal const *const constantValues, size_t &curPassivePos, Real const *const passiveValues, size_t &curRhsIdentifiersPos, Identifier const *const rhsIdentifiers)
Load the expression data and evaluate the expression in a forward mode.
Definition primalValueBaseTape.hpp:1196
void resetTo(Position const &pos, bool resetAdjoints=true, AdjointsManagement adjointsManagement=AdjointsManagement::Automatic)
Reset the tape to the provided position.
Definition primalValueBaseTape.hpp:1080
PrimalValueBaseTape()
Constructor.
Definition primalValueBaseTape.hpp:232
static void statementEvaluateReverseFull(Func const &evalInner, size_t const &maxActiveArgs, size_t const &maxConstantArgs, Real *primalVector, Gradient *adjointVector, Gradient lhsAdjoint, Config::ArgumentSize numberOfPassiveArguments, size_t &curConstantPos, PassiveReal const *const constantValues, size_t &curPassivePos, Real const *const passiveValues, size_t &curRhsIdentifiersPos, Identifier const *const rhsIdentifiers)
Load the expression data and evaluate the expression in a reverse mode.
Definition primalValueBaseTape.hpp:1274
PassiveValueData passiveValueData
Data stream for passive argument value data.
Definition primalValueBaseTape.hpp:185
T_Impl Impl
See PrimalValueBaseTape.
Definition primalValueBaseTape.hpp:144
static void statementEvaluateReverseInner(Real *primalVector, Gradient *adjointVector, Gradient lhsAdjoint, size_t &curConstantPos, PassiveReal const *const constantValues, size_t &curRhsIdentifiersPos, Identifier const *const rhsIdentifiers)
Evaluate expression in a reverse mode.
Definition primalValueBaseTape.hpp:1256
void registerInput(LhsExpressionInterface< Real, Gradient, Impl, Lhs > &value)
Definition primalValueBaseTape.hpp:514
void deleteAdjointVector()
Delete the adjoint vector. See Adjoint vector management.
Definition primalValueBaseTape.hpp:741
Real registerExternalFunctionOutput(LhsExpressionInterface< Real, Gradient, Impl, Lhs > &value)
Definition primalValueBaseTape.hpp:839
Real const & primal(Identifier const &identifier) const
Read only reference to primal value.
Definition primalValueBaseTape.hpp:1167
static bool constexpr HasPrimalValues
See PrimalEvaluationTapeInterface.
Definition primalValueBaseTape.hpp:172
typename TapeTypes::StatementEvaluator StatementEvaluator
See PrimalValueTapeTypes.
Definition primalValueBaseTape.hpp:152
static Real statementEvaluatePrimalInner(Real *primalVector, size_t &curConstantPos, PassiveReal const *const constantValues, size_t &curRhsIdentifiersPos, Identifier const *const rhsIdentifiers)
Evaluate expression in a primal setting.
Definition primalValueBaseTape.hpp:1220
typename TapeTypes::PassiveValueData PassiveValueData
See PrimalValueTapeTypes.
Definition primalValueBaseTape.hpp:159
std::vector< Real > primals
Current state of primal values in the program.
Definition primalValueBaseTape.hpp:189
typename TapeTypes::Real Real
See TapeTypesInterface.
Definition primalValueBaseTape.hpp:149
Gradient * selectAdjointVector(VectorAccess< Adjoint > *vectorAccess, Adjoint *data)
Select the configured adjoint vector, see codi::Config::VariableAdjointInterfaceInPrimalTapes.
Definition primalValueBaseTape.hpp:592
static void internalEvaluateReverse_EvalStatements(Args &&... args)
Perform a reverse evaluation of the tape. Arguments are from the recursive eval methods of the DataIn...
std::vector< Gradient > adjoints
Evaluation vector for AD.
Definition primalValueBaseTape.hpp:188
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 primalValueBaseTape.hpp:1113
void internalEvaluateForward(Position const &start, Position const &end, Adjoint *data)
Internal method for the forward evaluation of the whole tape.
Definition primalValueBaseTape.hpp:631
void evaluate(Position const &start, Position const &end, Adjoint *data)
Perform a reverse evaluation for a part of the tape. It hast to hold start >= end.
Definition primalValueBaseTape.hpp:710
void 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 primalValueBaseTape.hpp:1066
static Real statementEvaluateForwardInner(Real *primalVector, Gradient *adjointVector, Gradient &lhsTangent, size_t &curConstantPos, PassiveReal const *const constantValues, size_t &curRhsIdentifiersPos, Identifier const *const rhsIdentifiers)
Evaluate expression in a forward mode.
Definition primalValueBaseTape.hpp:1178
typename TapeTypes::Identifier Identifier
See PrimalValueTapeTypes.
Definition primalValueBaseTape.hpp:153
RhsIdentifierData rhsIdentiferData
Data stream for argument identifier data.
Definition primalValueBaseTape.hpp:184
void evaluateForward(Position const &start, Position const &end, Adjoint *data)
Perform a forward evaluation of a part of the tape. It has to hold start <= end.
Definition primalValueBaseTape.hpp:716
T_TapeTypes TapeTypes
See PrimalValueBaseTape.
Definition primalValueBaseTape.hpp:140
void pushStmtData(Identifier const &index, Config::ArgumentSize const &numberOfPassiveArguments, Real const &oldPrimalValue, EvalHandle evalHandle)
Add statement specific data to the data streams.
static bool constexpr AllowJacobianOptimization
See InternalStatementRecordingTapeInterface.
Definition primalValueBaseTape.hpp:171
static void statementEvaluateReverse(Real *primalVector, Gradient *adjointVector, Gradient lhsAdjoint, Config::ArgumentSize numberOfPassiveArguments, size_t &curConstantPos, PassiveReal const *const constantValues, size_t &curPassivePos, Real const *const passiveValues, size_t &curRhsIdentifiersPos, Identifier const *const rhsIdentifiers)
Evaluate expression in a reverse mode.
Definition primalValueBaseTape.hpp:1335
typename TapeTypes::RhsIdentifierData RhsIdentifierData
See PrimalValueTapeTypes.
Definition primalValueBaseTape.hpp:158
Gradient const & gradient(Identifier const &identifier, AdjointsManagement adjointsManagement=AdjointsManagement::Automatic) const
Constant reference access to gradient.
Definition primalValueBaseTape.hpp:282
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 primalValueBaseTape.hpp:1095
TapeValues internalGetTapeValues() const
Definition primalValueBaseTape.hpp:548
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 primalValueBaseTape.hpp:853
void initIdentifier(Real &value, Identifier &identifier)
Definition primalValueBaseTape.hpp:300
void deleteVectorAccess(VectorAccessInterface< Real, Identifier > *access)
See Adjoint vector access.
Definition primalValueBaseTape.hpp:828
void evaluatePrimal(Position const &start, Position const &end)
Perform a full (forward) reevaluation of the primals in the tape.
Definition primalValueBaseTape.hpp:1147
void reset(bool resetAdjoints=true, AdjointsManagement adjointsManagement=AdjointsManagement::Automatic)
Reset the tape to the initial state for a fresh recording.
Definition primalValueBaseTape.hpp:533
void store(LhsExpressionInterface< Real, Gradient, Impl, Lhs > &lhs, Real const &rhs)
Has to be called by an AD variable every time it is assigned.
Definition primalValueBaseTape.hpp:466
static void internalEvaluatePrimal_EvalStatements(Args &&... args)
Perform a primal evaluation of the tape. Arguments are from the recursive eval methods of the DataInt...
void setParameter(TapeParameters parameter, size_t value)
See Parameters functions.
Definition primalValueBaseTape.hpp:788
Real & primal(Identifier const &identifier)
Writable reference to primal value.
Definition primalValueBaseTape.hpp:1162
static void internalEvaluateForward_EvalStatements(Args &&... args)
Perform a forward evaluation of the tape. Arguments are from the recursive eval methods of the DataIn...
static bool constexpr LinearIndexHandling
See IdentifierInformationTapeInterface.
Definition primalValueBaseTape.hpp:173
void internalResetPrimalValues(Position const &pos)
Reset the primal values to the given position.
void swap(Impl &other)
Swap all data with an other tape.
Definition primalValueBaseTape.hpp:726
void 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 primalValueBaseTape.hpp:447
RealTraits::PassiveReal< Real > PassiveReal
Basic computation type.
Definition primalValueBaseTape.hpp:162
typename Base::Position Position
See TapeTypesInterface.
Definition primalValueBaseTape.hpp:165
typename TapeTypes::Gradient Gradient
See TapeTypesInterface.
Definition primalValueBaseTape.hpp:150
void 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 primalValueBaseTape.hpp:392
void internalEvaluateReverse(Position const &start, Position const &end, Adjoint *data)
Internal method for the reverse evaluation of the whole tape.
Definition primalValueBaseTape.hpp:679
void resizeAdjointVector()
Explicitly trigger resizing of the adjoint vector. See Adjoint vector management.
Definition primalValueBaseTape.hpp:746
typename TapeTypes::StatementData StatementData
See PrimalValueTapeTypes.
Definition primalValueBaseTape.hpp:157
void endUseAdjointVector()
Declare that the adjoint vector is no longer used. See Adjoint vector management.
Definition primalValueBaseTape.hpp:756
void destroyIdentifier(Real &value, Identifier &identifier)
Has to be called for each identifier, before it is deallocated.
Definition primalValueBaseTape.hpp:308
static Real statementEvaluateForward(Real *primalVector, Gradient *adjointVector, Gradient &lhsTangent, Config::ArgumentSize numberOfPassiveArguments, size_t &curConstantPos, PassiveReal const *const constantValues, size_t &curPassivePos, Real const *const passiveValues, size_t &curRhsIdentifiersPos, Identifier const *const rhsIdentifiers)
Evaluate expression in a forward mode.
Definition primalValueBaseTape.hpp:1305
VectorAccess< Gradient > * createVectorAccess()
See Adjoint vector access.
Definition primalValueBaseTape.hpp:817
void clearAdjoints(AdjointsManagement adjointsManagement=AdjointsManagement::Automatic)
Clear all adjoint values, that is, set them to zero.
Definition primalValueBaseTape.hpp:522
static EvalHandle const jacobianExpressions[Config::MaxArgumentSize]
Expressions for manual statement pushes.
Definition primalValueBaseTape.hpp:180
Gradient & gradient(Identifier const &identifier, AdjointsManagement adjointsManagement=AdjointsManagement::Automatic)
Reference access to gradient.
Definition primalValueBaseTape.hpp:268
Real internalRegisterInput(LhsExpressionInterface< Real, Gradient, Impl, Lhs > &value, bool unusedIndex)
Add a new input to the tape and update the primal value vector.
Definition primalValueBaseTape.hpp:481
void storeManual(Real const &lhsValue, Identifier &lhsIndex, Config::ArgumentSize const &size)
Definition primalValueBaseTape.hpp:1022
void pushJacobianManual(Real const &jacobian, Real const &value, Identifier const &index)
Definition primalValueBaseTape.hpp:996
StatementData statementData
Data stream for statement specific data.
Definition primalValueBaseTape.hpp:183
static Real statementEvaluatePrimal(Real *primalVector, Config::ArgumentSize numberOfPassiveArguments, size_t &curConstantPos, PassiveReal const *const constantValues, size_t &curPassivePos, Real const *const passiveValues, size_t &curRhsIdentifiersPos, Identifier const *const rhsIdentifiers)
Evaluate primal expression.
Definition primalValueBaseTape.hpp:1321
void pushLowLevelFunction(Config::LowLevelFunctionToken token, size_t size, ByteDataView &data)
Push a low level function to the tape.
Definition primalValueBaseTape.hpp:1046
typename TapeTypes::ConstantValueData ConstantValueData
See PrimalValueTapeTypes.
Definition primalValueBaseTape.hpp:160
friend Base
Allow the base class to call protected and private methods.
Definition primalValueBaseTape.hpp:147
size_t getParameter(TapeParameters parameter) const
See Parameters functions.
Definition primalValueBaseTape.hpp:759
static Real statementEvaluatePrimalFull(Func const &evalInner, size_t const &maxActiveArgs, size_t const &maxConstantArgs, Real *primalVector, Config::ArgumentSize numberOfPassiveArguments, size_t &curConstantPos, PassiveReal const *const constantValues, size_t &curPassivePos, Real const *const passiveValues, size_t &curRhsIdentifiersPos, Identifier const *const rhsIdentifiers)
Load the expression data and evaluate the expression in a primal setting.
Definition primalValueBaseTape.hpp:1234
typename TapeTypes::IndexManager IndexManager
See TapeTypesInterface.
Definition primalValueBaseTape.hpp:151
ConstantValueData constantValueData
Data stream for constant argument data.
Definition primalValueBaseTape.hpp:186
Type definitions for the primal value tapes.
Definition primalValueBaseTape.hpp:77
T_Gradient Gradient
See PrimalValueTapeTypes.
Definition primalValueBaseTape.hpp:81
typename IndexManager::Index Identifier
See IndexManagerInterface.
Definition primalValueBaseTape.hpp:89
Data< PassiveValueChunk, RhsIdentifierData > PassiveValueData
Passive values data vector.
Definition primalValueBaseTape.hpp:109
typename std::conditional< IsLinearIndexHandler, Chunk2< Config::ArgumentSize, EvalHandle >, Chunk4< Identifier, Config::ArgumentSize, Real, EvalHandle > >::type StatementChunk
Definition primalValueBaseTape.hpp:100
T_Data< Chunk, Nested > Data
See PrimalValueTapeTypes.
Definition primalValueBaseTape.hpp:86
static constexpr bool IsLinearIndexHandler
True if the index manager is linear.
Definition primalValueBaseTape.hpp:92
RealTraits::PassiveReal< Real > PassiveReal
Basic computation type.
Definition primalValueBaseTape.hpp:90
T_Real Real
See PrimalValueTapeTypes.
Definition primalValueBaseTape.hpp:80
Data< IdentifierChunk, StatementData > RhsIdentifierData
Rhs identifiers data vector.
Definition primalValueBaseTape.hpp:106
Data< StatementChunk, IndexManager > StatementData
Statement data vector.
Definition primalValueBaseTape.hpp:103
ConstantValueData NestedData
See TapeTypesInterface.
Definition primalValueBaseTape.hpp:114
T_IndexManager IndexManager
See PrimalValueTapeTypes.
Definition primalValueBaseTape.hpp:82
Data< ConstantValueChunk, PassiveValueData > ConstantValueData
Constant values data vector.
Definition primalValueBaseTape.hpp:112
static constexpr bool IsStaticIndexHandler
True if the index manager must be stored statically in the tape.
Definition primalValueBaseTape.hpp:93
typename StatementEvaluator::Handle EvalHandle
Handle type returned by the statement generator.
Definition primalValueBaseTape.hpp:96
T_StatementEvaluator< Real > StatementEvaluator
See PrimalValueTapeTypes.
Definition primalValueBaseTape.hpp:83
Tape side interface for StatementEvaluatorInterface.
Definition statementEvaluatorTapeInterface.hpp:91
Creation of handles for the evaluation of expressions in a context where the expression type is not a...
Definition statementEvaluatorInterface.hpp:103
Tape side interface for StatementEvaluatorInterface.
Definition statementEvaluatorTapeInterface.hpp:55
Interface for the definition of tape types.
Definition commonTapeImplementation.hpp:63
Tape information that can be printed in a pretty print format or a table format.
Definition tapeValues.hpp:73
void addDoubleEntry(std::string const &name, double const &value, bool usedMem=false, bool allocatedMem=false)
Add double entry. If it is a memory entry, it should be in bytes.
Definition tapeValues.hpp:126
void addUnsignedLongEntry(std::string const &name, unsigned long const &value)
Add unsigned long entry.
Definition tapeValues.hpp:150
void addSection(std::string const &name)
Add section. All further entries are added under this section.
Definition tapeValues.hpp:145
void eval(NodeInterface< Node > const &node, Args &&... args)
Start the evaluation of the logic on the given expression.
Definition traversalLogic.hpp:70
void node(Node const &node, Args &&... args)
Called for each node in the expression.
Definition traversalLogic.hpp:86
void link(Child const &child, Root const &root, Args &&... args)
Called for all links in the expression.
Definition traversalLogic.hpp:110
Unified access to the adjoint vector and primal vector in a tape evaluation.
Definition vectorAccessInterface.hpp:91