CoDiPack  3.0.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-2025 Chair for Scientific Computing (SciComp), University of Kaiserslautern-Landau
5 * Homepage: http://scicomp.rptu.de
6 * Contact: Prof. Nicolas R. Gauger (codi@scicomp.uni-kl.de)
7 *
8 * Lead developers: Max Sagebaum, Johannes Blühdorn (SciComp, University of Kaiserslautern-Landau)
9 *
10 * This file is part of CoDiPack (http://scicomp.rptu.de/software/codi).
11 *
12 * CoDiPack is free software: you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, either version 3 of the
15 * License, or (at your option) any later version.
16 *
17 * CoDiPack is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty
19 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
20 *
21 * See the GNU General Public License for more details.
22 * You should have received a copy of the GNU
23 * General Public License along with CoDiPack.
24 * If not, see <http://www.gnu.org/licenses/>.
25 *
26 * For other licensing options please contact us.
27 *
28 * Authors:
29 * - SciComp, University of Kaiserslautern-Landau:
30 * - Max Sagebaum
31 * - Johannes Blühdorn
32 * - Former members:
33 * - Tim Albring
34 */
35#pragma once
36
37#include <algorithm>
38#include <cmath>
39#include <functional>
40#include <type_traits>
41#include <utility>
42
43#include "../config.h"
44#include "../expressions/aggregate/aggregatedActiveType.hpp"
45#include "../expressions/aggregate/arrayAccessExpression.hpp"
46#include "../expressions/lhsExpressionInterface.hpp"
47#include "../expressions/logic/compileTimeTraversalLogic.hpp"
48#include "../expressions/logic/constructStaticContext.hpp"
49#include "../expressions/logic/helpers/forEachLeafLogic.hpp"
50#include "../expressions/logic/helpers/jacobianComputationLogic.hpp"
51#include "../expressions/logic/helpers/mathStatementGenLogic.hpp"
52#include "../expressions/logic/traversalLogic.hpp"
53#include "../misc/demangleName.hpp"
54#include "../misc/macros.hpp"
55#include "../misc/mathUtility.hpp"
56#include "../misc/memberStore.hpp"
57#include "../traits/expressionTraits.hpp"
58#include "commonTapeImplementation.hpp"
59#include "data/chunk.hpp"
60#include "data/chunkedData.hpp"
61#include "indices/indexManagerInterface.hpp"
62#include "misc/assignStatement.hpp"
63#include "misc/primalAdjointVectorAccess.hpp"
64#include "statementEvaluators/statementEvaluatorInterface.hpp"
65#include "statementEvaluators/statementEvaluatorTapeInterface.hpp"
67namespace codi {
68
79 template<typename T_Real, typename T_Gradient, typename T_IndexManager, typename T_StatementEvaluator,
80 template<typename, typename> class T_Data>
82 public:
83
84 using Real = CODI_DD(T_Real, double);
85 using Gradient = CODI_DD(T_Gradient, double);
87 using StatementEvaluator = CODI_DD(CODI_T(T_StatementEvaluator),
89 template<typename Chunk, typename Nested>
90 using Data = CODI_DD(CODI_T(T_Data<Chunk, Nested>),
92
93 using Identifier = typename IndexManager::Index;
95
96 constexpr static bool IsLinearIndexHandler = IndexManager::IsLinear;
97 constexpr static bool IsStaticIndexHandler =
98 IndexManager::NeedsStaticStorage;
99
100 using EvalHandle = typename StatementEvaluator::Handle;
101
105
108
110 };
111
128 template<typename T_TapeTypes, typename T_Impl>
129 struct PrimalValueBaseTape : public CommonTapeImplementation<T_TapeTypes, T_Impl>,
132 public:
133
135 using TapeTypes = CODI_DD(T_TapeTypes,
140
142 friend Base;
143
144 using Real = typename TapeTypes::Real;
145 using Gradient = typename TapeTypes::Gradient;
146 using IndexManager = typename TapeTypes::IndexManager;
147 using StatementEvaluator = typename TapeTypes::StatementEvaluator;
148 using Identifier = typename TapeTypes::Identifier;
149
150 using EvalHandle = typename TapeTypes::EvalHandle;
151
152 using StatementData = typename TapeTypes::StatementData;
153 using StatementByteData = typename TapeTypes::StatementByteData;
154
156
157 using NestedPosition = typename StatementData::Position;
158 using Position = typename Base::Position;
159
161 template<typename AdjointVector>
163
164 static bool constexpr AllowJacobianOptimization = false;
165 static bool constexpr HasPrimalValues = true;
166 static bool constexpr LinearIndexHandling =
167 TapeTypes::IsLinearIndexHandler;
168 static bool constexpr RequiresPrimalRestore =
169 !TapeTypes::IsLinearIndexHandler;
170
172 template<typename T>
173 using StackArray = std::array<T, Config::MaxArgumentSize>;
174
175 protected:
176
177 static EvalHandle const jacobianExpressions[Config::MaxArgumentSize];
178
182
183 std::vector<Gradient> adjoints;
184 std::vector<Real> primals;
185 std::vector<Real> primalsCopy;
186
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
225 public:
226
229 : Base(),
230 indexManager(Config::MaxArgumentSize), // Reserve first items for passive values.
231 statementData(Config::ChunkSize),
232 statementByteData(Config::ByteDataChunkSize),
233 adjoints(1), // Ensure that adjoint[0] exists, see its use in gradient() const.
234 primals(0),
235 primalsCopy(0) {
236 checkPrimalSize(true);
237
238 statementData.setNested(&indexManager.get());
240
242
248 }
249
250 /*******************************************************************************/
253
259 if (AdjointsManagement::Automatic == adjointsManagement) {
260 checkAdjointSize(identifier);
261 }
262
263 codiAssert(identifier < (Identifier)adjoints.size());
264
265 return adjoints[identifier];
266 }
267
272 Identifier const& identifier, AdjointsManagement adjointsManagement = AdjointsManagement::Automatic) const {
273 codiAssert(identifier < (Identifier)adjoints.size());
274
275 if (AdjointsManagement::Automatic == adjointsManagement && identifier >= (Identifier)adjoints.size()) {
276 return adjoints[0];
277 } else {
278 return adjoints[identifier];
279 }
280 }
281
283 /*******************************************************************************/
286
288 template<typename Real>
289 CODI_INLINE void initIdentifier(Real& value, Identifier& identifier) {
290 CODI_UNUSED(value);
291
292 identifier = IndexManager::InactiveIndex;
293 }
294
296 template<typename Real>
297 CODI_INLINE void destroyIdentifier(Real& value, Identifier& identifier) {
298 CODI_UNUSED(value);
299
300 indexManager.get().template freeIndex<Impl>(identifier);
301 }
302
304
312
315 template<typename T>
316 CODI_INLINE void push(T* CODI_RESTRICT& array, T const& value) {
317 *array = value;
318 array += 1;
319 }
320
322 CODI_INLINE void populate(size_t lhsSize, size_t rhsSize, size_t passiveSize, size_t constantSize,
323 char* byteData) {
324 size_t reserverLhsSize = LinearIndexHandling ? 0 : lhsSize;
325
326 char* curPos = byteData;
327
328 rhsIdentifiers = reinterpret_cast<Identifier*>(curPos);
329 curPos += sizeof(Identifier) * rhsSize;
330
331 lhsIdentifiers = reinterpret_cast<Identifier*>(curPos);
332 curPos += sizeof(Identifier) * reserverLhsSize;
333
334 passiveValues = reinterpret_cast<Real*>(curPos);
335 curPos += sizeof(Real) * passiveSize;
336
337 oldLhsValues = reinterpret_cast<Real*>(curPos);
338 curPos += sizeof(Real) * reserverLhsSize;
339
340 constantValues = reinterpret_cast<PassiveReal*>(curPos);
341 curPos += sizeof(PassiveReal) * constantSize;
342
343 codiAssert(curPos == byteData + computeSize(lhsSize, rhsSize, passiveSize, constantSize));
344 }
345
347 CODI_INLINE Config::LowLevelFunctionDataSize computeSize(size_t lhsSize, size_t rhsSize, size_t passiveSize,
348 size_t constantSize) {
349 size_t reserverLhsSize = LinearIndexHandling ? 0 : lhsSize;
350
351 return sizeof(Identifier) * (rhsSize + reserverLhsSize) + sizeof(Real) * (passiveSize + reserverLhsSize) +
352 sizeof(PassiveReal) * (constantSize);
353 }
354 };
355
356 protected:
357
359 CODI_INLINE void pushLhsData(Identifier const& index, Real const& oldPrimalValue,
360 StatementDataPointers& pointers) {
361 if (!LinearIndexHandling) {
362 pointers.push(pointers.lhsIdentifiers, index);
363 pointers.push(pointers.oldLhsValues, oldPrimalValue);
364 }
365 }
366
369 size_t passiveSize, size_t constantSize,
370 StatementDataPointers& pointers) {
371 Config::LowLevelFunctionDataSize byteSize = pointers.computeSize(lhsSize, rhsSize, passiveSize, constantSize);
372 statementData.reserveItems(1);
373 statementByteData.reserveItems(byteSize);
374
375 char* byteData = nullptr;
376 statementByteData.getDataPointers(byteData);
377 statementByteData.addDataSize(byteSize);
378
379 pointers.populate(lhsSize, rhsSize, passiveSize, constantSize, byteData);
380
381 return byteSize;
382 }
383
385 template<typename Lhs, typename Rhs>
387 StatementDataPointers& pointers) {
388 size_t constexpr MaxActiveArgs = ExpressionTraits::NumberOfActiveTypeArguments<Rhs>::value;
389 size_t constexpr MaxConstantArgs = ExpressionTraits::NumberOfConstantTypeArguments<Rhs>::value;
390 size_t constexpr MaxOutputArgs = ExpressionTraits::NumberOfActiveTypeArguments<Lhs>::value;
391
392 return reserveStmtDataManual(MaxOutputArgs, MaxActiveArgs, MaxActiveArgs - activeArguments, MaxConstantArgs,
393 pointers);
394 }
395
397 struct CountActiveArguments : public ForEachLeafLogic<CountActiveArguments> {
398 public:
399
401 template<typename Node>
402 CODI_INLINE void handleActive(Node const& node, size_t& numberOfActiveArguments) {
403 if (CODI_ENABLE_CHECK(Config::CheckZeroIndex, IndexManager::InactiveIndex != node.getIdentifier())) {
404 numberOfActiveArguments += 1;
405 }
406 }
407 };
408
410 struct PushIdentifierPassiveAndConstant : public ForEachLeafLogic<PushIdentifierPassiveAndConstant> {
411 public:
412
414 template<typename Node>
415 CODI_INLINE void handleActive(Node const& node, StatementDataPointers& pointers, size_t& curPassiveArgument) {
416 Identifier rhsIndex = node.getIdentifier();
417 if (CODI_ENABLE_CHECK(Config::CheckZeroIndex, IndexManager::InactiveIndex == rhsIndex)) {
418 rhsIndex = curPassiveArgument;
419
420 curPassiveArgument += 1;
421 pointers.push(pointers.passiveValues, node.getValue());
422 }
423
424 pointers.push(pointers.rhsIdentifiers, rhsIndex);
425 }
426
428 template<typename Node>
430 size_t& curPassiveArgument) {
431 CODI_UNUSED(curPassiveArgument);
432
434 using ConversionOperator = typename Node::template ConversionOperator<PassiveReal>;
435
436 typename Node::Real v = node.getValue();
437
439 pointers.push(pointers.constantValues,
440 ConversionOperator::toDataStore(AggregatedTraits::template arrayAccess<i.value>(v)));
441 });
442 }
443 };
444
449 template<typename Lhs, typename RhsType, typename Rhs>
451 StatementDataPointers& pointers) {
452 using Stmt = AssignStatement<Lhs, Rhs>;
453
454 CountActiveArguments countActiveArguments;
455 PushIdentifierPassiveAndConstant pushStatement;
456
460
461 size_t activeArguments = 0;
462 countActiveArguments.eval(rhs.cast(), activeArguments);
463
464 if (CODI_ENABLE_CHECK(Config::CheckEmptyStatements, 0 != activeArguments)) {
465 Config::LowLevelFunctionDataSize byteSize = reserveStmtData<Lhs, Rhs>(activeArguments, pointers);
466
467 size_t passiveArguments = 0;
468 pushStatement.eval(rhs.cast(), pointers, passiveArguments);
469 statementData.pushData((Config::ArgumentSize)passiveArguments,
470 StatementEvaluator::template createHandle<Impl, Impl, Stmt>(), byteSize);
471
472 return true;
473 } else {
474 return false;
475 }
476 }
477
479 struct JacobianExtractionLogic : public JacobianComputationLogic<JacobianExtractionLogic> {
480 private:
481 size_t pos;
482
483 public:
484
487
489 template<typename Node, typename Jacobian>
490 CODI_INLINE void handleJacobianOnActive(Node const& node, Jacobian jacobianExpr, Identifier* rhsIdentifiers,
491 Real* jacobians) {
492 rhsIdentifiers[pos] = node.getIdentifier();
493 jacobians[pos] = jacobianExpr;
494 pos++;
495 }
496 };
497
498 public:
499
504 template<typename Aggregated, typename Type, typename Lhs, typename Rhs>
507 using AggregatedTraits = RealTraits::AggregatedTypeTraits<Aggregated>;
508 int constexpr Elements = AggregatedTraits::Elements;
509
510 bool primalStored = false;
511 StatementDataPointers pointers = {};
512
513 if (storeArgumentAndStmtData<Lhs>(rhs, pointers)) {
514 bool generatedNewIndex = false;
516 generatedNewIndex |= indexManager.get().template assignIndex<Impl>(lhs.values[i.value].getIdentifier());
517 });
518 checkPrimalSize(generatedNewIndex);
519
520 Aggregated real = rhs.cast().getValue();
522 Identifier lhsIdentifier = lhs.values[i.value].getIdentifier();
523 Real& primalEntry = primals[lhsIdentifier];
524
525 pushLhsData(lhsIdentifier, primalEntry, pointers);
526
528 size_t constexpr MaxActiveArgs = ExpressionTraits::NumberOfActiveTypeArguments<Rhs>::value;
529
530 JacobianExtractionLogic getRhsIdentifiersAndJacobians;
531 std::array<Identifier, MaxActiveArgs> rhsIdentifiers;
532 std::array<Real, MaxActiveArgs> jacobians;
533 getRhsIdentifiersAndJacobians.eval(ArrayAccessExpression<Aggregated, i.value, Rhs>(rhs), Real(1.0),
534 rhsIdentifiers.data(), jacobians.data());
535
537 cast(), lhsIdentifier, AggregatedTraits::template arrayAccess<i.value>(real), MaxActiveArgs,
538 rhsIdentifiers.data(), jacobians.data());
539 }
540
541 lhs.values[i.value].value() = AggregatedTraits::template arrayAccess<i.value>(real);
542 primalEntry = lhs.values[i.value].getValue();
543 });
544
545 primalStored = true;
546 }
547
548 if (!primalStored) {
549 Aggregated real = rhs.cast().getValue();
550
552 lhs.values[i.value].value() = AggregatedTraits::template arrayAccess<i.value>(real);
553 indexManager.get().template freeIndex<Impl>(lhs.values[i.value].getIdentifier());
554 });
555 }
556 }
557
560 template<typename Aggregated, typename Type, typename Lhs, typename Rhs>
563 using AggregatedTraits = RealTraits::AggregatedTypeTraits<Aggregated>;
564
565 int constexpr Elements = AggregatedTraits::Elements;
566
568 if (IndexManager::CopyNeedsStatement || !Config::CopyOptimization) {
569 store(lhs, static_cast<ExpressionInterface<Aggregated, Rhs> const&>(rhs));
570 return;
571 } else {
573 indexManager.get().template copyIndex<Impl>(lhs.values[i.value].getIdentifier(),
574 rhs.values[i.value].getIdentifier());
575 });
576 }
577 } else {
579 indexManager.get().template freeIndex<Impl>(lhs.values[i.value].getIdentifier());
580 });
581 }
582
584 lhs.values[i.value].value() = rhs.values[i.value].getValue();
585 });
586 }
587
589 template<typename Lhs, typename Rhs>
592 bool primalStored = false;
593 StatementDataPointers pointers = {};
594
595 if (storeArgumentAndStmtData<Lhs>(rhs, pointers)) {
596 bool generatedNewIndex = indexManager.get().template assignIndex<Impl>(lhs.cast().getIdentifier());
597 checkPrimalSize(generatedNewIndex);
598
599 Real& primalEntry = primals[lhs.cast().getIdentifier()];
600 pushLhsData(lhs.cast().getIdentifier(), primalEntry, pointers);
601
602 primalEntry = rhs.cast().getValue();
603
605 size_t constexpr MaxActiveArgs = ExpressionTraits::NumberOfActiveTypeArguments<Rhs>::value;
606
607 JacobianExtractionLogic getRhsIdentifiersAndJacobians;
608 std::array<Identifier, MaxActiveArgs> rhsIdentifiers;
609 std::array<Real, MaxActiveArgs> jacobians;
610 getRhsIdentifiersAndJacobians.eval(rhs.cast(), Real(1.0), rhsIdentifiers.data(), jacobians.data());
611
613 rhs.cast().getValue(), MaxActiveArgs,
614 rhsIdentifiers.data(), jacobians.data());
615 }
616
617 primalStored = true;
618 }
619
620 if (!primalStored) {
621 indexManager.get().template freeIndex<Impl>(lhs.cast().getIdentifier());
622 }
623
624 lhs.cast().value() = rhs.cast().getValue();
625 }
626
629 template<typename Lhs, typename Rhs>
633 if (IndexManager::CopyNeedsStatement || !Config::CopyOptimization) {
634 store<Lhs, Rhs>(lhs, static_cast<ExpressionInterface<Real, Rhs> const&>(rhs));
635 return;
636 } else {
637 indexManager.get().template copyIndex<Impl>(lhs.cast().getIdentifier(), rhs.cast().getIdentifier());
638 }
639 } else {
640 indexManager.get().template freeIndex<Impl>(lhs.cast().getIdentifier());
641 }
642
643 lhs.cast().value() = rhs.cast().getValue();
644 }
645
648 template<typename Lhs>
650 indexManager.get().template freeIndex<Impl>(lhs.cast().getIdentifier());
651
652 lhs.cast().value() = rhs;
653 }
654
656 /*******************************************************************************
657 * Protected helper function for ReverseTapeInterface
658 */
659
660 protected:
661
663 template<typename Lhs>
665 bool unusedIndex) {
666 if (TapeTypes::IsLinearIndexHandler) {
667 statementData.reserveItems(1);
668 }
669
670 bool generatedNewIndex;
671 if (unusedIndex) {
672 generatedNewIndex = indexManager.get().template assignUnusedIndex<Impl>(value.cast().getIdentifier());
673 } else {
674 generatedNewIndex = indexManager.get().template assignIndex<Impl>(value.cast().getIdentifier());
675 }
676 checkPrimalSize(generatedNewIndex);
677
678 Real& primalEntry = primals[value.cast().getIdentifier()];
679 if (TapeTypes::IsLinearIndexHandler) {
681 StatementEvaluator::template createHandle<Impl, Impl, AssignStatement<Lhs, Lhs>>(), 0);
682 }
683
684 Real oldValue = primalEntry;
685 primalEntry = value.cast().value();
686
687 return oldValue;
688 }
689
690 public:
691
694
696 template<typename Lhs>
701
706 CODI_UNUSED(adjointsManagement);
707
708 size_t maxSize = std::min((size_t)indexManager.get().getLargestCreatedIndex() + 1, adjoints.size());
709 for (size_t i = 0; i < maxSize; i += 1) {
710 adjoints[i] = Gradient();
711 }
712 }
713
717 CODI_INLINE void reset(bool resetAdjoints = true,
719 for (Real& primal : primals) {
720 primal = Real();
721 }
722
723 Base::reset(resetAdjoints, adjointsManagement);
724 }
725
727
728 protected:
729
733 std::string name;
734 if (TapeTypes::IsLinearIndexHandler) {
735 name = "CoDi Tape Statistics ( PrimalValueLinearTape )";
736 } else {
737 name = "CoDi Tape Statistics ( PrimalValueReuseTape )";
738 }
739 TapeValues values = TapeValues(name);
740
741 size_t nAdjoints = indexManager.get().getLargestCreatedIndex();
742 double memoryAdjoints = static_cast<double>(nAdjoints) * static_cast<double>(sizeof(Gradient));
743
744 size_t nPrimals = indexManager.get().getLargestCreatedIndex();
745 double memoryPrimals = static_cast<double>(nPrimals) * static_cast<double>(sizeof(Real));
746
747 values.addSection("Adjoint vector");
748 values.addUnsignedLongEntry("Number of adjoints", nAdjoints);
749 values.addDoubleEntry("Memory allocated", memoryAdjoints, TapeValues::LocalReductionOperation::Sum, true, true);
750
751 values.addSection("Primal vector");
752 values.addUnsignedLongEntry("Number of primals", nPrimals);
753 values.addDoubleEntry("Memory allocated", memoryPrimals, TapeValues::LocalReductionOperation::Sum, true, true);
754
755 values.addSection("Index manager");
756 indexManager.get().addToTapeValues(values);
757
758 values.addSection("Statement entries");
759 statementData.addToTapeValues(values);
760
761 values.addSection("Statement byte entries");
762 statementByteData.addToTapeValues(values);
763
764 return values;
765 }
766
767 /******************************************************************************
768 * Protected helper function for CustomAdjointVectorEvaluationTapeInterface
769 */
770
772 template<typename AdjointVector>
774 CODI_UNUSED(vectorAccess, data);
775
776#if CODI_VariableAdjointInterfaceInPrimalTapes
777 return vectorAccess;
778#else
779 CODI_STATIC_ASSERT(CODI_T(std::is_same<typename std::remove_reference<AdjointVector>::type, Gradient*>::value),
780 "Please enable 'CODI_VariableAdjointInterfaceInPrimalTapes' in order"
781 " to use custom adjoint vectors in the primal value tapes.");
782
783 return data;
784#endif
785 }
786
788 struct IncrementForwardLogic : public JacobianComputationLogic<IncrementForwardLogic> {
789 public:
790
792 template<typename Node>
793 CODI_INLINE void handleJacobianOnActive(Node const& node, Real jacobian, Gradient& lhsTangent,
794 ADJOINT_VECTOR_TYPE* adjointVector) {
795 CODI_UNUSED(lhsTangent);
796
798#if CODI_VariableAdjointInterfaceInPrimalTapes
799 adjointVector->updateTangentWithLhs(node.getIdentifier(), jacobian);
800#else
801 lhsTangent += jacobian * adjointVector[node.getIdentifier()];
802#endif
803 }
804 }
805 };
806
808 CODI_WRAP_FUNCTION(Wrap_internalEvaluateForward_EvalStatements, Impl::internalEvaluateForward_EvalStatements);
809
811 template<bool copyPrimal, typename AdjointVector>
812 CODI_NO_INLINE void internalEvaluateForward(Position const& start, Position const& end, AdjointVector&& data) {
815 CODI_T(std::is_same<typename std::remove_reference<AdjointVector>::type, Gradient*>::value),
816 "Please enable 'CODI_VariableAdjointInterfaceInPrimalTapes' in order"
817 " to use custom adjoint vectors in the primal value tapes.");
818
819 std::vector<Real> primalsCopy(0);
820 Real* primalData = primals.data();
821
822 if (copyPrimal) {
824 primalData = primalsCopy.data();
825 }
826
827 VectorAccess<AdjointVector> vectorAccess(data, primalData);
828
829 ADJOINT_VECTOR_TYPE* dataVector = selectAdjointVector<AdjointVector>(&vectorAccess, data);
830
832 cast(), start, end, &vectorAccess, EventHints::EvaluationKind::Forward, EventHints::Endpoint::Begin);
833
834 Wrap_internalEvaluateForward_EvalStatements evalFunc{};
835 Base::llfByteData.evaluateForward(start, end, evalFunc, cast(), primalData, dataVector);
836
837 EventSystem<Impl>::notifyTapeEvaluateListeners(cast(), start, end, &vectorAccess,
838 EventHints::EvaluationKind::Forward, EventHints::Endpoint::End);
839 }
840
842 struct IncrementReversalLogic : public JacobianComputationLogic<IncrementReversalLogic> {
843 public:
844
846 template<typename Node>
847 CODI_INLINE void handleJacobianOnActive(Node const& node, Real jacobian, Gradient const& lhsAdjoint,
848 ADJOINT_VECTOR_TYPE* adjointVector) {
849 CODI_UNUSED(lhsAdjoint);
850
852#if CODI_VariableAdjointInterfaceInPrimalTapes
853 adjointVector->updateAdjointWithLhs(node.getIdentifier(), jacobian);
854#else
855 adjointVector[node.getIdentifier()] += jacobian * lhsAdjoint;
856#endif
857 }
858 }
859 };
860
862 CODI_WRAP_FUNCTION(Wrap_internalEvaluateReverse_EvalStatements, Impl::internalEvaluateReverse_EvalStatements);
863
865 template<bool copyPrimal, typename AdjointVector>
866 CODI_INLINE void internalEvaluateReverse(Position const& start, Position const& end, AdjointVector&& data) {
869 CODI_T(std::is_same<typename std::remove_reference<AdjointVector>::type, Gradient*>::value),
870 "Please enable 'CODI_VariableAdjointInterfaceInPrimalTapes' in order"
871 " to use custom adjoint vectors in the primal value tapes.");
872
873 Real* primalData = primals.data();
874
875 if (copyPrimal) {
877 primalData = primalsCopy.data();
878 }
879
880 VectorAccess<AdjointVector> vectorAccess(data, primalData);
881
882 ADJOINT_VECTOR_TYPE* dataVector = selectAdjointVector<AdjointVector>(&vectorAccess, data);
883
885 cast(), start, end, &vectorAccess, EventHints::EvaluationKind::Reverse, EventHints::Endpoint::Begin);
886
887 Wrap_internalEvaluateReverse_EvalStatements evalFunc;
888 Base::llfByteData.evaluateReverse(start, end, evalFunc, cast(), primalData, dataVector);
889
890 EventSystem<Impl>::notifyTapeEvaluateListeners(cast(), start, end, &vectorAccess,
891 EventHints::EvaluationKind::Reverse, EventHints::Endpoint::End);
892 }
893
894 public:
895
898
899 using Base::evaluate;
900
902 template<typename AdjointVector>
903 CODI_INLINE void evaluate(Position const& start, Position const& end, AdjointVector&& data) {
904 internalEvaluateReverse<!TapeTypes::IsLinearIndexHandler>(start, end, std::forward<AdjointVector>(data));
905 }
906
908 template<typename AdjointVector>
909 CODI_INLINE void evaluateForward(Position const& start, Position const& end, AdjointVector&& data) {
910 internalEvaluateForward<!TapeTypes::IsLinearIndexHandler>(start, end, std::forward<AdjointVector>(data));
911 }
912
915 return adjoints.data();
916 }
917
919 /*******************************************************************************/
922
924 CODI_INLINE void swap(Impl& other) {
925 // Index manager does not need to be swapped, it is either static or swapped with the vector data.
926 // Vectors are swapped recursively in the base class.
927
928 std::swap(adjoints, other.adjoints);
929 std::swap(primals, other.primals);
930
931 Base::swap(other);
932
933 // Ensure that the primals vector of both tapes are sized according to the index manager.
934 checkPrimalSize(true);
935 other.checkPrimalSize(true);
936 }
937
940 adjoints.resize(1);
941 }
942
945 checkAdjointSize(indexManager.get().getLargestCreatedIndex());
946 }
947
951
955
957 size_t getParameter(TapeParameters parameter) const {
958 switch (parameter) {
960 return adjoints.size();
961 break;
963 return indexManager.get().getLargestCreatedIndex();
964 break;
966 return primals.size();
967 break;
969 return statementData.getDataSize();
970 break;
972 return statementByteData.getDataSize();
973 break;
974 default:
975 return Base::getParameter(parameter);
976 break;
977 }
978 }
979
981 void setParameter(TapeParameters parameter, size_t value) {
982 switch (parameter) {
984 adjoints.resize(value);
985 break;
987 CODI_EXCEPTION("Tried to set a get only option.");
988 break;
990 primals.resize(value);
991 break;
993 return statementData.resize(value);
994 break;
996 return statementByteData.resize(value);
997 break;
998 default:
999 Base::setParameter(parameter, value);
1000 break;
1001 }
1002 }
1003
1008
1010 template<typename AdjointVector>
1012 return new VectorAccess<AdjointVector>(data, primals.data());
1013 }
1014
1017 template<typename Adjoint>
1019 return new VectorAccess<Adjoint*>(data, primals.data());
1020 }
1021
1024 delete access;
1025 }
1026
1028 /*******************************************************************************/
1031
1033 template<typename Lhs>
1037
1039 /*******************************************************************************/
1042
1044
1048 void evaluateForward(Position const& start, Position const& end,
1050 if (AdjointsManagement::Automatic == adjointsManagement) {
1051 checkAdjointSize(indexManager.get().getLargestCreatedIndex());
1052 }
1053
1054 codiAssert(indexManager.get().getLargestCreatedIndex() < (Identifier)adjoints.size());
1055
1056 cast().evaluateForward(start, end, adjoints.data());
1057 }
1058
1060 /*******************************************************************************/
1063
1065 void pushJacobianManual(Real const& jacobian, Real const& value, Identifier const& index) {
1066 CODI_UNUSED(value);
1067
1068 cast().incrementManualPushCounter();
1069
1070 *manualPushIdentifiers = index;
1071 *manualPushJacobians = jacobian;
1072
1075
1077 if (this->manualPushCounter == this->manualPushGoal) {
1078 // emit statement event
1081
1085 }
1086 }
1087 }
1088
1090 void storeManual(Real const& lhsValue, Identifier& lhsIndex, Config::ArgumentSize const& size) {
1091 CODI_UNUSED(lhsValue);
1092
1094
1095 StatementDataPointers pointers = {};
1096 Config::LowLevelFunctionDataSize byteSize = reserveStmtDataManual(1, size, size, 0, pointers);
1097
1098 manualPushJacobians = pointers.passiveValues;
1099 manualPushIdentifiers = pointers.rhsIdentifiers;
1100
1101 indexManager.get().template assignIndex<Impl>(lhsIndex);
1102 Real& primalEntry = primals[lhsIndex];
1103 statementData.pushData(size, PrimalValueBaseTape::jacobianExpressions[size], byteSize);
1104 pushLhsData(lhsIndex, primalEntry, pointers);
1105
1106 primalEntry = lhsValue;
1107
1108 cast().initializeManualPushData(lhsValue, lhsIndex, size);
1109 }
1110
1112 /*******************************************************************************/
1115
1121 void createStatementManual(Config::ArgumentSize const& nOutputValues, Identifier const* const lhsIndices,
1122 Real const* const lhsValues, Config::ArgumentSize const& nActiveValues,
1123 Identifier const* const rhsIdentifiers, Config::ArgumentSize const& nPassiveValues,
1124 Real const* const rhsPrimals, Config::ArgumentSize const& nConstants,
1125 Real const* const rhsConstant, EvalHandle const& evalHandle) {
1126 Impl& impl = cast();
1128 // TODO.
1129 } else if (Config::StatementInputTag == nPassiveValues && TapeTypes::IsLinearIndexHandler) CODI_Unlikely {
1130 statementData.reserveItems(1);
1131 primals[lhsIndices[0]] = lhsValues[0];
1132 statementData.pushData(Config::StatementInputTag, evalHandle, 0);
1133 } else CODI_Likely {
1134 StatementDataPointers pointers = {};
1136 reserveStmtDataManual(nOutputValues, nActiveValues, nPassiveValues, nConstants, pointers);
1137
1138 impl.initializeManualPushData(lhsValues[0], lhsIndices[0], nPassiveValues);
1139
1140 for (size_t activeCount = 0; activeCount < nActiveValues; activeCount++) {
1141 pointers.rhsIdentifiers[activeCount] = rhsIdentifiers[activeCount];
1142 }
1143 for (size_t passiveCount = 0; passiveCount < nPassiveValues; passiveCount++) {
1144 cast().incrementManualPushCounter();
1145 pointers.passiveValues[passiveCount] = rhsPrimals[passiveCount];
1146 }
1147 for (size_t constantCount = 0; constantCount < nConstants; constantCount++) {
1148 pointers.constantValues[constantCount] = rhsConstant[constantCount];
1149 }
1150
1151 statementData.pushData(nPassiveValues, evalHandle, byteSize);
1152
1153 for (Config::ArgumentSize i = 0; i < nOutputValues; i += 1) {
1154 pushLhsData(lhsIndices[i], lhsValues[i], pointers);
1155
1156 if (TapeTypes::IsLinearIndexHandler) {
1157 primals[lhsIndices[i]] = lhsValues[i];
1158 }
1159 }
1160 }
1161 }
1162
1163 using Base::writeTape;
1164
1169 template<typename Type>
1171 Position const& end) {
1172 Impl& impl = cast();
1173 writer->start(impl);
1174 Base::llfByteData.evaluateForward(start, end, Impl::template internalWriteTape<Type>, primals.data(), writer);
1175 writer->finish();
1176 }
1177
1179 /*******************************************************************************/
1182
1185 return indexManager.get();
1186 }
1187
1189 /*******************************************************************************/
1192
1195 statementData.reserveItems(1);
1196
1197 Base::internalStoreLowLevelFunction(token, size, data);
1198
1200 }
1201
1203 /*******************************************************************************/
1206
1210 CODI_INLINE void evaluate(Position const& start, Position const& end,
1212 if (AdjointsManagement::Automatic == adjointsManagement) {
1213 checkAdjointSize(indexManager.get().getLargestCreatedIndex());
1214 }
1215
1216 codiAssert(indexManager.get().getLargestCreatedIndex() < (Identifier)adjoints.size());
1217
1218 evaluate(start, end, adjoints.data());
1219 }
1220
1224 CODI_INLINE void resetTo(Position const& pos, bool resetAdjoints = true,
1226 cast().internalResetPrimalValues(pos);
1227
1228 Base::resetTo(pos, resetAdjoints, adjointsManagement);
1229 }
1230
1232 /*******************************************************************************/
1235
1239 void evaluateKeepState(Position const& start, Position const& end,
1241 if (AdjointsManagement::Automatic == adjointsManagement) {
1242 checkAdjointSize(indexManager.get().getLargestCreatedIndex());
1243 }
1244
1245 codiAssert(indexManager.get().getLargestCreatedIndex() < (Identifier)adjoints.size());
1246
1247 evaluateKeepState(start, end, adjoints.data());
1248 }
1249
1251 template<typename AdjointVector>
1252 void evaluateKeepState(Position const& start, Position const& end, AdjointVector&& data) {
1253 internalEvaluateReverse<false>(start, end, std::forward<AdjointVector>(data));
1254
1255 if (!TapeTypes::IsLinearIndexHandler) {
1256 evaluatePrimal(end, start);
1257 }
1258 }
1259
1263 void evaluateForwardKeepState(Position const& start, Position const& end,
1265 if (AdjointsManagement::Automatic == adjointsManagement) {
1266 checkAdjointSize(indexManager.get().getLargestCreatedIndex());
1267 }
1268
1269 codiAssert(indexManager.get().getLargestCreatedIndex() < (Identifier)adjoints.size());
1270
1271 evaluateForwardKeepState(start, end, adjoints.data());
1272 }
1273
1275 template<typename AdjointVector>
1276 void evaluateForwardKeepState(Position const& start, Position const& end, AdjointVector&& data) {
1277 if (!TapeTypes::IsLinearIndexHandler) {
1278 cast().internalResetPrimalValues(end);
1279 }
1280
1281 internalEvaluateForward<false>(start, end, std::forward<AdjointVector>(data));
1282 }
1283
1284 protected:
1285
1286 /******************************************************************************
1287 * Protected helper function for PrimalEvaluationTapeInterface
1288 */
1289
1291 CODI_WRAP_FUNCTION(Wrap_internalEvaluatePrimal_EvalStatements, Impl::internalEvaluatePrimal_EvalStatements);
1292
1293 public:
1294
1296 /*******************************************************************************/
1299
1301
1303 CODI_NO_INLINE void evaluatePrimal(Position const& start, Position const& end) {
1304 // TODO: implement primal value only accessor
1306
1307 EventSystem<Impl>::notifyTapeEvaluateListeners(cast(), start, end, &primalAdjointAccess,
1308 EventHints::EvaluationKind::Primal, EventHints::Endpoint::Begin);
1309
1310 Wrap_internalEvaluatePrimal_EvalStatements evalFunc{};
1311 Base::llfByteData.evaluateForward(start, end, evalFunc, cast(), primals.data());
1312
1313 EventSystem<Impl>::notifyTapeEvaluateListeners(cast(), start, end, &primalAdjointAccess,
1314 EventHints::EvaluationKind::Primal, EventHints::Endpoint::End);
1315 }
1316
1318 Real& primal(Identifier const& identifier) {
1319 return primals[identifier];
1320 }
1321
1323 Real const& primal(Identifier const& identifier) const {
1324 return primals[identifier];
1325 }
1326
1328 /*******************************************************************************/
1331
1333 template<typename Stmt, typename GenImpl>
1335 public:
1336 using Lhs = typename Stmt::Lhs;
1337 using Rhs = typename Stmt::Rhs;
1338 using LhsReal = typename Lhs::Real;
1340
1343
1344 template<size_t pos>
1347
1350 PassiveReal const* CODI_RESTRICT const constantValues,
1351 Identifier const* CODI_RESTRICT const identifiers) {
1352 return Constructor::construct(primalVector, identifiers, constantValues);
1353 }
1354
1356 template<typename... Args>
1357 CODI_INLINE static void internalEvaluate(Args&&... args) {
1358 size_t constexpr MaxActiveArgs = ExpressionTraits::NumberOfActiveTypeArguments<Rhs>::value;
1359 size_t constexpr MaxConstantArgs = ExpressionTraits::NumberOfConstantTypeArguments<Rhs>::value;
1360 size_t constexpr MaxOutputArgs = ExpressionTraits::NumberOfActiveTypeArguments<Lhs>::value;
1361
1362 GenImpl::evaluateFull(GenImpl::evaluateInner, MaxOutputArgs, MaxActiveArgs, MaxConstantArgs,
1363 std::forward<Args>(args)...);
1364 }
1365 };
1366
1368 template<StatementCall type, typename Stmt>
1370
1371// Define macros for the definition of the evaluate functions in the Statement call generators.
1372#define STMT_COMMON_ARGS Config::ArgumentSize numberOfPassiveArguments, char *CODI_RESTRICT byteData
1373#define STMT_COMMON_CALL numberOfPassiveArguments, byteData
1374
1375 /*******************************************************************************/
1377 template<typename Stmt>
1379 : public StatementCallGeneratorBase<Stmt, StatementCallGenerator<StatementCall::WriteInformation, Stmt>> {
1380 public:
1383 using StaticRhs = typename Base::StaticRhs;
1384
1386 CODI_INLINE static void evaluateInner(size_t const& CODI_RESTRICT maxOutputArgs,
1387 size_t const& CODI_RESTRICT maxActiveArgs,
1388 size_t const& CODI_RESTRICT maxConstantArgs,
1389 WriteInfo& CODI_RESTRICT writeInfo, Real* CODI_RESTRICT primalVector,
1390 STMT_COMMON_ARGS) {
1391 StatementDataPointers pointers = {};
1392 pointers.populate(maxOutputArgs, maxActiveArgs, numberOfPassiveArguments, maxConstantArgs, byteData);
1393
1394 if (Config::StatementInputTag != numberOfPassiveArguments) {
1395 for (Config::ArgumentSize curPos = 0; curPos < numberOfPassiveArguments; curPos += 1) {
1396 primalVector[curPos] = pointers.passiveValues[curPos];
1397 }
1398 }
1399
1400 StaticRhs staticRhs =
1401 Base::constructStaticRhs(primalVector, pointers.constantValues, pointers.rhsIdentifiers);
1402
1403 writeInfo.numberOfOutputArguments = maxOutputArgs;
1404 writeInfo.numberOfActiveArguments = maxActiveArgs;
1405 writeInfo.numberOfConstantArguments = maxConstantArgs;
1406
1407 // The Impl template name is added to simplify the writer and reader interfaces EvalHandles. It represents
1408 // the first and second template args in the createHandle method. For the manual push, the second Impl
1409 // template is instead replaced with JacobianGenerator<size>.
1410
1411 writeInfo.stmtExpression = "Impl, Impl, ";
1412 writeInfo.stmtExpression += demangleName<Stmt>();
1414 mathGen.eval(staticRhs, writeInfo.mathRepresentation);
1415 }
1416
1418 template<typename Func, typename... Args>
1419 CODI_INLINE static void evaluateFull(Func const& func, Args&&... args) {
1420 func(std::forward<Args>(args)...);
1421 }
1422
1424 CODI_INLINE static void evaluate(WriteInfo& CODI_RESTRICT writeInfo, Real* CODI_RESTRICT primalVector,
1425 STMT_COMMON_ARGS) {
1426 Base::internalEvaluate(writeInfo, primalVector, STMT_COMMON_CALL);
1427 }
1428 };
1429
1430 /*******************************************************************************/
1432 template<typename Stmt>
1434 : public StatementCallGeneratorBase<Stmt, StatementCallGenerator<StatementCall::ClearAdjoints, Stmt>> {
1435 public:
1438 using StaticRhs = typename Base::StaticRhs;
1439
1442
1444 template<typename Func>
1445 CODI_INLINE static void evaluateFull(Func const& evalInner, size_t const& CODI_RESTRICT maxOutputArgs,
1446 size_t const& CODI_RESTRICT maxActiveArgs,
1447 size_t const& CODI_RESTRICT maxConstantArgs,
1448 ADJOINT_VECTOR_TYPE* CODI_RESTRICT adjointVector, STMT_COMMON_ARGS) {
1449 CODI_UNUSED(evalInner);
1450
1451 StatementDataPointers pointers = {};
1452 pointers.populate(maxOutputArgs, maxActiveArgs, numberOfPassiveArguments, maxConstantArgs, byteData);
1453
1454 for (size_t iLhs = 0; iLhs < maxOutputArgs; iLhs += 1) {
1455 // Only called from reuse tape.
1456 Identifier lhsIdentifier = pointers.lhsIdentifiers[iLhs];
1457
1458#if CODI_VariableAdjointInterfaceInPrimalTapes
1459 adjointVector->resetAdjointVec(lhsIdentifier);
1460#else
1461 adjointVector[lhsIdentifier] = Gradient();
1462#endif
1463 }
1464 }
1465
1467 CODI_INLINE static void evaluate(ADJOINT_VECTOR_TYPE* CODI_RESTRICT adjointVector, STMT_COMMON_ARGS) {
1468 Base::internalEvaluate(adjointVector, STMT_COMMON_CALL);
1469 }
1470 };
1471
1472 /*******************************************************************************/
1474 template<typename Stmt>
1476 : public StatementCallGeneratorBase<Stmt, StatementCallGenerator<StatementCall::Forward, Stmt>> {
1477 public:
1480 using StaticRhs = typename Base::StaticRhs;
1481
1482 template<size_t pos>
1483 using ExtractExpr = typename Base::template ExtractExpr<pos>;
1484
1486 CODI_INLINE static void evaluateInner(Real* CODI_RESTRICT primalVector,
1487 ADJOINT_VECTOR_TYPE* CODI_RESTRICT adjointVector,
1488 Real* CODI_RESTRICT lhsPrimals, Gradient* lhsTangents,
1489 PassiveReal const* CODI_RESTRICT const constantValues,
1490 Identifier const* CODI_RESTRICT const rhsIdentifiers) {
1491 StaticRhs staticRhs = Base::constructStaticRhs(primalVector, constantValues, rhsIdentifiers);
1492
1493 IncrementForwardLogic incrementForward;
1494
1496#if CODI_VariableAdjointInterfaceInPrimalTapes
1497 adjointVector->setActiveVariableForIndirectAccess(i.value);
1498#else
1499 lhsTangents[i.value] = Gradient();
1500#endif
1501 ExtractExpr<i.value> expr(staticRhs);
1502
1503 incrementForward.eval(expr, Real(1.0), lhsTangents[i.value], adjointVector);
1504 lhsPrimals[i.value] = expr.getValue();
1505 });
1506 }
1507
1509 template<typename Func>
1510 CODI_INLINE static void evaluateFull(Func const& evalInner, size_t const& CODI_RESTRICT maxOutputArgs,
1511 size_t const& CODI_RESTRICT maxActiveArgs,
1512 size_t const& CODI_RESTRICT maxConstantArgs, Impl& CODI_RESTRICT tape,
1513 Real* CODI_RESTRICT lhsPrimals, Gradient* CODI_RESTRICT lhsTangents,
1514 Real* CODI_RESTRICT primalVector,
1515 ADJOINT_VECTOR_TYPE* CODI_RESTRICT adjointVector,
1516 size_t& CODI_RESTRICT linearAdjointPos, STMT_COMMON_ARGS) {
1517 StatementDataPointers pointers = {};
1518 pointers.populate(maxOutputArgs, maxActiveArgs, numberOfPassiveArguments, maxConstantArgs, byteData);
1519
1520 for (Config::ArgumentSize curPos = 0; curPos < numberOfPassiveArguments; curPos += 1) {
1521 primalVector[curPos] = pointers.passiveValues[curPos];
1522 }
1523
1524 evalInner(primalVector, adjointVector, lhsPrimals, lhsTangents, pointers.constantValues,
1525 pointers.rhsIdentifiers);
1526
1527 for (size_t iLhs = 0; iLhs < maxOutputArgs; iLhs += 1) {
1528 Identifier lhsIdentifier;
1529 if (LinearIndexHandling) {
1530 linearAdjointPos += 1;
1531 lhsIdentifier = linearAdjointPos;
1532 } else {
1533 lhsIdentifier = pointers.lhsIdentifiers[iLhs];
1534 }
1535
1536 if (!LinearIndexHandling) {
1537 pointers.oldLhsValues[iLhs] = primalVector[lhsIdentifier];
1538 }
1539
1540 primalVector[lhsIdentifier] = lhsPrimals[iLhs];
1541
1542#if CODI_VariableAdjointInterfaceInPrimalTapes
1543 adjointVector->setLhsTangent(lhsIdentifier);
1544 EventSystem<Impl>::notifyStatementEvaluateListeners(tape, lhsIdentifier, adjointVector->getVectorSize(),
1545 adjointVector->getAdjointVec(lhsIdentifier));
1546#else
1547 adjointVector[lhsIdentifier] = lhsTangents[iLhs];
1549 GradientTraits::toArray(lhsTangents[iLhs]).data());
1550#endif
1552 primalVector[lhsIdentifier]);
1553 }
1554 }
1555
1558 Gradient* CODI_RESTRICT lhsTangents, Real* CODI_RESTRICT primalVector,
1559 ADJOINT_VECTOR_TYPE* CODI_RESTRICT adjointVector,
1560 size_t& CODI_RESTRICT linearAdjointPos, STMT_COMMON_ARGS) {
1561 Base::internalEvaluate(tape, lhsPrimals, lhsTangents, primalVector, adjointVector, linearAdjointPos,
1562 STMT_COMMON_CALL);
1563 }
1564 };
1565
1566 /*******************************************************************************/
1568 template<typename Stmt>
1570 : public StatementCallGeneratorBase<Stmt, StatementCallGenerator<StatementCall::Primal, Stmt>> {
1571 public:
1574 using StaticRhs = typename Base::StaticRhs;
1575
1576 template<size_t pos>
1577 using ExtractExpr = typename Base::template ExtractExpr<pos>;
1578
1580 CODI_INLINE static void evaluateInner(Real* CODI_RESTRICT lhsPrimals, Real* CODI_RESTRICT primalVector,
1581 PassiveReal const* CODI_RESTRICT const constantValues,
1582 Identifier const* CODI_RESTRICT const rhsIdentifiers) {
1583 StaticRhs staticRhs = Base::constructStaticRhs(primalVector, constantValues, rhsIdentifiers);
1584
1586 ExtractExpr<i.value> expr(staticRhs);
1587
1588 lhsPrimals[i.value] = expr.getValue();
1589 });
1590 }
1591
1593 template<typename Func>
1594 CODI_INLINE static void evaluateFull(Func const& evalInner, size_t const& CODI_RESTRICT maxOutputArgs,
1595 size_t const& CODI_RESTRICT maxActiveArgs,
1596 size_t const& CODI_RESTRICT maxConstantArgs, Impl& CODI_RESTRICT tape,
1597 Real* CODI_RESTRICT lhsPrimals, Real* CODI_RESTRICT primalVector,
1598 size_t& CODI_RESTRICT linearAdjointPos, STMT_COMMON_ARGS) {
1599 StatementDataPointers pointers = {};
1600 pointers.populate(maxOutputArgs, maxActiveArgs, numberOfPassiveArguments, maxConstantArgs, byteData);
1601
1602 for (Config::ArgumentSize curPos = 0; curPos < numberOfPassiveArguments; curPos += 1) {
1603 primalVector[curPos] = pointers.passiveValues[curPos];
1604 }
1605
1606 evalInner(lhsPrimals, primalVector, pointers.constantValues, pointers.rhsIdentifiers);
1607
1608 for (size_t iLhs = 0; iLhs < maxOutputArgs; iLhs += 1) {
1609 Identifier lhsIdentifier;
1610 if (LinearIndexHandling) {
1611 linearAdjointPos += 1;
1612 lhsIdentifier = linearAdjointPos;
1613 } else {
1614 lhsIdentifier = pointers.lhsIdentifiers[iLhs];
1615 }
1616
1617 if (!LinearIndexHandling) {
1618 pointers.oldLhsValues[iLhs] = primalVector[lhsIdentifier];
1619 }
1620
1621 primalVector[lhsIdentifier] = lhsPrimals[iLhs];
1622
1624 primalVector[lhsIdentifier]);
1625 }
1626 }
1627
1630 Real* CODI_RESTRICT primalVector, size_t& CODI_RESTRICT linearAdjointPos,
1631 STMT_COMMON_ARGS) {
1632 Base::internalEvaluate(tape, lhsPrimals, primalVector, linearAdjointPos, STMT_COMMON_CALL);
1633 }
1634 };
1635
1636 /*******************************************************************************/
1638 template<typename Stmt>
1640 : public StatementCallGeneratorBase<Stmt, StatementCallGenerator<StatementCall::Reverse, Stmt>> {
1641 public:
1644 using StaticRhs = typename Base::StaticRhs;
1645
1646 template<size_t pos>
1647 using ExtractExpr = typename Base::template ExtractExpr<pos>;
1648
1650 CODI_INLINE static void evaluateInner(Real* CODI_RESTRICT primalVector,
1651 ADJOINT_VECTOR_TYPE* CODI_RESTRICT adjointVector,
1652 Gradient* CODI_RESTRICT lhsAdjoints,
1653 PassiveReal const* CODI_RESTRICT const constantValues,
1654 Identifier const* CODI_RESTRICT const rhsIdentifiers) {
1655 StaticRhs staticRhs = Base::constructStaticRhs(primalVector, constantValues, rhsIdentifiers);
1656
1657 IncrementReversalLogic incrementReverse;
1659#if CODI_VariableAdjointInterfaceInPrimalTapes
1660 adjointVector->setActiveVariableForIndirectAccess(i.value);
1661#endif
1662 ExtractExpr<i.value> expr(staticRhs);
1663 incrementReverse.eval(expr, Real(1.0), const_cast<Gradient const&>(lhsAdjoints[i.value]), adjointVector);
1664 });
1665 }
1666
1668 template<typename Func>
1669 CODI_INLINE static void evaluateFull(Func const& evalInner, size_t const& CODI_RESTRICT maxOutputArgs,
1670 size_t const& CODI_RESTRICT maxActiveArgs,
1671 size_t const& CODI_RESTRICT maxConstantArgs, Impl& CODI_RESTRICT tape,
1672 Gradient* CODI_RESTRICT lhsAdjoints, Real* CODI_RESTRICT primalVector,
1673 ADJOINT_VECTOR_TYPE* CODI_RESTRICT adjointVector,
1674 size_t& CODI_RESTRICT linearAdjointPos, STMT_COMMON_ARGS) {
1675 StatementDataPointers pointers = {};
1676 pointers.populate(maxOutputArgs, maxActiveArgs, numberOfPassiveArguments, maxConstantArgs, byteData);
1677
1678 if (LinearIndexHandling) {
1679 linearAdjointPos -= maxOutputArgs;
1680 }
1681
1682 bool allZero = true;
1683 for (size_t iLhs = 0; iLhs < maxOutputArgs; iLhs += 1) {
1684 Identifier lhsIdentifier;
1685 if (LinearIndexHandling) {
1686 lhsIdentifier = linearAdjointPos + 1 + iLhs;
1687 } else {
1688 lhsIdentifier = pointers.lhsIdentifiers[iLhs];
1689 }
1690
1691#if CODI_VariableAdjointInterfaceInPrimalTapes
1692 EventSystem<Impl>::notifyStatementEvaluateListeners(tape, lhsIdentifier, adjointVector->getVectorSize(),
1693 adjointVector->getAdjointVec(lhsIdentifier));
1694 adjointVector->setActiveVariableForIndirectAccess(iLhs);
1695 adjointVector->setLhsAdjoint(lhsIdentifier);
1696 allZero &= adjointVector->isLhsZero();
1697#else
1698 lhsAdjoints[iLhs] = adjointVector[lhsIdentifier];
1700 GradientTraits::toArray(lhsAdjoints[iLhs]).data());
1701 adjointVector[lhsIdentifier] = Gradient();
1702 allZero &= RealTraits::isTotalZero(lhsAdjoints[iLhs]);
1703#endif
1704
1706 primalVector[lhsIdentifier]);
1707 if (!LinearIndexHandling) {
1708 primalVector[lhsIdentifier] = pointers.oldLhsValues[iLhs];
1709 }
1710 }
1711
1713 for (Config::ArgumentSize curPos = 0; curPos < numberOfPassiveArguments; curPos += 1) {
1714 primalVector[curPos] = pointers.passiveValues[curPos];
1715 }
1716
1717 evalInner(primalVector, adjointVector, lhsAdjoints, pointers.constantValues, pointers.rhsIdentifiers);
1718 }
1719 }
1720
1723 Real* CODI_RESTRICT primalVector,
1724 ADJOINT_VECTOR_TYPE* CODI_RESTRICT adjointVector,
1725 size_t& CODI_RESTRICT linearAdjointPos, STMT_COMMON_ARGS) {
1726 Base::internalEvaluate(tape, lhsAdjoints, primalVector, adjointVector, linearAdjointPos, STMT_COMMON_CALL);
1727 }
1728 };
1729
1730 /*******************************************************************************/
1732 template<typename Stmt>
1734 : public StatementCallGeneratorBase<Stmt, StatementCallGenerator<StatementCall::ResetPrimals, Stmt>> {
1735 public:
1738 using StaticRhs = typename Base::StaticRhs;
1739
1742
1744 template<typename Func>
1745 CODI_INLINE static void evaluateFull(Func const& evalInner, size_t const& CODI_RESTRICT maxOutputArgs,
1746 size_t const& CODI_RESTRICT maxActiveArgs,
1747 size_t const& CODI_RESTRICT maxConstantArgs,
1748 Real* CODI_RESTRICT primalVector, STMT_COMMON_ARGS) {
1749 CODI_UNUSED(evalInner);
1750
1751 StatementDataPointers pointers = {};
1752 pointers.populate(maxOutputArgs, maxActiveArgs, numberOfPassiveArguments, maxConstantArgs, byteData);
1753
1754 // Only called from reuse tape.
1755 for (size_t iLhs = 0; iLhs < maxOutputArgs; iLhs += 1) {
1756 Identifier lhsIdentifier = pointers.lhsIdentifiers[iLhs];
1757
1758 primalVector[lhsIdentifier] = pointers.oldLhsValues[iLhs];
1759 }
1760 }
1761
1763 CODI_INLINE static void evaluate(Real* CODI_RESTRICT primalVector, STMT_COMMON_ARGS) {
1764 Base::internalEvaluate(primalVector, STMT_COMMON_CALL);
1765 }
1766 };
1767
1769
1770 private:
1771
1772 CODI_INLINE void checkAdjointSize(Identifier const& identifier) {
1773 if (identifier >= (Identifier)adjoints.size()) {
1774 resizeAdjointsVector();
1775 }
1776 }
1777
1778 CODI_INLINE void checkPrimalSize(bool generatedNewIndex) {
1779 if (generatedNewIndex && indexManager.get().getLargestCreatedIndex() >= (Identifier)primals.size()) {
1780 resizePrimalVector();
1781 }
1782 }
1783
1784 CODI_NO_INLINE void resizeAdjointsVector() {
1785 // overallocate as next multiple of Config::ChunkSize
1786 adjoints.resize(getNextMultiple((size_t)indexManager.get().getLargestCreatedIndex() + 1, Config::ChunkSize));
1787 }
1788
1789 CODI_NO_INLINE void resizePrimalVector() {
1790 // overallocate as next multiple of Config::ChunkSize
1791 primals.resize(getNextMultiple((size_t)indexManager.get().getLargestCreatedIndex() + 1, Config::ChunkSize));
1792 }
1793 };
1794
1796 template<size_t size>
1798
1800 template<size_t size>
1802 static size_t constexpr value = size;
1803 };
1804
1806 template<size_t size>
1808 static size_t constexpr value = 0;
1809 };
1810
1813 template<typename T_TapeImpl, size_t T_size>
1816 public:
1817
1821 void>));
1822 static size_t constexpr size = T_size;
1823
1824 using Real = typename TapeImpl::Real;
1825 using Gradient = typename TapeImpl::Gradient;
1826 using Identifier = typename TapeImpl::Identifier;
1827 using PassiveReal = typename TapeImpl::PassiveReal;
1828
1829 using StatementDataPointers = typename TapeImpl::StatementDataPointers;
1830
1831 static size_t constexpr LinearIndexHandling = TapeImpl::LinearIndexHandling;
1832
1834 template<typename Rhs, typename Impl>
1836
1837 /*******************************************************************************/
1840
1842 template<StatementCall type, typename Stmt>
1844
1846 template<typename Stmt>
1848 : public StatementCallGeneratorBase<Stmt, StatementCallGenerator<StatementCall::WriteInformation, Stmt>> {
1849 public:
1852
1855
1857 template<typename Func>
1858 CODI_INLINE static void evaluateFull(Func const& func, size_t const& maxOutputArgs,
1859 size_t const& maxActiveArgs, size_t const& maxConstantArgs,
1860 WriteInfo& writeInfo, Real* primalVector, STMT_COMMON_ARGS) {
1861 CODI_UNUSED(func, primalVector, numberOfPassiveArguments, byteData);
1862
1863 writeInfo.numberOfOutputArguments = maxOutputArgs;
1864 writeInfo.numberOfActiveArguments = maxActiveArgs;
1865 writeInfo.numberOfConstantArguments = maxConstantArgs;
1866 writeInfo.stmtExpression = "Impl, typename Impl::template JacobianStatementGenerator<" +
1867 std::to_string(size) + ">, codi::JacobianExpression<" + std::to_string(size) +
1868 ">";
1869 writeInfo.mathRepresentation = "Jacobian statement";
1870 }
1871
1873 CODI_INLINE static void evaluate(WriteInfo& CODI_RESTRICT writeInfo, Real* CODI_RESTRICT primalVector,
1874 STMT_COMMON_ARGS) {
1875 Base::internalEvaluate(writeInfo, primalVector, STMT_COMMON_CALL);
1876 }
1877 };
1878
1880 template<typename Stmt>
1882 : public StatementCallGeneratorBase<Stmt, StatementCallGenerator<StatementCall::ClearAdjoints, Stmt>> {
1883 public:
1886
1889
1891 template<typename Func>
1892 CODI_INLINE static void evaluateFull(Func const& func, size_t const& maxOutputArgs,
1893 size_t const& maxActiveArgs, size_t const& maxConstantArgs,
1894 ADJOINT_VECTOR_TYPE* adjointVector, STMT_COMMON_ARGS) {
1895 CODI_UNUSED(func);
1896
1897 StatementDataPointers pointers = {};
1898 pointers.populate(maxOutputArgs, maxActiveArgs, numberOfPassiveArguments, maxConstantArgs, byteData);
1899
1900 codiAssert(1 == maxOutputArgs);
1901
1902 // Only called from reuse tape.
1903 Identifier lhsIdentifier = pointers.lhsIdentifiers[0];
1904
1905#if CODI_VariableAdjointInterfaceInPrimalTapes
1906 adjointVector->resetAdjointVec(lhsIdentifier);
1907#else
1908 adjointVector[lhsIdentifier] = Gradient();
1909#endif
1910 }
1911
1913 CODI_INLINE static void evaluate(ADJOINT_VECTOR_TYPE* CODI_RESTRICT adjointVector, STMT_COMMON_ARGS) {
1914 Base::internalEvaluate(adjointVector, STMT_COMMON_CALL);
1915 }
1916 };
1917
1919 template<typename Stmt>
1920 struct StatementCallGenerator<StatementCall::Forward, Stmt> {
1922 static void evaluateInner() {
1923 CODI_EXCEPTION("Forward evaluation of jacobian statement not possible.");
1924 }
1925
1927 static void evaluate() {
1928 CODI_EXCEPTION("Forward evaluation of jacobian statement not possible.");
1929 }
1930 };
1931
1933 template<typename Stmt>
1936 static void evaluateInner() {
1937 CODI_EXCEPTION("Primal evaluation of jacobian statement not possible.");
1938 }
1939
1941 static void evaluate() {
1942 CODI_EXCEPTION("Primal evaluation of jacobian statement not possible.");
1943 }
1944 };
1945
1947 template<typename Stmt>
1949 : public StatementCallGeneratorBase<Stmt, StatementCallGenerator<StatementCall::Reverse, Stmt>> {
1950 public:
1953
1955 static void evaluateInner(Real* primalVector, ADJOINT_VECTOR_TYPE* adjointVector, Gradient* lhsAdjoints,
1956 PassiveReal const* const constantValues, Identifier const* const rhsIdentifiers) {
1957 CODI_UNUSED(constantValues);
1958
1959 evalJacobianReverse(adjointVector, lhsAdjoints[0], primalVector, rhsIdentifiers);
1960 }
1961
1963 static void evaluate(TapeImpl& tape, Gradient* lhsAdjoints, Real* primalVector,
1964 ADJOINT_VECTOR_TYPE* adjointVector, size_t& linearAdjointPos, STMT_COMMON_ARGS) {
1965 CODI_UNUSED(primalVector, lhsAdjoints, numberOfPassiveArguments);
1966
1967 StatementDataPointers pointers = {};
1968 pointers.populate(1, size, size, 0, byteData);
1969
1970 Identifier lhsIdentifier;
1971 if (LinearIndexHandling) {
1972 lhsIdentifier = linearAdjointPos;
1973 } else {
1974 lhsIdentifier = pointers.lhsIdentifiers[0];
1975 }
1976
1977#if CODI_VariableAdjointInterfaceInPrimalTapes
1978 Gradient const lhsAdjoint = {};
1979 EventSystem<TapeImpl>::notifyStatementEvaluateListeners(tape, lhsIdentifier, adjointVector->getVectorSize(),
1980 adjointVector->getAdjointVec(lhsIdentifier));
1981 adjointVector->setLhsAdjoint(lhsIdentifier);
1982#else
1983 Gradient const lhsAdjoint = adjointVector[lhsIdentifier];
1985 tape, lhsIdentifier, GradientTraits::dim<Gradient>(), GradientTraits::toArray(lhsAdjoint).data());
1986 adjointVector[lhsIdentifier] = Gradient();
1987#endif
1988
1990 primalVector[lhsIdentifier]);
1991 if (!LinearIndexHandling) {
1992 primalVector[lhsIdentifier] = pointers.oldLhsValues[0];
1993 }
1994
1995 evalJacobianReverse(adjointVector, lhsAdjoint, pointers.passiveValues, pointers.rhsIdentifiers);
1996 }
1997 };
1998
2000 template<typename Stmt>
2002 : public StatementCallGeneratorBase<Stmt, StatementCallGenerator<StatementCall::ResetPrimals, Stmt>> {
2003 public:
2006
2009
2011 template<typename Func>
2012 CODI_INLINE static void evaluateFull(Func const& evalInner, size_t const& maxOutputArgs,
2013 size_t const& maxActiveArgs, size_t const& maxConstantArgs,
2014 Real* primalVector, STMT_COMMON_ARGS) {
2015 CODI_UNUSED(evalInner, maxActiveArgs, maxConstantArgs, numberOfPassiveArguments);
2016
2017 StatementDataPointers pointers = {};
2018 pointers.populate(1, size, size, 0, byteData);
2019
2020 codiAssert(1 == maxOutputArgs);
2021
2022 // Only called from reuse tape.
2023 Identifier lhsIdentifier = pointers.lhsIdentifiers[0];
2024 primalVector[lhsIdentifier] = pointers.oldLhsValues[0];
2025 }
2026
2028 CODI_INLINE static void evaluate(Real* CODI_RESTRICT primalVector, STMT_COMMON_ARGS) {
2029 Base::internalEvaluate(primalVector, STMT_COMMON_CALL);
2030 }
2031 };
2032
2034
2035 private:
2036 static void evalJacobianReverse(ADJOINT_VECTOR_TYPE* adjointVector, Gradient lhsAdjoint, Real const* const values,
2037 Identifier const* const rhsIdentifiers) {
2038#if CODI_VariableAdjointInterfaceInPrimalTapes
2039 CODI_UNUSED(lhsAdjoint);
2040 bool const lhsZero = adjointVector->isLhsZero();
2041#else
2042 bool const lhsZero = RealTraits::isTotalZero(lhsAdjoint);
2043#endif
2044
2046 for (size_t pos = 0; pos < size; pos += 1) {
2047 Real const& jacobian = values[pos];
2048#if CODI_VariableAdjointInterfaceInPrimalTapes
2049 adjointVector->updateAdjointWithLhs(rhsIdentifiers[pos], jacobian);
2050#else
2051 adjointVector[rhsIdentifiers[pos]] += jacobian * lhsAdjoint;
2052#endif
2053 }
2054 }
2055 }
2056 };
2057
2058#undef STMT_COMMON_ARGS
2059#undef STMT_COMMON_CALL
2060
2061#define CREATE_EXPRESSION(size) \
2062 TapeTypes::StatementEvaluator::template createHandle<Impl, JacobianStatementGenerator<Impl, size>, \
2063 AssignStatement<ActiveType<Impl>, JacobianExpression<size>>>()
2064
2066 template<typename TapeTypes, typename Impl>
2067 const CODI_DD(typename TapeTypes::EvalHandle,
2068 CODI_ANY) PrimalValueBaseTape<TapeTypes, Impl>::jacobianExpressions[Config::MaxArgumentSize] = {
2069 CREATE_EXPRESSION(0), CREATE_EXPRESSION(1), CREATE_EXPRESSION(2), CREATE_EXPRESSION(3),
2070 CREATE_EXPRESSION(4), CREATE_EXPRESSION(5), CREATE_EXPRESSION(6), CREATE_EXPRESSION(7),
2071 CREATE_EXPRESSION(8), CREATE_EXPRESSION(9), CREATE_EXPRESSION(10), CREATE_EXPRESSION(11),
2072 CREATE_EXPRESSION(12), CREATE_EXPRESSION(13), CREATE_EXPRESSION(14), CREATE_EXPRESSION(15),
2073 CREATE_EXPRESSION(16), CREATE_EXPRESSION(17), CREATE_EXPRESSION(18), CREATE_EXPRESSION(19),
2074 CREATE_EXPRESSION(20), CREATE_EXPRESSION(21), CREATE_EXPRESSION(22), CREATE_EXPRESSION(23),
2075 CREATE_EXPRESSION(24), CREATE_EXPRESSION(25), CREATE_EXPRESSION(26), CREATE_EXPRESSION(27),
2076 CREATE_EXPRESSION(28), CREATE_EXPRESSION(29), CREATE_EXPRESSION(30), CREATE_EXPRESSION(31),
2077 CREATE_EXPRESSION(32), CREATE_EXPRESSION(33), CREATE_EXPRESSION(34), CREATE_EXPRESSION(35),
2078 CREATE_EXPRESSION(36), CREATE_EXPRESSION(37), CREATE_EXPRESSION(38), CREATE_EXPRESSION(39),
2079 CREATE_EXPRESSION(40), CREATE_EXPRESSION(41), CREATE_EXPRESSION(42), CREATE_EXPRESSION(43),
2080 CREATE_EXPRESSION(44), CREATE_EXPRESSION(45), CREATE_EXPRESSION(46), CREATE_EXPRESSION(47),
2081 CREATE_EXPRESSION(48), CREATE_EXPRESSION(49), CREATE_EXPRESSION(50), CREATE_EXPRESSION(51),
2082 CREATE_EXPRESSION(52), CREATE_EXPRESSION(53), CREATE_EXPRESSION(54), CREATE_EXPRESSION(55),
2083 CREATE_EXPRESSION(56), CREATE_EXPRESSION(57), CREATE_EXPRESSION(58), CREATE_EXPRESSION(59),
2084 CREATE_EXPRESSION(60), CREATE_EXPRESSION(61), CREATE_EXPRESSION(62), CREATE_EXPRESSION(63),
2085 CREATE_EXPRESSION(64), CREATE_EXPRESSION(65), CREATE_EXPRESSION(66), CREATE_EXPRESSION(67),
2086 CREATE_EXPRESSION(68), CREATE_EXPRESSION(69), CREATE_EXPRESSION(70), CREATE_EXPRESSION(71),
2087 CREATE_EXPRESSION(72), CREATE_EXPRESSION(73), CREATE_EXPRESSION(74), CREATE_EXPRESSION(75),
2088 CREATE_EXPRESSION(76), CREATE_EXPRESSION(77), CREATE_EXPRESSION(78), CREATE_EXPRESSION(79),
2089 CREATE_EXPRESSION(80), CREATE_EXPRESSION(81), CREATE_EXPRESSION(82), CREATE_EXPRESSION(83),
2090 CREATE_EXPRESSION(84), CREATE_EXPRESSION(85), CREATE_EXPRESSION(86), CREATE_EXPRESSION(87),
2091 CREATE_EXPRESSION(88), CREATE_EXPRESSION(89), CREATE_EXPRESSION(90), CREATE_EXPRESSION(91),
2092 CREATE_EXPRESSION(92), CREATE_EXPRESSION(93), CREATE_EXPRESSION(94), CREATE_EXPRESSION(95),
2093 CREATE_EXPRESSION(96), CREATE_EXPRESSION(97), CREATE_EXPRESSION(98), CREATE_EXPRESSION(99),
2094 CREATE_EXPRESSION(100), CREATE_EXPRESSION(101), CREATE_EXPRESSION(102), CREATE_EXPRESSION(103),
2095 CREATE_EXPRESSION(104), CREATE_EXPRESSION(105), CREATE_EXPRESSION(106), CREATE_EXPRESSION(107),
2096 CREATE_EXPRESSION(108), CREATE_EXPRESSION(109), CREATE_EXPRESSION(110), CREATE_EXPRESSION(111),
2097 CREATE_EXPRESSION(112), CREATE_EXPRESSION(113), CREATE_EXPRESSION(114), CREATE_EXPRESSION(115),
2098 CREATE_EXPRESSION(116), CREATE_EXPRESSION(117), CREATE_EXPRESSION(118), CREATE_EXPRESSION(119),
2099 CREATE_EXPRESSION(120), CREATE_EXPRESSION(121), CREATE_EXPRESSION(122), CREATE_EXPRESSION(123),
2100 CREATE_EXPRESSION(124), CREATE_EXPRESSION(125), CREATE_EXPRESSION(126), CREATE_EXPRESSION(127),
2101 CREATE_EXPRESSION(128), CREATE_EXPRESSION(129), CREATE_EXPRESSION(130), CREATE_EXPRESSION(131),
2102 CREATE_EXPRESSION(132), CREATE_EXPRESSION(133), CREATE_EXPRESSION(134), CREATE_EXPRESSION(135),
2103 CREATE_EXPRESSION(136), CREATE_EXPRESSION(137), CREATE_EXPRESSION(138), CREATE_EXPRESSION(139),
2104 CREATE_EXPRESSION(140), CREATE_EXPRESSION(141), CREATE_EXPRESSION(142), CREATE_EXPRESSION(143),
2105 CREATE_EXPRESSION(144), CREATE_EXPRESSION(145), CREATE_EXPRESSION(146), CREATE_EXPRESSION(147),
2106 CREATE_EXPRESSION(148), CREATE_EXPRESSION(149), CREATE_EXPRESSION(150), CREATE_EXPRESSION(151),
2107 CREATE_EXPRESSION(152), CREATE_EXPRESSION(153), CREATE_EXPRESSION(154), CREATE_EXPRESSION(155),
2108 CREATE_EXPRESSION(156), CREATE_EXPRESSION(157), CREATE_EXPRESSION(158), CREATE_EXPRESSION(159),
2109 CREATE_EXPRESSION(160), CREATE_EXPRESSION(161), CREATE_EXPRESSION(162), CREATE_EXPRESSION(163),
2110 CREATE_EXPRESSION(164), CREATE_EXPRESSION(165), CREATE_EXPRESSION(166), CREATE_EXPRESSION(167),
2111 CREATE_EXPRESSION(168), CREATE_EXPRESSION(169), CREATE_EXPRESSION(170), CREATE_EXPRESSION(171),
2112 CREATE_EXPRESSION(172), CREATE_EXPRESSION(173), CREATE_EXPRESSION(174), CREATE_EXPRESSION(175),
2113 CREATE_EXPRESSION(176), CREATE_EXPRESSION(177), CREATE_EXPRESSION(178), CREATE_EXPRESSION(179),
2114 CREATE_EXPRESSION(180), CREATE_EXPRESSION(181), CREATE_EXPRESSION(182), CREATE_EXPRESSION(183),
2115 CREATE_EXPRESSION(184), CREATE_EXPRESSION(185), CREATE_EXPRESSION(186), CREATE_EXPRESSION(187),
2116 CREATE_EXPRESSION(188), CREATE_EXPRESSION(189), CREATE_EXPRESSION(190), CREATE_EXPRESSION(191),
2117 CREATE_EXPRESSION(192), CREATE_EXPRESSION(193), CREATE_EXPRESSION(194), CREATE_EXPRESSION(195),
2118 CREATE_EXPRESSION(196), CREATE_EXPRESSION(197), CREATE_EXPRESSION(198), CREATE_EXPRESSION(199),
2119 CREATE_EXPRESSION(200), CREATE_EXPRESSION(201), CREATE_EXPRESSION(202), CREATE_EXPRESSION(203),
2120 CREATE_EXPRESSION(204), CREATE_EXPRESSION(205), CREATE_EXPRESSION(206), CREATE_EXPRESSION(207),
2121 CREATE_EXPRESSION(208), CREATE_EXPRESSION(209), CREATE_EXPRESSION(210), CREATE_EXPRESSION(211),
2122 CREATE_EXPRESSION(212), CREATE_EXPRESSION(213), CREATE_EXPRESSION(214), CREATE_EXPRESSION(215),
2123 CREATE_EXPRESSION(216), CREATE_EXPRESSION(217), CREATE_EXPRESSION(218), CREATE_EXPRESSION(219),
2124 CREATE_EXPRESSION(220), CREATE_EXPRESSION(221), CREATE_EXPRESSION(222), CREATE_EXPRESSION(223),
2125 CREATE_EXPRESSION(224), CREATE_EXPRESSION(225), CREATE_EXPRESSION(226), CREATE_EXPRESSION(227),
2126 CREATE_EXPRESSION(228), CREATE_EXPRESSION(229), CREATE_EXPRESSION(230), CREATE_EXPRESSION(231),
2127 CREATE_EXPRESSION(232), CREATE_EXPRESSION(233), CREATE_EXPRESSION(234), CREATE_EXPRESSION(235),
2128 CREATE_EXPRESSION(236), CREATE_EXPRESSION(237), CREATE_EXPRESSION(238), CREATE_EXPRESSION(239),
2129 CREATE_EXPRESSION(240), CREATE_EXPRESSION(241), CREATE_EXPRESSION(242), CREATE_EXPRESSION(243),
2130 CREATE_EXPRESSION(244), CREATE_EXPRESSION(245), CREATE_EXPRESSION(246), CREATE_EXPRESSION(247),
2131 CREATE_EXPRESSION(248), CREATE_EXPRESSION(249), CREATE_EXPRESSION(250), CREATE_EXPRESSION(251),
2132 CREATE_EXPRESSION(252)};
2133
2134#undef CREATE_EXPRESSION
2135}
#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 ADJOINT_VECTOR_TYPE
See codi::Config::VariableAdjointInterfaceInPrimalTapes.
Definition config.h:286
#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 codiAssert(x)
See codi::Config::EnableAssert.
Definition config.h:441
#define CODI_DD(Type, Default)
Abbreviation for CODI_DECLARE_DEFAULT.
Definition macros.hpp:96
#define CODI_ENABLE_CHECK(option, condition)
Definition macros.hpp:61
#define CODI_WRAP_FUNCTION(NAME, FUNC)
Wrap a function in a function object. Used for performance optimizations.
Definition macros.hpp:165
#define CODI_ANY
Used in default declarations of expression templates.
Definition macros.hpp:100
#define CODI_STATIC_ASSERT(cond, message)
Static assert definition for CoDiPack. Not evaluated in IDE mode.
Definition macros.hpp:129
#define CODI_T(...)
Abbreviation for CODI_TEMPLATE.
Definition macros.hpp:116
Configuration options for CoDiPack.
Definition config.h:65
uint16_t LowLevelFunctionDataSize
Size store type for a low level function.
Definition config.h:98
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:328
bool constexpr CopyOptimization
Do not store copy statements like a = b; if the identity handler allows it.
Definition config.h:186
bool constexpr VariableAdjointInterfaceInPrimalTapes
Allow custom adjoint vector in primal values tapes.
Definition config.h:281
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
inlinestd::array< AtomicTraits::RemoveAtomic< typename TraitsImplementation< Gradient >::Real >, TraitsImplementation< Gradient >::dim > toArray(Gradient const &gradient)
Converts the (possibly multi-component) gradient to an array of Reals.
Definition gradientTraits.hpp:116
inlinesize_t constexpr dim()
Number of dimensions this gradient value has.
Definition gradientTraits.hpp:96
inlinebool isTotalFinite(Type const &v)
Function for checking if all values of the type are finite.
Definition realTraits.hpp:139
inlinebool isTotalZero(Type const &v)
Function for checking if the value of the type is completely zero.
Definition realTraits.hpp:145
typename TraitsImplementation< Type >::PassiveReal PassiveReal
The original computation type that was used in the application.
Definition realTraits.hpp:123
CoDiPack - Code Differentiation Package.
Definition codi.hpp:94
IntegralType getNextMultiple(IntegralType const &targetSize, IntegralType const &chunkSize)
Helper function for overallocation in multiples of a given chunk size.
Definition mathUtility.hpp:49
std::string demangleName()
Return a string of the provided template name.
Definition demangleName.hpp:47
TapeParameters
Configuration options for a tape.
Definition tapeParameters.hpp:52
@ StatementByteSize
[A: RW] Allocated size of the byte data for the statement data.
Definition tapeParameters.hpp:67
@ LargestIdentifier
[A: R] Largest identifier distributed by the index manger.
Definition tapeParameters.hpp:60
@ PrimalSize
[A: RW] Number of primal vector entries in primal value tapes.
Definition tapeParameters.hpp:63
@ 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
StatementCall
Defines all the operations which can be evaluated on a statement by a tape.
Definition statementEvaluatorTapeInterface.hpp:45
@ WriteInformation
Get write information.
Definition statementEvaluatorTapeInterface.hpp:51
@ ResetPrimals
Restore the primal values.
Definition statementEvaluatorTapeInterface.hpp:49
@ ClearAdjoints
Clear the adjoint values.
Definition statementEvaluatorTapeInterface.hpp:46
typename ArrayAccessExpressionImpl< Aggregated, element >::template Expression< Arg > ArrayAccessExpression
Expression that performs a[element] in a compile time context.
Definition arrayAccessExpression.hpp:98
inlineauto real(ExpressionInterface< std::complex< Real >, Arg > const &arg)
Function overload for FUNCTION.
Definition allOperators.hpp:75
inlinevoid CODI_UNUSED(Args const &...)
Disable unused warnings for an arbitrary number of arguments.
Definition macros.hpp:54
AdjointsManagement
Policies for management of the tape's interal adjoints.
Definition tapeParameters.hpp:100
@ Automatic
Manage internal adjoints automatically, including locking, bounds checking, and resizing.
Definition tapeParameters.hpp:102
ChunkedData< Chunk, NestedData > DefaultChunkedData
ChunkData DataInterface used in all regular tapes.
Definition chunkedData.hpp:520
InnerActiveType values[Elements]
Array representation.
Definition aggregatedActiveType.hpp:75
Represents a concrete aggregated lvalue int the CoDiPack expression tree.
Definition aggregatedActiveType.hpp:164
Definition assignStatement.hpp:50
Definition byteDataView.hpp:51
Definition chunk.hpp:185
Definition chunk.hpp:400
inlinevoid internalStoreLowLevelFunction(Config::LowLevelFunctionToken token, size_t size, ByteDataView &dataView)
Definition commonTapeImplementation.hpp:494
inlinevoid initializeManualPushData(Real const &lhsValue, Identifier const &lhsIndex, size_t size)
Initialize all manual push data, including the counter. Check that a previous manual store is complet...
Definition commonTapeImplementation.hpp:200
Real manualPushLhsValue
For storeManual, remember the value assigned to the lhs.
Definition commonTapeImplementation.hpp:158
void setParameter(TapeParameters parameter, size_t value)
Definition commonTapeImplementation.hpp:459
void evaluateForward(AdjointsManagement adjointsManagement=AdjointsManagement::Automatic)
Definition commonTapeImplementation.hpp:611
size_t manualPushCounter
Count the pushes after storeManual, to identify the last push.
Definition commonTapeImplementation.hpp:161
inlinevoid resetTo(Position const &pos, bool resetAdjoints=true, AdjointsManagement adjointsManagement=AdjointsManagement::Automatic)
Definition commonTapeImplementation.hpp:723
Identifier manualPushLhsIdentifier
For storeManual, remember the identifier assigned to the lhs.
Definition commonTapeImplementation.hpp:159
bool isActive() const
Definition commonTapeImplementation.hpp:320
size_t manualPushGoal
Store the number of expected pushes after a storeManual call.
Definition commonTapeImplementation.hpp:160
void init(typename ImplTapeTypes::NestedData *nested)
Definition commonTapeImplementation.hpp:770
std::set< TapeParameters > options
All options.
Definition commonTapeImplementation.hpp:153
void writeTape(std::unique_ptr< TapeWriterInterface< Type > > writer)
Definition commonTapeImplementation.hpp:624
void evaluate(AdjointsManagement adjointsManagement=AdjointsManagement::Automatic)
Definition commonTapeImplementation.hpp:293
void swap(Impl &other)
Definition commonTapeImplementation.hpp:368
inlinevoid reset(bool resetAdjoints=true, AdjointsManagement adjointsManagement=AdjointsManagement::Automatic)
Definition commonTapeImplementation.hpp:355
typename CommonTapeTypes< ImplTapeTypes >::Position Position
Definition commonTapeImplementation.hpp:145
LowLevelFunctionByteData llfByteData
Byte data for low level functions.
Definition commonTapeImplementation.hpp:156
CommonTapeImplementation()
Definition commonTapeImplementation.hpp:232
size_t getParameter(TapeParameters parameter) const
Definition commonTapeImplementation.hpp:431
void evaluatePrimal()
Definition commonTapeImplementation.hpp:745
Helper class for the construction of an expression in a different context.
Definition constructStaticContext.hpp:69
Rhs ResultType
Definition constructStaticContext.hpp:85
static ResultType construct(Real *primalVector, Identifier const *const identifiers, PassiveReal const *const constantData)
Data stream interface for tape data. Encapsulates data that is written e.g. for each statement or arg...
Definition dataInterface.hpp:149
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
static inlinevoid notifyStatementEvaluatePrimalListeners(Tape &tape, Identifier const &lhsIdentifier, Real const &lhsValue)
Invoke callbacks for StatementEvaluatePrimal events.
Definition eventSystem.hpp:745
static inlinevoid notifyStatementEvaluateListeners(Tape &tape, Identifier const &lhsIdentifier, size_t sizeLhsAdjoint, Real const *lhsAdjoint)
Invoke callbacks for StatementEvaluate events.
Definition eventSystem.hpp:712
Base class for all CoDiPack expressions.
Definition expressionInterface.hpp:60
inlineImpl const & cast() const
Cast to the implementation.
Definition expressionInterface.hpp:76
static size_t constexpr value
Number of arguments.
Definition primalValueBaseTape.hpp:1802
Counts the number of nodes that inherit from LhsExpressionInterface in the expression.
Definition expressionTraits.hpp:226
static size_t constexpr value
See NumberOfActiveTypeArguments.
Definition expressionTraits.hpp:240
static size_t constexpr value
Always zero.
Definition primalValueBaseTape.hpp:1808
Counts the number of types that inherit from ConstantExpression in the expression.
Definition expressionTraits.hpp:250
static size_t constexpr value
See NumberOfConstantTypeArguments.
Definition expressionTraits.hpp:264
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:54
Specialized for NumberOfActiveTypeArguments and NumberOfConstantTypeArguments.
Definition primalValueBaseTape.hpp:1797
inlinestatic void evaluate(Gradient *adjointVector, Config::ArgumentSize numberOfPassiveArguments, char *byteData)
Evaluate the full expression.
Definition primalValueBaseTape.hpp:1913
StatementCallGeneratorBase< Stmt, StatementCallGenerator< StatementCall::ClearAdjoints, Stmt > > Base
Base class abbreviation.
Definition primalValueBaseTape.hpp:1885
inlinestatic void evaluateInner()
Evaluate expression in a forward mode.
Definition primalValueBaseTape.hpp:1888
inlinestatic void evaluateFull(Func const &func, size_t const &maxOutputArgs, size_t const &maxActiveArgs, size_t const &maxConstantArgs, Gradient *adjointVector, Config::ArgumentSize numberOfPassiveArguments, char *byteData)
Load the expression data and evaluate the expression.
Definition primalValueBaseTape.hpp:1892
static void evaluateInner()
Throws exception.
Definition primalValueBaseTape.hpp:1922
static void evaluate()
Throws exception.
Definition primalValueBaseTape.hpp:1927
static void evaluateInner()
Throws exception.
Definition primalValueBaseTape.hpp:1936
static void evaluate()
Throws exception.
Definition primalValueBaseTape.hpp:1941
inlinestatic void evaluateInner()
Evaluate expression in a forward mode.
Definition primalValueBaseTape.hpp:2008
inlinestatic void evaluateFull(Func const &evalInner, size_t const &maxOutputArgs, size_t const &maxActiveArgs, size_t const &maxConstantArgs, Real *primalVector, Config::ArgumentSize numberOfPassiveArguments, char *byteData)
Load the expression data and evaluate the expression.
Definition primalValueBaseTape.hpp:2012
StatementCallGeneratorBase< Stmt, StatementCallGenerator< StatementCall::ResetPrimals, Stmt > > Base
Base class abbreviation.
Definition primalValueBaseTape.hpp:2005
inlinestatic void evaluate(Real *primalVector, Config::ArgumentSize numberOfPassiveArguments, char *byteData)
Evaluate the full expression.
Definition primalValueBaseTape.hpp:2028
StatementCallGeneratorBase< Stmt, StatementCallGenerator< StatementCall::Reverse, Stmt > > Base
Base class abbreviation.
Definition primalValueBaseTape.hpp:1952
static void evaluateInner(Real *primalVector, Gradient *adjointVector, Gradient *lhsAdjoints, PassiveReal const *const constantValues, Identifier const *const rhsIdentifiers)
Evaluate expression in a forward mode.
Definition primalValueBaseTape.hpp:1955
static void evaluate(TapeImpl &tape, Gradient *lhsAdjoints, Real *primalVector, Gradient *adjointVector, size_t &linearAdjointPos, Config::ArgumentSize numberOfPassiveArguments, char *byteData)
Evaluate the full expression.
Definition primalValueBaseTape.hpp:1963
StatementCallGeneratorBase< Stmt, StatementCallGenerator< StatementCall::WriteInformation, Stmt > > Base
Base class abbreviation.
Definition primalValueBaseTape.hpp:1851
inlinestatic void evaluateInner()
Evaluate expression in a forward mode.
Definition primalValueBaseTape.hpp:1854
inlinestatic void evaluateFull(Func const &func, size_t const &maxOutputArgs, size_t const &maxActiveArgs, size_t const &maxConstantArgs, WriteInfo &writeInfo, Real *primalVector, Config::ArgumentSize numberOfPassiveArguments, char *byteData)
Load the expression data and evaluate the expression.
Definition primalValueBaseTape.hpp:1858
inlinestatic void evaluate(WriteInfo &writeInfo, Real *primalVector, Config::ArgumentSize numberOfPassiveArguments, char *byteData)
Evaluate the full expression.
Definition primalValueBaseTape.hpp:1873
This structure is accessed by the StatementEvaluatorInterface.
Definition primalValueBaseTape.hpp:1843
Definition primalValueBaseTape.hpp:1815
typename TapeImpl::Identifier Identifier
See PrimalValueBaseTape.
Definition primalValueBaseTape.hpp:1826
typename TapeImpl::Real Real
See PrimalValueBaseTape.
Definition primalValueBaseTape.hpp:1824
typename TapeImpl::StatementDataPointers StatementDataPointers
Defined in PrimalValueBaseTape.
Definition primalValueBaseTape.hpp:1829
static size_t constexpr size
See JacobianStatementGenerator.
Definition primalValueBaseTape.hpp:1822
T_TapeImpl TapeImpl
PrimalValueBaseTape.
Definition primalValueBaseTape.hpp:1818
typename TapeImpl::PassiveReal PassiveReal
See PrimalValueBaseTape.
Definition primalValueBaseTape.hpp:1827
typename TapeImpl::template StatementCallGeneratorBase< Rhs, Impl > StatementCallGeneratorBase
Base for statement generators.
Definition primalValueBaseTape.hpp:1835
static size_t constexpr LinearIndexHandling
See PrimalValueBaseTape.
Definition primalValueBaseTape.hpp:1831
typename TapeImpl::Gradient Gradient
See PrimalValueBaseTape.
Definition primalValueBaseTape.hpp:1825
Default implementation of the Jacobian interface.
Definition jacobian.hpp:60
Base class for all CoDiPack lvalue expression.
Definition lhsExpressionInterface.hpp:63
inlineImpl & cast()
Cast to the implementation.
Definition lhsExpressionInterface.hpp:99
Creates a math representation from a given rhs in the form of a string.
Definition mathStatementGenLogic.hpp:57
inlinevoid eval(NodeInterface< Node > const &node, std::string &mathRep)
Produces a math representation string for a given statement.
Definition mathStatementGenLogic.hpp:66
Defines a member that can either be static or local to the struct.
Definition memberStore.hpp:56
Implementation of VectorAccessInterface for adjoint and primal vectors.
Definition primalAdjointVectorAccess.hpp:59
Count all arguments that have non-zero index.
Definition primalValueBaseTape.hpp:397
inlinevoid handleActive(Node const &node, size_t &numberOfActiveArguments)
Called for leaf nodes which implement LhsExpressionInterface.
Definition primalValueBaseTape.hpp:402
Perform the adjoint update based on the configuration in codi::Config::VariableAdjointInterfaceInPrim...
Definition primalValueBaseTape.hpp:788
inlinevoid handleJacobianOnActive(Node const &node, Real jacobian, Gradient &lhsTangent, Gradient *adjointVector)
Called for leaf nodes which implement LhsExpressionInterface.
Definition primalValueBaseTape.hpp:793
Perform the adjoint update based on the configuration in codi::Config::VariableAdjointInterfaceInPrim...
Definition primalValueBaseTape.hpp:842
inlinevoid handleJacobianOnActive(Node const &node, Real jacobian, Gradient const &lhsAdjoint, Gradient *adjointVector)
See IncrementReversalLogic.
Definition primalValueBaseTape.hpp:847
JacobianExtractionLogic()
Constructor.
Definition primalValueBaseTape.hpp:486
inlinevoid handleJacobianOnActive(Node const &node, Jacobian jacobianExpr, Identifier *rhsIdentifiers, Real *jacobians)
Stores the identifiers and Jacobians.
Definition primalValueBaseTape.hpp:490
Push all data for each argument.
Definition primalValueBaseTape.hpp:410
inlinevoid handleActive(Node const &node, StatementDataPointers &pointers, size_t &curPassiveArgument)
Called for leaf nodes which implement LhsExpressionInterface.
Definition primalValueBaseTape.hpp:415
inlinevoid handleConstant(Node const &node, StatementDataPointers &pointers, size_t &curPassiveArgument)
Called for leaf nodes which implement ConstantExpression.
Definition primalValueBaseTape.hpp:429
Base class for statement call generators. Prepares the static construction context.
Definition primalValueBaseTape.hpp:1334
ArrayAccessExpression< LhsReal, pos, StaticRhs > ExtractExpr
Extract expressions for aggregated types.
Definition primalValueBaseTape.hpp:1345
inlinestatic StaticRhs constructStaticRhs(Real *primalVector, PassiveReal const *const constantValues, Identifier const *const identifiers)
Construct the statement in the static context.
Definition primalValueBaseTape.hpp:1349
typename Lhs::Real LhsReal
Primal value of lhs.
Definition primalValueBaseTape.hpp:1338
typename Stmt::Lhs Lhs
See AssignStatement.
Definition primalValueBaseTape.hpp:1336
typename Constructor::ResultType StaticRhs
Static right hand side.
Definition primalValueBaseTape.hpp:1342
inlinestatic void internalEvaluate(Args &&... args)
Evaluate the full expression.
Definition primalValueBaseTape.hpp:1357
RealTraits::AggregatedTypeTraits< LhsReal > AggregateTraits
Traits for aggregated type.
Definition primalValueBaseTape.hpp:1339
typename Stmt::Rhs Rhs
See AssignStatement.
Definition primalValueBaseTape.hpp:1337
ConstructStaticContextLogic< Rhs, Impl, 0, 0 > Constructor
Static construction context.
Definition primalValueBaseTape.hpp:1341
inlinestatic void evaluate(Gradient *adjointVector, Config::ArgumentSize numberOfPassiveArguments, char *byteData)
Evaluate the full expression.
Definition primalValueBaseTape.hpp:1467
typename Base::StaticRhs StaticRhs
See StatementCallGeneratorBase.
Definition primalValueBaseTape.hpp:1438
StatementCallGeneratorBase< Stmt, StatementCallGenerator< StatementCall::ClearAdjoints, Stmt > > Base
Base class abbreviation.
Definition primalValueBaseTape.hpp:1437
inlinestatic void evaluateInner()
Evaluate expression in a forward mode.
Definition primalValueBaseTape.hpp:1441
inlinestatic void evaluateFull(Func const &evalInner, size_t const &maxOutputArgs, size_t const &maxActiveArgs, size_t const &maxConstantArgs, Gradient *adjointVector, Config::ArgumentSize numberOfPassiveArguments, char *byteData)
Load the expression data and evaluate the expression.
Definition primalValueBaseTape.hpp:1445
inlinestatic void evaluate(Impl &tape, Real *lhsPrimals, Gradient *lhsTangents, Real *primalVector, Gradient *adjointVector, size_t &linearAdjointPos, Config::ArgumentSize numberOfPassiveArguments, char *byteData)
Evaluate the full expression.
Definition primalValueBaseTape.hpp:1557
inlinestatic void evaluateInner(Real *primalVector, Gradient *adjointVector, Real *lhsPrimals, Gradient *lhsTangents, PassiveReal const *const constantValues, Identifier const *const rhsIdentifiers)
Evaluate expression in a forward mode.
Definition primalValueBaseTape.hpp:1486
inlinestatic void evaluateFull(Func const &evalInner, size_t const &maxOutputArgs, size_t const &maxActiveArgs, size_t const &maxConstantArgs, Impl &tape, Real *lhsPrimals, Gradient *lhsTangents, Real *primalVector, Gradient *adjointVector, size_t &linearAdjointPos, Config::ArgumentSize numberOfPassiveArguments, char *byteData)
Load the expression data and evaluate the expression.
Definition primalValueBaseTape.hpp:1510
StatementCallGeneratorBase< Stmt, StatementCallGenerator< StatementCall::Forward, Stmt > > Base
Base class abbreviation.
Definition primalValueBaseTape.hpp:1479
typename Base::template ExtractExpr< pos > ExtractExpr
See StatementCallGeneratorBase.
Definition primalValueBaseTape.hpp:1483
typename Base::StaticRhs StaticRhs
See StatementCallGeneratorBase.
Definition primalValueBaseTape.hpp:1480
typename Base::template ExtractExpr< pos > ExtractExpr
See StatementCallGeneratorBase.
Definition primalValueBaseTape.hpp:1577
inlinestatic void evaluate(Impl &tape, Real *lhsPrimals, Real *primalVector, size_t &linearAdjointPos, Config::ArgumentSize numberOfPassiveArguments, char *byteData)
Evaluate the full expression.
Definition primalValueBaseTape.hpp:1629
StatementCallGeneratorBase< Stmt, StatementCallGenerator< StatementCall::Primal, Stmt > > Base
Base class abbreviation.
Definition primalValueBaseTape.hpp:1573
inlinestatic void evaluateFull(Func const &evalInner, size_t const &maxOutputArgs, size_t const &maxActiveArgs, size_t const &maxConstantArgs, Impl &tape, Real *lhsPrimals, Real *primalVector, size_t &linearAdjointPos, Config::ArgumentSize numberOfPassiveArguments, char *byteData)
Load the expression data and evaluate the expression.
Definition primalValueBaseTape.hpp:1594
inlinestatic void evaluateInner(Real *lhsPrimals, Real *primalVector, PassiveReal const *const constantValues, Identifier const *const rhsIdentifiers)
Evaluate expression in a forward mode.
Definition primalValueBaseTape.hpp:1580
typename Base::StaticRhs StaticRhs
See StatementCallGeneratorBase.
Definition primalValueBaseTape.hpp:1574
typename Base::StaticRhs StaticRhs
See StatementCallGeneratorBase.
Definition primalValueBaseTape.hpp:1738
inlinestatic void evaluate(Real *primalVector, Config::ArgumentSize numberOfPassiveArguments, char *byteData)
Evaluate the full expression.
Definition primalValueBaseTape.hpp:1763
inlinestatic void evaluateInner()
Evaluate expression in a forward mode.
Definition primalValueBaseTape.hpp:1741
StatementCallGeneratorBase< Stmt, StatementCallGenerator< StatementCall::ResetPrimals, Stmt > > Base
Base class abbreviation.
Definition primalValueBaseTape.hpp:1737
inlinestatic void evaluateFull(Func const &evalInner, size_t const &maxOutputArgs, size_t const &maxActiveArgs, size_t const &maxConstantArgs, Real *primalVector, Config::ArgumentSize numberOfPassiveArguments, char *byteData)
Load the expression data and evaluate the expression.
Definition primalValueBaseTape.hpp:1745
inlinestatic void evaluateInner(Real *primalVector, Gradient *adjointVector, Gradient *lhsAdjoints, PassiveReal const *const constantValues, Identifier const *const rhsIdentifiers)
Evaluate expression in a forward mode.
Definition primalValueBaseTape.hpp:1650
inlinestatic void evaluate(Impl &tape, Gradient *lhsAdjoints, Real *primalVector, Gradient *adjointVector, size_t &linearAdjointPos, Config::ArgumentSize numberOfPassiveArguments, char *byteData)
Evaluate the full expression.
Definition primalValueBaseTape.hpp:1722
inlinestatic void evaluateFull(Func const &evalInner, size_t const &maxOutputArgs, size_t const &maxActiveArgs, size_t const &maxConstantArgs, Impl &tape, Gradient *lhsAdjoints, Real *primalVector, Gradient *adjointVector, size_t &linearAdjointPos, Config::ArgumentSize numberOfPassiveArguments, char *byteData)
Load the expression data and evaluate the expression.
Definition primalValueBaseTape.hpp:1669
typename Base::template ExtractExpr< pos > ExtractExpr
See StatementCallGeneratorBase.
Definition primalValueBaseTape.hpp:1647
typename Base::StaticRhs StaticRhs
See StatementCallGeneratorBase.
Definition primalValueBaseTape.hpp:1644
StatementCallGeneratorBase< Stmt, StatementCallGenerator< StatementCall::Reverse, Stmt > > Base
Base class abbreviation.
Definition primalValueBaseTape.hpp:1643
inlinestatic void evaluate(WriteInfo &writeInfo, Real *primalVector, Config::ArgumentSize numberOfPassiveArguments, char *byteData)
Evaluate the full expression.
Definition primalValueBaseTape.hpp:1424
inlinestatic void evaluateFull(Func const &func, Args &&... args)
Load the expression data and evaluate the expression.
Definition primalValueBaseTape.hpp:1419
inlinestatic void evaluateInner(size_t const &maxOutputArgs, size_t const &maxActiveArgs, size_t const &maxConstantArgs, WriteInfo &writeInfo, Real *primalVector, Config::ArgumentSize numberOfPassiveArguments, char *byteData)
Evaluate expression in a forward mode.
Definition primalValueBaseTape.hpp:1386
StatementCallGeneratorBase< Stmt, StatementCallGenerator< StatementCall::WriteInformation, Stmt > > Base
Base class abbreviation.
Definition primalValueBaseTape.hpp:1382
typename Base::StaticRhs StaticRhs
See StatementCallGeneratorBase.
Definition primalValueBaseTape.hpp:1383
This structure is accessed by the StatementEvaluatorInterface.
Definition primalValueBaseTape.hpp:1369
Definition of the data for a statement. The pointers a populated from a byte data stream.
Definition primalValueBaseTape.hpp:306
inlinevoid populate(size_t lhsSize, size_t rhsSize, size_t passiveSize, size_t constantSize, char *byteData)
Set all the pointer from the given byte data. The sizes are used to compute the offsets.
Definition primalValueBaseTape.hpp:322
Real * passiveValues
Array for the passive values of a statement.
Definition primalValueBaseTape.hpp:309
inlineConfig::LowLevelFunctionDataSize computeSize(size_t lhsSize, size_t rhsSize, size_t passiveSize, size_t constantSize)
Computes the byte size for the data of the statement.
Definition primalValueBaseTape.hpp:347
PassiveReal * constantValues
Array for the constant values in the statement.
Definition primalValueBaseTape.hpp:311
Identifier * rhsIdentifiers
Array for the rhs identifiers.
Definition primalValueBaseTape.hpp:307
inlinevoid push(T *&array, T const &value)
Definition primalValueBaseTape.hpp:316
Real * oldLhsValues
Array for the old values of the lhs values.
Definition primalValueBaseTape.hpp:310
Identifier * lhsIdentifiers
Array for the lhs identifiers.
Definition primalValueBaseTape.hpp:308
Additional wrapper that triggers compiler optimizations.
Definition primalValueBaseTape.hpp:808
Wrapper helper for improved compiler optimizations.
Definition primalValueBaseTape.hpp:1291
Additional wrapper that triggers compiler optimizations.
Definition primalValueBaseTape.hpp:862
Base class for all standard Primal value tape implementations.
Definition primalValueBaseTape.hpp:131
MemberStore< IndexManager, Impl, TapeTypes::IsStaticIndexHandler > indexManager
Definition primalValueBaseTape.hpp:179
inlineGradient * getInternalAdjoints()
Obtain a representation of the tape's internal adjoint vector that can be used as custom adjoints.
Definition primalValueBaseTape.hpp:914
std::vector< Real > primalsCopy
Definition primalValueBaseTape.hpp:185
typename TapeTypes::EvalHandle EvalHandle
See PrimalValueTapeTypes.
Definition primalValueBaseTape.hpp:150
inlineConfig::LowLevelFunctionDataSize reserveStmtDataManual(size_t lhsSize, size_t rhsSize, size_t passiveSize, size_t constantSize, StatementDataPointers &pointers)
Reserve all the data for a statement.
Definition primalValueBaseTape.hpp:368
static bool constexpr RequiresPrimalRestore
Definition primalValueBaseTape.hpp:168
void beginUseAdjointVector()
Declare that the adjoint vector is being used. See Adjoint vector management.
Definition primalValueBaseTape.hpp:950
inlineReal 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:664
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 primalValueBaseTape.hpp:590
inlinevoid evaluateForward(Position const &start, Position const &end, AdjointVector &&data)
Perform a forward evaluation of a part of the tape. It has to hold start <= end.
Definition primalValueBaseTape.hpp:909
inlinevoid registerInput(LhsExpressionInterface< Real, Gradient, Impl, Lhs > &value)
Definition primalValueBaseTape.hpp:697
PrimalValueBaseTape()
Constructor.
Definition primalValueBaseTape.hpp:228
inlinebool storeArgumentAndStmtData(ExpressionInterface< RhsType, Rhs > const &rhs, StatementDataPointers &pointers)
Definition primalValueBaseTape.hpp:450
Gradient * selectAdjointVector(VectorAccess< AdjointVector > *vectorAccess, AdjointVector data)
Select the configured adjoint vector, see codi::Config::VariableAdjointInterfaceInPrimalTapes.
Definition primalValueBaseTape.hpp:773
T_Impl Impl
See PrimalValueBaseTape.
Definition primalValueBaseTape.hpp:139
void deleteAdjointVector()
Delete the adjoint vector. See Adjoint vector management.
Definition primalValueBaseTape.hpp:939
Real registerExternalFunctionOutput(LhsExpressionInterface< Real, Gradient, Impl, Lhs > &value)
Definition primalValueBaseTape.hpp:1034
StatementByteData statementByteData
Definition primalValueBaseTape.hpp:181
Real const & primal(Identifier const &identifier) const
Read only reference to primal value.
Definition primalValueBaseTape.hpp:1323
static bool constexpr HasPrimalValues
Definition primalValueBaseTape.hpp:165
CommonTapeImplementation< T_TapeTypes, T_Impl > Base
Base class abbreviation.
Definition primalValueBaseTape.hpp:141
typename TapeTypes::StatementEvaluator StatementEvaluator
See PrimalValueTapeTypes.
Definition primalValueBaseTape.hpp:147
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 primalValueBaseTape.hpp:1276
inlinevoid destroyIdentifier(Real &value, Identifier &identifier)
Has to be called for each identifier, before it is deallocated.
Definition primalValueBaseTape.hpp:297
inlinevoid store(AggregatedActiveType< Aggregated, Type, Lhs > &lhs, ExpressionInterface< Aggregated, Rhs > const &rhs)
Definition primalValueBaseTape.hpp:505
inlinevoid resetTo(Position const &pos, bool resetAdjoints=true, AdjointsManagement adjointsManagement=AdjointsManagement::Automatic)
Reset the tape to the provided position.
Definition primalValueBaseTape.hpp:1224
std::vector< Real > primals
Definition primalValueBaseTape.hpp:184
typename TapeTypes::Real Real
See TapeTypesInterface.
Definition primalValueBaseTape.hpp:144
static void internalEvaluateReverse_EvalStatements(Args &&... args)
Perform a reverse evaluation of the tape. Arguments are from the recursive eval methods of the DataIn...
typename TapeTypes::StatementByteData StatementByteData
See PrimalValueTapeTypes.
Definition primalValueBaseTape.hpp:153
inlinevoid 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 primalValueBaseTape.hpp:903
std::vector< Gradient > adjoints
Definition primalValueBaseTape.hpp:183
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:1263
typename TapeTypes::Identifier Identifier
See PrimalValueTapeTypes.
Definition primalValueBaseTape.hpp:148
inlinevoid clearAdjoints(AdjointsManagement adjointsManagement=AdjointsManagement::Automatic)
Clear all adjoint values, that is, set them to zero.
Definition primalValueBaseTape.hpp:705
inlinevoid initIdentifier(Real &value, Identifier &identifier)
Definition primalValueBaseTape.hpp:289
T_TapeTypes TapeTypes
See PrimalValueBaseTape.
Definition primalValueBaseTape.hpp:135
Identifier * manualPushIdentifiers
Definition primalValueBaseTape.hpp:189
static bool constexpr AllowJacobianOptimization
Definition primalValueBaseTape.hpp:164
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 primalValueBaseTape.hpp:1252
VectorAccess< Adjoint * > * createVectorAccessCustomAdjoints(Adjoint *data)
Definition primalValueBaseTape.hpp:1018
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:1239
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 primalValueBaseTape.hpp:561
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:1048
void deleteVectorAccess(VectorAccessInterface< Real, Identifier > *access)
See Adjoint vector access.
Definition primalValueBaseTape.hpp:1023
void evaluatePrimal(Position const &start, Position const &end)
Perform a full (forward) reevaluation of the primals in the tape.
Definition primalValueBaseTape.hpp:1303
void evaluatePrimal()
Perform a full (forward) reevaluation of the primals in the tape.
Definition commonTapeImplementation.hpp:745
std::array< T, Config::MaxArgumentSize > StackArray
Used for generating arrays for lhs handling.
Definition primalValueBaseTape.hpp:173
void writeTape(codi::TapeWriterInterface< Type > *writer, Position const &start, Position const &end)
For full or partial tapes using a pointer to the writer.
Definition primalValueBaseTape.hpp:1170
static void internalEvaluatePrimal_EvalStatements(Args &&... args)
Perform a primal evaluation of the tape. Arguments are from the recursive eval methods of the DataInt...
inlineGradient & gradient(Identifier const &identifier, AdjointsManagement adjointsManagement=AdjointsManagement::Automatic)
Reference access to gradient.
Definition primalValueBaseTape.hpp:257
void setParameter(TapeParameters parameter, size_t value)
See Parameters functions.
Definition primalValueBaseTape.hpp:981
Real & primal(Identifier const &identifier)
Definition primalValueBaseTape.hpp:1318
VectorAccess< AdjointVector > * createVectorAccessCustomAdjoints(AdjointVector &&data)
Definition primalValueBaseTape.hpp:1011
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
Definition primalValueBaseTape.hpp:166
void internalEvaluateForward(Position const &start, Position const &end, AdjointVector &&data)
Internal method for the forward evaluation of the whole tape.
Definition primalValueBaseTape.hpp:812
void internalResetPrimalValues(Position const &pos)
Reset the primal values to the given position.
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 primalValueBaseTape.hpp:630
inlinevoid pushLowLevelFunction(Config::LowLevelFunctionToken token, size_t size, ByteDataView &data)
Push a low level function to the tape.
Definition primalValueBaseTape.hpp:1194
inlineGradient const & gradient(Identifier const &identifier, AdjointsManagement adjointsManagement=AdjointsManagement::Automatic) const
Constant reference access to gradient.
Definition primalValueBaseTape.hpp:271
inlinevoid internalEvaluateReverse(Position const &start, Position const &end, AdjointVector &&data)
Internal method for the reverse evaluation of the whole tape.
Definition primalValueBaseTape.hpp:866
RealTraits::PassiveReal< Real > PassiveReal
Basic computation type.
Definition primalValueBaseTape.hpp:155
typename Base::Position Position
See TapeTypesInterface.
Definition primalValueBaseTape.hpp:158
typename TapeTypes::Gradient Gradient
See TapeTypesInterface.
Definition primalValueBaseTape.hpp:145
VectorAccess< Gradient * > * createVectorAccess()
See Adjoint vector access.
Definition primalValueBaseTape.hpp:1005
typename StatementData::Position NestedPosition
See PrimalValueTapeTypes.
Definition primalValueBaseTape.hpp:157
void createStatementManual(Config::ArgumentSize const &nOutputValues, Identifier const *const lhsIndices, Real const *const lhsValues, Config::ArgumentSize const &nActiveValues, Identifier const *const rhsIdentifiers, Config::ArgumentSize const &nPassiveValues, Real const *const rhsPrimals, Config::ArgumentSize const &nConstants, Real const *const rhsConstant, EvalHandle const &evalHandle)
Definition primalValueBaseTape.hpp:1121
inlineTapeValues internalGetTapeValues() const
Definition primalValueBaseTape.hpp:732
void resizeAdjointVector()
Explicitly trigger resizing of the adjoint vector. See Adjoint vector management.
Definition primalValueBaseTape.hpp:944
typename TapeTypes::StatementData StatementData
See PrimalValueTapeTypes.
Definition primalValueBaseTape.hpp:152
void endUseAdjointVector()
Declare that the adjoint vector is no longer used. See Adjoint vector management.
Definition primalValueBaseTape.hpp:954
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 primalValueBaseTape.hpp:1210
PrimalAdjointVectorAccess< Real, Identifier, AdjointVector > VectorAccess
Vector access type generated by this tape.
Definition primalValueBaseTape.hpp:162
inlinevoid reset(bool resetAdjoints=true, AdjointsManagement adjointsManagement=AdjointsManagement::Automatic)
Reset the tape to the initial state for a fresh recording.
Definition primalValueBaseTape.hpp:717
void storeManual(Real const &lhsValue, Identifier &lhsIndex, Config::ArgumentSize const &size)
Definition primalValueBaseTape.hpp:1090
inlineConfig::LowLevelFunctionDataSize reserveStmtData(size_t activeArguments, StatementDataPointers &pointers)
Reserve all the data for a statement.
Definition primalValueBaseTape.hpp:386
void pushJacobianManual(Real const &jacobian, Real const &value, Identifier const &index)
Definition primalValueBaseTape.hpp:1065
inlinevoid swap(Impl &other)
Swap all data with an other tape.
Definition primalValueBaseTape.hpp:924
StatementData statementData
Definition primalValueBaseTape.hpp:180
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 primalValueBaseTape.hpp:649
size_t getParameter(TapeParameters parameter) const
See Parameters functions.
Definition primalValueBaseTape.hpp:957
IndexManager & getIndexManager()
Returns a reference to the Index Manager.
Definition primalValueBaseTape.hpp:1184
inlinevoid pushLhsData(Identifier const &index, Real const &oldPrimalValue, StatementDataPointers &pointers)
Add data for a lhs entry to the data streams.
Definition primalValueBaseTape.hpp:359
typename TapeTypes::IndexManager IndexManager
See TapeTypesInterface.
Definition primalValueBaseTape.hpp:146
Type definitions for the primal value tapes.
Definition primalValueBaseTape.hpp:81
T_Gradient Gradient
See PrimalValueTapeTypes.
Definition primalValueBaseTape.hpp:85
T_StatementEvaluator StatementEvaluator
See PrimalValueTapeTypes.
Definition primalValueBaseTape.hpp:87
typename IndexManager::Index Identifier
See IndexManagerInterface.
Definition primalValueBaseTape.hpp:93
Data< StatementByteChunk, StatementData > StatementByteData
Statement byte data vector.
Definition primalValueBaseTape.hpp:107
T_Data< Chunk, Nested > Data
See PrimalValueTapeTypes.
Definition primalValueBaseTape.hpp:90
static constexpr bool IsLinearIndexHandler
True if the index manager is linear.
Definition primalValueBaseTape.hpp:96
RealTraits::PassiveReal< Real > PassiveReal
Basic computation type.
Definition primalValueBaseTape.hpp:94
T_Real Real
See PrimalValueTapeTypes.
Definition primalValueBaseTape.hpp:84
Chunk1< char > StatementByteChunk
Binary data for the statements.
Definition primalValueBaseTape.hpp:106
Data< StatementChunk, IndexManager > StatementData
Statement data vector.
Definition primalValueBaseTape.hpp:104
T_IndexManager IndexManager
See PrimalValueTapeTypes.
Definition primalValueBaseTape.hpp:86
static constexpr bool IsStaticIndexHandler
True if the index manager must be stored statically in the tape.
Definition primalValueBaseTape.hpp:97
typename StatementEvaluator::Handle EvalHandle
Handle type returned by the statement generator.
Definition primalValueBaseTape.hpp:100
Chunk3< Config::ArgumentSize, EvalHandle, Config::LowLevelFunctionDataSize > StatementChunk
Statement chunk contains <argument size, eval handle, data size of statement in bytes>.
Definition primalValueBaseTape.hpp:103
StatementByteData NestedData
See TapeTypesInterface.
Definition primalValueBaseTape.hpp:109
Methods that access inner values of aggregated types that contain CoDiPack active types.
Definition realTraits.hpp:226
Tape side interface for StatementEvaluatorInterface.
Definition statementEvaluatorTapeInterface.hpp:97
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:70
Interface for the definition of tape types.
Definition commonTapeImplementation.hpp:64
Tape information that can be printed in a pretty print format or a table format.
Definition tapeValues.hpp:75
void addUnsignedLongEntry(std::string const &name, unsigned long const &value, LocalReductionOperation operation=LocalReductionOperation::Sum)
Add unsigned long entry.
Definition tapeValues.hpp:163
void addDoubleEntry(std::string const &name, double const &value, LocalReductionOperation operation=LocalReductionOperation::Sum, bool usedMem=false, bool allocatedMem=false)
Add double entry. If it is a memory entry, it should be in bytes.
Definition tapeValues.hpp:137
void addSection(std::string const &name)
Add section. All further entries are added under this section.
Definition tapeValues.hpp:158
The interface used by all the tape writers. The tape writers are used to generate text,...
Definition tapeReaderWriterInterface.hpp:129
virtual void start(Tape &tape)
Destructor.
Definition tapeReaderWriterInterface.hpp:144
virtual void finish()
After all the statements have been written, the finish method finalizes the writing process.
Definition tapeReaderWriterInterface.hpp:178
inlinevoid eval(NodeInterface< Node > const &node, Args &&... args)
Start the evaluation of the logic on the given expression.
Definition traversalLogic.hpp:71
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
This class is used during the writing process of a primal value tape. The WriteInfo is returned by St...
Definition tapeReaderWriterInterface.hpp:69
size_t numberOfActiveArguments
Number of active arguments.
Definition tapeReaderWriterInterface.hpp:71
std::string stmtExpression
Used to generate a .hpp file for reading back a primal value tape.
Definition tapeReaderWriterInterface.hpp:73
size_t numberOfOutputArguments
Number of output arguments.
Definition tapeReaderWriterInterface.hpp:70
std::string mathRepresentation
Definition tapeReaderWriterInterface.hpp:74
size_t numberOfConstantArguments
Number of constant arguments.
Definition tapeReaderWriterInterface.hpp:72