44#include "../expressions/lhsExpressionInterface.hpp"
45#include "../expressions/logic/compileTimeTraversalLogic.hpp"
46#include "../expressions/logic/constructStaticContext.hpp"
47#include "../expressions/logic/helpers/forEachLeafLogic.hpp"
48#include "../expressions/logic/helpers/jacobianComputationLogic.hpp"
49#include "../expressions/logic/helpers/mathStatementGenLogic.hpp"
50#include "../expressions/logic/traversalLogic.hpp"
51#include "../misc/demangleName.hpp"
53#include "../misc/mathUtility.hpp"
54#include "../misc/memberStore.hpp"
55#include "../traits/expressionTraits.hpp"
56#include "commonTapeImplementation.hpp"
57#include "data/chunk.hpp"
58#include "data/chunkedData.hpp"
59#include "indices/indexManagerInterface.hpp"
60#include "misc/primalAdjointVectorAccess.hpp"
61#include "statementEvaluators/statementEvaluatorInterface.hpp"
62#include "statementEvaluators/statementEvaluatorTapeInterface.hpp"
76 template<
typename T_Real,
typename T_Gradient,
typename T_IndexManager,
template<
typename>
class T_StatementEvaluator,
77 template<
typename,
typename>
class T_Data>
86 template<
typename Chunk,
typename Nested>
95 IndexManager::NeedsStaticStorage;
102 typename std::conditional<IsLinearIndexHandler, Chunk2<Config::ArgumentSize, EvalHandle>,
134 template<
typename T_TapeTypes,
typename T_Impl>
150 using Real =
typename TapeTypes::Real;
169 template<
typename Adjo
intVector>
175 TapeTypes::IsLinearIndexHandler;
177 !TapeTypes::IsLinearIndexHandler;
196 return static_cast<Impl const&
>(*this);
200 return static_cast<Impl&
>(*this);
210 template<
typename... Args>
214 template<
typename... Args>
218 template<
typename... Args>
244 checkPrimalSize(
true);
272 checkAdjointSize(identifier);
300 template<
typename Real>
304 identifier = IndexManager::InactiveIndex;
308 template<
typename Real>
324 template<
typename Node>
327 numberOfActiveArguments += 1;
337 template<
typename Node>
340 size_t& curPassiveArgument) {
345 rhsIndex = curPassiveArgument;
347 curPassiveArgument += 1;
355 template<
typename Node>
358 size_t& curPassiveArgument) {
361 using ConversionOperator =
typename Node::template ConversionOperator<PassiveReal>;
378 template<
typename Node,
typename Jacobian>
381 rhsIdentifiers[pos] =
node.getIdentifier();
382 jacobians[pos] = ComputationTraits::adjointConversion<Real>(jacobianExpr);
392 template<
typename Lhs,
typename Rhs>
405 size_t activeArguments = 0;
406 countActiveArguments.
eval(rhs.
cast(), activeArguments);
414 size_t passiveArguments = 0;
417 bool generatedNewIndex =
indexManager.
get().template assignIndex<Impl>(lhs.
cast().getIdentifier());
418 checkPrimalSize(generatedNewIndex);
421 cast().pushStmtData(lhs.
cast().getIdentifier(), passiveArguments, primalEntry,
422 StatementEvaluator::template createHandle<Impl, Impl, Rhs>());
424 primalEntry = rhs.
cast().getValue();
428 std::array<Identifier, MaxActiveArgs> rhsIdentifiers;
429 std::array<Real, MaxActiveArgs> jacobians;
430 getRhsIdentifiersAndJacobians.
eval(rhs.
cast(),
Real(1.0), rhsIdentifiers.data(), jacobians.data());
433 rhs.
cast().getValue(), MaxActiveArgs,
434 rhsIdentifiers.data(), jacobians.data());
443 lhs.
cast().value() = rhs.
cast().getValue();
448 template<
typename Lhs,
typename Rhs>
462 lhs.
cast().value() = rhs.
cast().getValue();
467 template<
typename Lhs>
471 lhs.
cast().value() = rhs;
482 template<
typename Lhs>
485 if (TapeTypes::IsLinearIndexHandler) {
489 bool generatedNewIndex;
491 generatedNewIndex =
indexManager.
get().template assignUnusedIndex<Impl>(value.
cast().getIdentifier());
493 generatedNewIndex =
indexManager.
get().template assignIndex<Impl>(value.
cast().getIdentifier());
495 checkPrimalSize(generatedNewIndex);
498 if (TapeTypes::IsLinearIndexHandler) {
500 StatementEvaluator::template createHandle<Impl, Impl, Lhs>());
503 Real oldValue = primalEntry;
504 primalEntry = value.
cast().value();
515 template<
typename Lhs>
528 for (
size_t i = 0; i < maxSize; i += 1) {
553 if (TapeTypes::IsLinearIndexHandler) {
554 name =
"CoDi Tape Statistics ( PrimalValueLinearTape )";
556 name =
"CoDi Tape Statistics ( PrimalValueReuseTape )";
561 double memoryAdjoints =
static_cast<double>(nAdjoints) *
static_cast<double>(
sizeof(
Gradient));
564 double memoryPrimals =
static_cast<double>(nPrimals) *
static_cast<double>(
sizeof(
Real));
568 values.
addDoubleEntry(
"Memory allocated", memoryAdjoints, TapeValues::LocalReductionOperation::Sum,
true,
true);
572 values.
addDoubleEntry(
"Memory allocated", memoryPrimals, TapeValues::LocalReductionOperation::Sum,
true,
true);
594 template<
typename Adjo
intVector>
598#if CODI_VariableAdjointInterfaceInPrimalTapes
602 "Please enable 'CODI_VariableAdjointInterfaceInPrimalTapes' in order"
603 " to use custom adjoint vectors in the primal value tapes.");
614 template<
typename Node>
620#if CODI_VariableAdjointInterfaceInPrimalTapes
621 adjointVector->updateTangentWithLhs(
node.getIdentifier(), jacobian);
623 lhsTangent += jacobian * adjointVector[
node.getIdentifier()];
633 template<
bool copyPrimal,
typename Adjo
intVector>
637 CODI_T(std::is_same<
typename std::remove_reference<AdjointVector>::type,
Gradient*>::value),
638 "Please enable 'CODI_VariableAdjointInterfaceInPrimalTapes' in order"
639 " to use custom adjoint vectors in the primal value tapes.");
654 cast(), start, end, &vectorAccess, EventHints::EvaluationKind::Forward, EventHints::Endpoint::Begin);
657 Base::llfByteData.evaluateForward(start, end, evalFunc, cast(), primalData, dataVector);
660 EventHints::EvaluationKind::Forward, EventHints::Endpoint::End);
668 template<
typename Node>
674#if CODI_VariableAdjointInterfaceInPrimalTapes
675 adjointVector->updateAdjointWithLhs(
node.getIdentifier(), jacobian);
677 adjointVector[
node.getIdentifier()] += jacobian * lhsAdjoint;
687 template<
bool copyPrimal,
typename Adjo
intVector>
691 CODI_T(std::is_same<
typename std::remove_reference<AdjointVector>::type,
Gradient*>::value),
692 "Please enable 'CODI_VariableAdjointInterfaceInPrimalTapes' in order"
693 " to use custom adjoint vectors in the primal value tapes.");
707 cast(), start, end, &vectorAccess, EventHints::EvaluationKind::Reverse, EventHints::Endpoint::Begin);
710 Base::llfByteData.evaluateReverse(start, end, evalFunc, cast(), primalData, dataVector);
713 EventHints::EvaluationKind::Reverse, EventHints::Endpoint::End);
724 template<
typename Adjo
intVector>
726 internalEvaluateReverse<!TapeTypes::IsLinearIndexHandler>(start, end, std::forward<AdjointVector>(data));
730 template<
typename Adjo
intVector>
732 internalEvaluateForward<!TapeTypes::IsLinearIndexHandler>(start, end, std::forward<AdjointVector>(data));
750 std::swap(
adjoints, other.adjoints);
751 std::swap(
primals, other.primals);
756 checkPrimalSize(
true);
757 other.checkPrimalSize(
true);
817 CODI_EXCEPTION(
"Tried to set a get only option.");
842 template<
typename Adjo
intVector>
849 template<
typename Adjo
int>
865 template<
typename Lhs>
888 cast().evaluateForward(start, end,
adjoints.data());
900 template<
size_t T_size>
904 static size_t constexpr size = T_size;
911 template<
typename Expr,
typename... Args>
914 CODI_EXCEPTION(
"Forward evaluation of jacobian statement not possible.");
918 template<
typename Expr,
typename... Args>
921 CODI_EXCEPTION(
"Primal evaluation of jacobian statement not possible.");
925 template<
typename Expr>
928 size_t& curConstantPos,
PassiveReal const*
const constantValues,
929 size_t& curPassivePos,
Real const*
const passiveValues,
930 size_t& curRhsIdentifiersPos,
Identifier const*
const rhsIdentifiers) {
931 CODI_UNUSED(primalVector, curConstantPos, constantValues);
933 size_t endPos = curRhsIdentifiersPos - numberOfPassiveArguments;
935 bool const lhsZero = evalJacobianReverse(adjointVector, lhsAdjoint, curPassivePos, passiveValues,
936 curRhsIdentifiersPos, rhsIdentifiers, endPos);
939 curPassivePos -= numberOfPassiveArguments;
940 curRhsIdentifiersPos -= numberOfPassiveArguments;
945 template<
typename Expr,
typename... Args>
952 writeInfo.
stmtExpression =
"Impl, typename Impl::template JacobianStatementGenerator<" +
953 std::to_string(
size) +
">, codi::JacobianExpression<" + std::to_string(
size) +
965 template<
typename Expr,
typename... Args>
968 CODI_EXCEPTION(
"Forward evaluation of jacobian statement not possible.");
974 template<
typename Expr,
typename... Args>
977 CODI_EXCEPTION(
"Primal evaluation of jacobian statement not possible.");
983 template<
typename Expr>
985 Gradient lhsAdjoint,
size_t& curConstantPos,
987 size_t& curRhsIdentifiersPos,
989 CODI_UNUSED(primalVector, curConstantPos, constantValues);
991 size_t passivePos =
size;
992 size_t rhsPos = curRhsIdentifiersPos +
size;
993 size_t endPos = curRhsIdentifiersPos;
995 evalJacobianReverse(adjointVector, lhsAdjoint, passivePos, primalVector, rhsPos, rhsIdentifiers, endPos);
1003 size_t& curPassivePos,
Real const*
const passiveValues,
1004 size_t& curRhsIdentifiersPos,
Identifier const*
const rhsIdentifiers,
1005 size_t endRhsIdentifiersPos) {
1006#if CODI_VariableAdjointInterfaceInPrimalTapes
1008 bool const lhsZero = adjointVector->isLhsZero();
1014 while (curRhsIdentifiersPos > endRhsIdentifiersPos) {
1016 curRhsIdentifiersPos -= 1;
1018 Real const& jacobian = passiveValues[curPassivePos];
1019#if CODI_VariableAdjointInterfaceInPrimalTapes
1020 adjointVector->updateAdjointWithLhs(rhsIdentifiers[curRhsIdentifiersPos], jacobian);
1022 adjointVector[rhsIdentifiers[curRhsIdentifiersPos]] += jacobian * lhsAdjoint;
1039 cast().incrementManualPushCounter();
1056 rhsIdentifiers, jacobians);
1075 primalEntry = lhsValue;
1077 cast().initializeManualPushData(lhsValue, lhsIndex, size);
1095 Impl& impl = cast();
1100 if (TapeTypes::IsLinearIndexHandler) {
1111 if (TapeTypes::IsLinearIndexHandler) {
1115 impl.pushStmtData(lhsIndex, nPassiveValues, lhsValue, evalHandle);
1116 impl.initializeManualPushData(lhsValue, lhsIndex, nPassiveValues);
1118 for (
size_t activeCount = 0; activeCount < nActiveValues; activeCount++) {
1121 for (
size_t passiveCount = 0; passiveCount < nPassiveValues; passiveCount++) {
1122 cast().incrementManualPushCounter();
1125 for (
size_t constantCount = 0; constantCount < nConstants; constantCount++) {
1137 template<
typename Type>
1140 Impl& impl = cast();
1141 writer->
start(impl);
1199 cast().internalResetPrimalValues(pos);
1224 template<
typename Adjo
intVector>
1226 internalEvaluateReverse<false>(start, end, std::forward<AdjointVector>(data));
1228 if (!TapeTypes::IsLinearIndexHandler) {
1248 template<
typename Adjo
intVector>
1250 if (!TapeTypes::IsLinearIndexHandler) {
1251 cast().internalResetPrimalValues(end);
1254 internalEvaluateForward<false>(start, end, std::forward<AdjointVector>(data));
1281 EventHints::EvaluationKind::Primal, EventHints::Endpoint::Begin);
1287 EventHints::EvaluationKind::Primal, EventHints::Endpoint::End);
1306 template<
typename Expr>
1308 size_t& curConstantPos,
PassiveReal const*
const constantValues,
1309 size_t& curPassivePos,
Real const*
const passiveValues,
1310 size_t& curRhsIdentifiersPos,
1314 primalVector[curPos] = passiveValues[curPassivePos + curPos];
1319 using StaticRhs =
typename Constructor::ResultType;
1321 StaticRhs staticRhs = Constructor::construct(primalVector, &rhsIdentifiers[curRhsIdentifiersPos],
1322 &constantValues[curConstantPos]);
1341 template<
typename Rhs>
1343 Gradient& lhsTangent,
size_t& curConstantPos,
1344 PassiveReal const*
const constantValues,
size_t& curRhsIdentifiersPos,
1347 using StaticRhs =
typename Constructor::ResultType;
1349 StaticRhs staticsRhs = Constructor::construct(primalVector, &rhsIdentifiers[curRhsIdentifiersPos],
1350 &constantValues[curConstantPos]);
1354 incrementForward.
eval(staticsRhs,
Real(1.0), lhsTangent, adjointVector);
1355 return staticsRhs.getValue();
1359 template<
typename Func>
1361 size_t const& maxConstantArgs,
Real* primalVector,
1364 PassiveReal const*
const constantValues,
size_t& curPassivePos,
1365 Real const*
const passiveValues,
size_t& curRhsIdentifiersPos,
1368 primalVector[curPos] = passiveValues[curPassivePos + curPos];
1371 Real ret = evalInner(primalVector, adjointVector, lhsTangent, curConstantPos, constantValues,
1372 curRhsIdentifiersPos, rhsIdentifiers);
1375 curConstantPos += maxConstantArgs;
1376 curPassivePos += numberOfPassiveArguments;
1377 curRhsIdentifiersPos += maxActiveArgs;
1383 template<
typename Rhs>
1385 PassiveReal const*
const constantValues,
size_t& curRhsIdentifiersPos,
1388 using StaticRhs =
typename Constructor::ResultType;
1390 StaticRhs staticsRhs = Constructor::construct(primalVector, &rhsIdentifiers[curRhsIdentifiersPos],
1391 &constantValues[curConstantPos]);
1393 return staticsRhs.getValue();
1397 template<
typename Func>
1399 size_t const& maxConstantArgs,
Real* primalVector,
1401 PassiveReal const*
const constantValues,
size_t& curPassivePos,
1402 Real const*
const passiveValues,
size_t& curRhsIdentifiersPos,
1405 primalVector[curPos] = passiveValues[curPassivePos + curPos];
1408 Real ret = evalInner(primalVector, curConstantPos, constantValues, curRhsIdentifiersPos, rhsIdentifiers);
1411 curConstantPos += maxConstantArgs;
1412 curPassivePos += numberOfPassiveArguments;
1413 curRhsIdentifiersPos += maxActiveArgs;
1419 template<
typename Rhs>
1421 Gradient lhsAdjoint,
size_t& curConstantPos,
1423 size_t& curRhsIdentifiersPos,
1426 using StaticRhs =
typename Constructor::ResultType;
1428 StaticRhs staticsRhs = Constructor::construct(primalVector, &rhsIdentifiers[curRhsIdentifiersPos],
1429 &constantValues[curConstantPos]);
1433 incrementReverse.
eval(staticsRhs,
Real(1.0),
const_cast<Gradient const&
>(lhsAdjoint), adjointVector);
1437 template<
typename Func>
1439 Func
const& evalInner,
size_t const& maxActiveArgs,
size_t const& maxConstantArgs,
Real* primalVector,
1441 size_t& curConstantPos,
PassiveReal const*
const constantValues,
size_t& curPassivePos,
1442 Real const*
const passiveValues,
size_t& curRhsIdentifiersPos,
Identifier const*
const rhsIdentifiers) {
1444 curConstantPos -= maxConstantArgs;
1445 curPassivePos -= numberOfPassiveArguments;
1446 curRhsIdentifiersPos -= maxActiveArgs;
1448#if CODI_VariableAdjointInterfaceInPrimalTapes
1454 primalVector[curPos] = passiveValues[curPassivePos + curPos];
1457 evalInner(primalVector, adjointVector, lhsAdjoint, curConstantPos, constantValues, curRhsIdentifiersPos,
1468 template<
typename Rhs>
1471 PassiveReal const*
const constantValues,
size_t& curPassivePos,
1472 Real const*
const passiveValues,
size_t& curRhsIdentifiersPos,
1478 primalVector, adjointVector, lhsTangent, numberOfPassiveArguments,
1479 curConstantPos, constantValues, curPassivePos, passiveValues,
1480 curRhsIdentifiersPos, rhsIdentifiers);
1484 template<
typename Rhs>
1486 size_t& curConstantPos,
PassiveReal const*
const constantValues,
1487 size_t& curPassivePos,
Real const*
const passiveValues,
1488 size_t& curRhsIdentifiersPos,
Identifier const*
const rhsIdentifiers) {
1493 primalVector, numberOfPassiveArguments, curConstantPos, constantValues,
1494 curPassivePos, passiveValues, curRhsIdentifiersPos, rhsIdentifiers);
1498 template<
typename Rhs>
1502 size_t& curConstantPos,
PassiveReal const*
const constantValues,
1503 size_t& curPassivePos,
Real const*
const passiveValues,
1504 size_t& curRhsIdentifiersPos,
1509 adjointVector, lhsAdjoint, numberOfPassiveArguments, curConstantPos,
1510 constantValues, curPassivePos, passiveValues, curRhsIdentifiersPos,
1516 CODI_INLINE void checkAdjointSize(Identifier
const& identifier) {
1517 if (identifier >= (Identifier)
adjoints.size()) {
1518 resizeAdjointsVector();
1522 CODI_INLINE void checkPrimalSize(
bool generatedNewIndex) {
1524 resizePrimalVector();
1540 template<
size_t size>
1544 template<
size_t size>
1546 static size_t constexpr value = size;
1550 template<
size_t size>
1552 static size_t constexpr value = 0;
1555#define CREATE_EXPRESSION(size) \
1556 TapeTypes::StatementEvaluator::template createHandle<Impl, typename Impl::template JacobianStatementGenerator<size>, \
1557 JacobianExpression<size>>()
1560 template<
typename TapeTypes,
typename Impl>
1561 const CODI_DD(
typename TapeTypes::EvalHandle,
1563 CREATE_EXPRESSION(0), CREATE_EXPRESSION(1), CREATE_EXPRESSION(2), CREATE_EXPRESSION(3),
1564 CREATE_EXPRESSION(4), CREATE_EXPRESSION(5), CREATE_EXPRESSION(6), CREATE_EXPRESSION(7),
1565 CREATE_EXPRESSION(8), CREATE_EXPRESSION(9), CREATE_EXPRESSION(10), CREATE_EXPRESSION(11),
1566 CREATE_EXPRESSION(12), CREATE_EXPRESSION(13), CREATE_EXPRESSION(14), CREATE_EXPRESSION(15),
1567 CREATE_EXPRESSION(16), CREATE_EXPRESSION(17), CREATE_EXPRESSION(18), CREATE_EXPRESSION(19),
1568 CREATE_EXPRESSION(20), CREATE_EXPRESSION(21), CREATE_EXPRESSION(22), CREATE_EXPRESSION(23),
1569 CREATE_EXPRESSION(24), CREATE_EXPRESSION(25), CREATE_EXPRESSION(26), CREATE_EXPRESSION(27),
1570 CREATE_EXPRESSION(28), CREATE_EXPRESSION(29), CREATE_EXPRESSION(30), CREATE_EXPRESSION(31),
1571 CREATE_EXPRESSION(32), CREATE_EXPRESSION(33), CREATE_EXPRESSION(34), CREATE_EXPRESSION(35),
1572 CREATE_EXPRESSION(36), CREATE_EXPRESSION(37), CREATE_EXPRESSION(38), CREATE_EXPRESSION(39),
1573 CREATE_EXPRESSION(40), CREATE_EXPRESSION(41), CREATE_EXPRESSION(42), CREATE_EXPRESSION(43),
1574 CREATE_EXPRESSION(44), CREATE_EXPRESSION(45), CREATE_EXPRESSION(46), CREATE_EXPRESSION(47),
1575 CREATE_EXPRESSION(48), CREATE_EXPRESSION(49), CREATE_EXPRESSION(50), CREATE_EXPRESSION(51),
1576 CREATE_EXPRESSION(52), CREATE_EXPRESSION(53), CREATE_EXPRESSION(54), CREATE_EXPRESSION(55),
1577 CREATE_EXPRESSION(56), CREATE_EXPRESSION(57), CREATE_EXPRESSION(58), CREATE_EXPRESSION(59),
1578 CREATE_EXPRESSION(60), CREATE_EXPRESSION(61), CREATE_EXPRESSION(62), CREATE_EXPRESSION(63),
1579 CREATE_EXPRESSION(64), CREATE_EXPRESSION(65), CREATE_EXPRESSION(66), CREATE_EXPRESSION(67),
1580 CREATE_EXPRESSION(68), CREATE_EXPRESSION(69), CREATE_EXPRESSION(70), CREATE_EXPRESSION(71),
1581 CREATE_EXPRESSION(72), CREATE_EXPRESSION(73), CREATE_EXPRESSION(74), CREATE_EXPRESSION(75),
1582 CREATE_EXPRESSION(76), CREATE_EXPRESSION(77), CREATE_EXPRESSION(78), CREATE_EXPRESSION(79),
1583 CREATE_EXPRESSION(80), CREATE_EXPRESSION(81), CREATE_EXPRESSION(82), CREATE_EXPRESSION(83),
1584 CREATE_EXPRESSION(84), CREATE_EXPRESSION(85), CREATE_EXPRESSION(86), CREATE_EXPRESSION(87),
1585 CREATE_EXPRESSION(88), CREATE_EXPRESSION(89), CREATE_EXPRESSION(90), CREATE_EXPRESSION(91),
1586 CREATE_EXPRESSION(92), CREATE_EXPRESSION(93), CREATE_EXPRESSION(94), CREATE_EXPRESSION(95),
1587 CREATE_EXPRESSION(96), CREATE_EXPRESSION(97), CREATE_EXPRESSION(98), CREATE_EXPRESSION(99),
1588 CREATE_EXPRESSION(100), CREATE_EXPRESSION(101), CREATE_EXPRESSION(102), CREATE_EXPRESSION(103),
1589 CREATE_EXPRESSION(104), CREATE_EXPRESSION(105), CREATE_EXPRESSION(106), CREATE_EXPRESSION(107),
1590 CREATE_EXPRESSION(108), CREATE_EXPRESSION(109), CREATE_EXPRESSION(110), CREATE_EXPRESSION(111),
1591 CREATE_EXPRESSION(112), CREATE_EXPRESSION(113), CREATE_EXPRESSION(114), CREATE_EXPRESSION(115),
1592 CREATE_EXPRESSION(116), CREATE_EXPRESSION(117), CREATE_EXPRESSION(118), CREATE_EXPRESSION(119),
1593 CREATE_EXPRESSION(120), CREATE_EXPRESSION(121), CREATE_EXPRESSION(122), CREATE_EXPRESSION(123),
1594 CREATE_EXPRESSION(124), CREATE_EXPRESSION(125), CREATE_EXPRESSION(126), CREATE_EXPRESSION(127),
1595 CREATE_EXPRESSION(128), CREATE_EXPRESSION(129), CREATE_EXPRESSION(130), CREATE_EXPRESSION(131),
1596 CREATE_EXPRESSION(132), CREATE_EXPRESSION(133), CREATE_EXPRESSION(134), CREATE_EXPRESSION(135),
1597 CREATE_EXPRESSION(136), CREATE_EXPRESSION(137), CREATE_EXPRESSION(138), CREATE_EXPRESSION(139),
1598 CREATE_EXPRESSION(140), CREATE_EXPRESSION(141), CREATE_EXPRESSION(142), CREATE_EXPRESSION(143),
1599 CREATE_EXPRESSION(144), CREATE_EXPRESSION(145), CREATE_EXPRESSION(146), CREATE_EXPRESSION(147),
1600 CREATE_EXPRESSION(148), CREATE_EXPRESSION(149), CREATE_EXPRESSION(150), CREATE_EXPRESSION(151),
1601 CREATE_EXPRESSION(152), CREATE_EXPRESSION(153), CREATE_EXPRESSION(154), CREATE_EXPRESSION(155),
1602 CREATE_EXPRESSION(156), CREATE_EXPRESSION(157), CREATE_EXPRESSION(158), CREATE_EXPRESSION(159),
1603 CREATE_EXPRESSION(160), CREATE_EXPRESSION(161), CREATE_EXPRESSION(162), CREATE_EXPRESSION(163),
1604 CREATE_EXPRESSION(164), CREATE_EXPRESSION(165), CREATE_EXPRESSION(166), CREATE_EXPRESSION(167),
1605 CREATE_EXPRESSION(168), CREATE_EXPRESSION(169), CREATE_EXPRESSION(170), CREATE_EXPRESSION(171),
1606 CREATE_EXPRESSION(172), CREATE_EXPRESSION(173), CREATE_EXPRESSION(174), CREATE_EXPRESSION(175),
1607 CREATE_EXPRESSION(176), CREATE_EXPRESSION(177), CREATE_EXPRESSION(178), CREATE_EXPRESSION(179),
1608 CREATE_EXPRESSION(180), CREATE_EXPRESSION(181), CREATE_EXPRESSION(182), CREATE_EXPRESSION(183),
1609 CREATE_EXPRESSION(184), CREATE_EXPRESSION(185), CREATE_EXPRESSION(186), CREATE_EXPRESSION(187),
1610 CREATE_EXPRESSION(188), CREATE_EXPRESSION(189), CREATE_EXPRESSION(190), CREATE_EXPRESSION(191),
1611 CREATE_EXPRESSION(192), CREATE_EXPRESSION(193), CREATE_EXPRESSION(194), CREATE_EXPRESSION(195),
1612 CREATE_EXPRESSION(196), CREATE_EXPRESSION(197), CREATE_EXPRESSION(198), CREATE_EXPRESSION(199),
1613 CREATE_EXPRESSION(200), CREATE_EXPRESSION(201), CREATE_EXPRESSION(202), CREATE_EXPRESSION(203),
1614 CREATE_EXPRESSION(204), CREATE_EXPRESSION(205), CREATE_EXPRESSION(206), CREATE_EXPRESSION(207),
1615 CREATE_EXPRESSION(208), CREATE_EXPRESSION(209), CREATE_EXPRESSION(210), CREATE_EXPRESSION(211),
1616 CREATE_EXPRESSION(212), CREATE_EXPRESSION(213), CREATE_EXPRESSION(214), CREATE_EXPRESSION(215),
1617 CREATE_EXPRESSION(216), CREATE_EXPRESSION(217), CREATE_EXPRESSION(218), CREATE_EXPRESSION(219),
1618 CREATE_EXPRESSION(220), CREATE_EXPRESSION(221), CREATE_EXPRESSION(222), CREATE_EXPRESSION(223),
1619 CREATE_EXPRESSION(224), CREATE_EXPRESSION(225), CREATE_EXPRESSION(226), CREATE_EXPRESSION(227),
1620 CREATE_EXPRESSION(228), CREATE_EXPRESSION(229), CREATE_EXPRESSION(230), CREATE_EXPRESSION(231),
1621 CREATE_EXPRESSION(232), CREATE_EXPRESSION(233), CREATE_EXPRESSION(234), CREATE_EXPRESSION(235),
1622 CREATE_EXPRESSION(236), CREATE_EXPRESSION(237), CREATE_EXPRESSION(238), CREATE_EXPRESSION(239),
1623 CREATE_EXPRESSION(240), CREATE_EXPRESSION(241), CREATE_EXPRESSION(242), CREATE_EXPRESSION(243),
1624 CREATE_EXPRESSION(244), CREATE_EXPRESSION(245), CREATE_EXPRESSION(246), CREATE_EXPRESSION(247),
1625 CREATE_EXPRESSION(248), CREATE_EXPRESSION(249), CREATE_EXPRESSION(250), CREATE_EXPRESSION(251),
1626 CREATE_EXPRESSION(252)};
1628#undef CREATE_EXPRESSION
#define CODI_Unlikely
Declare unlikely evaluation of an execution path.
Definition config.h:399
#define CODI_NO_INLINE
See codi::Config::AvoidedInlines.
Definition config.h:417
#define CODI_INLINE
See codi::Config::ForcedInlines.
Definition config.h:457
#define ADJOINT_VECTOR_TYPE
See codi::Config::VariableAdjointInterfaceInPrimalTapes.
Definition config.h:277
#define CODI_Likely
Declare likely evaluation of an execution path.
Definition config.h:397
#define codiAssert(x)
See codi::Config::EnableAssert.
Definition config.h:432
#define CODI_DD(Type, Default)
Abbreviation for CODI_DECLARE_DEFAULT.
Definition macros.hpp:94
#define CODI_ENABLE_CHECK(option, condition)
Definition macros.hpp:53
#define CODI_WRAP_FUNCTION(NAME, FUNC)
Wrap a function in a function object. Used for performance optimizations.
Definition macros.hpp:156
#define CODI_ANY
Used in default declarations of expression templates.
Definition macros.hpp:98
#define CODI_STATIC_ASSERT(cond, message)
Static assert in CoDiPack.
Definition macros.hpp:123
#define CODI_T(...)
Abbreviation for CODI_TEMPLATE.
Definition macros.hpp:111
uint16_t LowLevelFunctionToken
Token type for low level functions in the tapes.
Definition config.h:108
const bool CheckEmptyStatements
Tapes push statements only if at least one Jacobian was pushed.
Definition config.h:154
size_t constexpr ChunkSize
Default size of chunks (ChunkBase) used in ChunkedData in reverse tape implementations.
Definition config.h:94
bool constexpr CheckZeroIndex
Ignore active types that are not dependent on any input value in Jacobian tapes.
Definition config.h:178
bool constexpr IgnoreInvalidJacobians
Ignore invalid Jacobians like NaN or Inf.
Definition config.h:240
bool constexpr CheckTapeActivity
Makes it possible to ignore certain code parts. If turned of everything will be recorded.
Definition config.h:170
size_t constexpr StatementLowLevelFunctionTag
Statement tag for low level functions.
Definition config.h:126
size_t constexpr MaxArgumentSize
Maximum number of arguments in a statement.
Definition config.h:120
bool constexpr StatementEvents
Enable statement events. Disabled by default.
Definition config.h:319
bool constexpr CopyOptimization
Do not store copy statements like a = b; if the identity handler allows it.
Definition config.h:186
bool constexpr VariableAdjointInterfaceInPrimalTapes
Allow custom adjoint vector in primal values tapes.
Definition config.h:272
uint8_t ArgumentSize
Type for the number of arguments in statements.
Definition config.h:117
size_t constexpr StatementInputTag
Tag for statements that are inputs. Used in linear index management context.
Definition config.h:123
bool constexpr SkipZeroAdjointEvaluation
Do not perform a reverse evaluation of a statement if the seeding adjoint is zero.
Definition config.h:256
bool isTotalFinite(Type const &v)
Function for checking if all values of the type are finite.
Definition realTraits.hpp:133
typename TraitsImplementation< Type >::PassiveReal PassiveReal
The original computation type, that was used in the application.
Definition realTraits.hpp:117
bool isTotalZero(Type const &v)
Function for checking if the value of the type is completely zero.
Definition realTraits.hpp:139
CoDiPack - Code Differentiation Package.
Definition codi.hpp:91
void CODI_UNUSED(Args const &...)
Disable unused warnings for an arbitrary number of arguments.
Definition macros.hpp:46
IntegralType getNextMultiple(IntegralType const &targetSize, IntegralType const &chunkSize)
Helper function for overallocation in multiples of a given chunk size.
Definition mathUtility.hpp:49
TapeParameters
Configuration options for a tape.
Definition tapeParameters.hpp:52
@ PassiveValuesSize
[A: RW] Allocated number of entries in the passive value vector in primal value tapes.
@ LargestIdentifier
[A: R] Largest identifier distributed by the index manger.
@ PrimalSize
[A: RW] Number of primal vector entries in primal value tapes.
@ StatementSize
[A: RW] Allocated number of entries in the statement vector in all tapes.
AdjointsManagement
Policies for management of the tape's interal adjoints.
Definition tapeParameters.hpp:98
@ Automatic
Manage internal adjoints automatically, including locking, bounds checking, and resizing.
Definition byteDataView.hpp:51
Data is stored chunk-wise in this DataInterface implementation. If a chunk runs out of space,...
Definition chunkedData.hpp:64
Implementation of all common tape functionality.
Definition commonTapeImplementation.hpp:131
Real manualPushLhsValue
For storeManual, remember the value assigned to the lhs.
Definition commonTapeImplementation.hpp:158
void setParameter(TapeParameters parameter, size_t value)
See Parameters functions.
Definition commonTapeImplementation.hpp:459
void evaluateForward(AdjointsManagement adjointsManagement=AdjointsManagement::Automatic)
Perform a forward evaluation of a part of the tape. It has to hold start <= end.
Definition commonTapeImplementation.hpp:592
size_t manualPushCounter
Count the pushes after storeManual, to identify the last push.
Definition commonTapeImplementation.hpp:161
Identifier manualPushLhsIdentifier
For storeManual, remember the identifier assigned to the lhs.
Definition commonTapeImplementation.hpp:159
bool isActive() const
Check if the tape is recording.
Definition commonTapeImplementation.hpp:320
size_t manualPushGoal
Store the number of expected pushes after a storeManual call.
Definition commonTapeImplementation.hpp:160
void init(typename ImplTapeTypes::NestedData *nested)
Initialize the base class.
Definition commonTapeImplementation.hpp:751
void reset(bool resetAdjoints=true, AdjointsManagement adjointsManagement=AdjointsManagement::Automatic)
Reset the tape to the initial state for a fresh recording.
Definition commonTapeImplementation.hpp:355
std::set< TapeParameters > options
All options.
Definition commonTapeImplementation.hpp:153
void writeTape(std::unique_ptr< TapeWriterInterface< Type > > writer)
For full-tape writers using a smart pointer.
Definition commonTapeImplementation.hpp:605
void evaluate(AdjointsManagement adjointsManagement=AdjointsManagement::Automatic)
Perform a full reverse evaluation of the tape.
Definition commonTapeImplementation.hpp:293
void swap(Impl &other)
Swap all data with an other tape.
Definition commonTapeImplementation.hpp:368
typename CommonTapeTypes< ImplTapeTypes >::Position Position
See TapeTypesInterface.
Definition commonTapeImplementation.hpp:145
LowLevelFunctionByteData llfByteData
Byte data for low level functions.
Definition commonTapeImplementation.hpp:156
void resetTo(Position const &pos, bool resetAdjoints=true, AdjointsManagement adjointsManagement=AdjointsManagement::Automatic)
Reset the tape to the provided position.
Definition commonTapeImplementation.hpp:704
size_t getParameter(TapeParameters parameter) const
See Parameters functions.
Definition commonTapeImplementation.hpp:431
void evaluatePrimal()
Perform a full (forward) reevaluation of the primals in the tape.
Definition commonTapeImplementation.hpp:726
void internalStoreLowLevelFunction(Config::LowLevelFunctionToken token, size_t size, ByteDataView &dataView)
Called by the implementing tapes to store a low level function. The size is reserved and allocated....
Definition commonTapeImplementation.hpp:494
Helper class for the construction of an expression in a different context.
Definition constructStaticContext.hpp:70
Data stream interface for tape data. Encapsulates data that is written e.g. for each statement or arg...
Definition dataInterface.hpp:149
static void notifyStatementStoreOnTapeListeners(Tape &tape, Identifier const &lhsIdentifier, Real const &newValue, size_t numActiveVariables, Identifier const *rhsIdentifiers, Real const *jacobians)
Invoke callbacks for StatementStoreOnTape events.
Definition eventSystem.hpp:676
static void notifyTapeEvaluateListeners(Tape &tape, Position const &start, Position const &end, VectorAccess *adjoint, EventHints::EvaluationKind evalKind, EventHints::Endpoint endpoint)
Invoke callbacks for TapeEvaluate events.
Definition eventSystem.hpp:486
static void notifyTapeRegisterInputListeners(Tape &tape, Real &value, Identifier &identifier)
Invoke callbacks for TapeRegisterInput events.
Definition eventSystem.hpp:424
Base class for all CoDiPack expressions.
Definition expressionInterface.hpp:59
Impl const & cast() const
Cast to the implementation.
Definition expressionInterface.hpp:75
Counts the number of nodes that inherit from LhsExpressionInterface in the expression.
Definition expressionTraits.hpp:184
Counts the number of types that inherit from ConstantExpression in the expression.
Definition expressionTraits.hpp:210
Implement logic for leaf nodes only.
Definition forEachLeafLogic.hpp:60
Indices enable the mapping of primal values to their adjoint counterparts.
Definition indexManagerInterface.hpp:78
Definition jacobianComputationLogic.hpp:53
Specialized for NumberOfActiveTypeArguments and NumberOfConstantTypeArguments.
Definition primalValueBaseTape.hpp:1541
Default implementation of the Jacobian interface.
Definition jacobian.hpp:60
Base class for all CoDiPack lvalue expression.
Definition lhsExpressionInterface.hpp:63
Impl & cast()
Cast to the implementation.
Definition lhsExpressionInterface.hpp:99
Creates a math representation from a given rhs in the form of a string.
Definition mathStatementGenLogic.hpp:56
void eval(NodeInterface< Node > const &node, std::string &mathRep)
Produces a math representation string for a given statement.
Definition mathStatementGenLogic.hpp:65
Defines a member that can either be static or local to the struct.
Definition memberStore.hpp:56
Type & get()
Get a reference to the actual member.
Definition memberStore.hpp:76
Implementation of VectorAccessInterface for adjoint and primal vectors.
Definition primalAdjointVectorAccess.hpp:59
Count all arguments that have non-zero index.
Definition primalValueBaseTape.hpp:320
void handleActive(Node const &node, size_t &numberOfActiveArguments)
Called for leaf nodes which implement LhsExpressionInterface.
Definition primalValueBaseTape.hpp:325
Perform the adjoint update based on the configuration in codi::Config::VariableAdjointInterfaceInPrim...
Definition primalValueBaseTape.hpp:610
void handleJacobianOnActive(Node const &node, Real jacobian, Gradient &lhsTangent, Gradient *adjointVector)
Called for leaf nodes which implement LhsExpressionInterface.
Definition primalValueBaseTape.hpp:615
Perform the adjoint update based on the configuration in codi::Config::VariableAdjointInterfaceInPrim...
Definition primalValueBaseTape.hpp:664
void handleJacobianOnActive(Node const &node, Real jacobian, Gradient const &lhsAdjoint, Gradient *adjointVector)
See IncrementReversalLogic.
Definition primalValueBaseTape.hpp:669
Definition primalValueBaseTape.hpp:901
static Real statementEvaluatePrimalInner(Args &&... args)
Throws exception.
Definition primalValueBaseTape.hpp:975
static Real statementEvaluateForwardInner(Args &&... args)
Throws exception.
Definition primalValueBaseTape.hpp:966
static Real statementEvaluateForward(Args &&... args)
Throws exception.
Definition primalValueBaseTape.hpp:912
static void statementEvaluateReverseInner(Real *primalVector, Gradient *adjointVector, Gradient lhsAdjoint, size_t &curConstantPos, PassiveReal const *const constantValues, size_t &curRhsIdentifiersPos, Identifier const *const rhsIdentifiers)
Evaluate expression in a reverse mode.
Definition primalValueBaseTape.hpp:984
static size_t constexpr size
See JacobianStatementGenerator.
Definition primalValueBaseTape.hpp:904
static void statementEvaluateReverse(Real *primalVector, Gradient *adjointVector, Gradient lhsAdjoint, Config::ArgumentSize numberOfPassiveArguments, size_t &curConstantPos, PassiveReal const *const constantValues, size_t &curPassivePos, Real const *const passiveValues, size_t &curRhsIdentifiersPos, Identifier const *const rhsIdentifiers)
Evaluate expression in a reverse mode.
Definition primalValueBaseTape.hpp:926
static WriteInfo statementGetWriteInformation(Args &&... args)
Get write information.
Definition primalValueBaseTape.hpp:946
static Real statementEvaluatePrimal(Args &&... args)
Throws exception.
Definition primalValueBaseTape.hpp:919
Push all data for each argument.
Definition primalValueBaseTape.hpp:333
void handleActive(Node const &node, RhsIdentifierData &rhsIdentifierData, PassiveValueData &passiveValueData, ConstantValueData &constantValueData, size_t &curPassiveArgument)
Called for leaf nodes which implement LhsExpressionInterface.
Definition primalValueBaseTape.hpp:338
void handleConstant(Node const &node, RhsIdentifierData &rhsIdentifierData, PassiveValueData &passiveValueData, ConstantValueData &constantValueData, size_t &curPassiveArgument)
Called for leaf nodes which implement ConstantExpression.
Definition primalValueBaseTape.hpp:356
Additional wrapper that triggers compiler optimizations.
Definition primalValueBaseTape.hpp:630
Wrapper helper for improved compiler optimizations.
Definition primalValueBaseTape.hpp:1264
Additional wrapper that triggers compiler optimizations.
Definition primalValueBaseTape.hpp:684
Base class for all standard Primal value tape implementations.
Definition primalValueBaseTape.hpp:137
MemberStore< IndexManager, Impl, TapeTypes::IsStaticIndexHandler > indexManager
Index manager.
Definition primalValueBaseTape.hpp:183
static WriteInfo statementGetWriteInformation(Real *primalVector, Config::ArgumentSize numberOfPassiveArguments, size_t &curConstantPos, PassiveReal const *const constantValues, size_t &curPassivePos, Real const *const passiveValues, size_t &curRhsIdentifiersPos, Identifier const *const rhsIdentifiers)
Get write information.
Definition primalValueBaseTape.hpp:1307
Gradient * getInternalAdjoints()
Obtain a representation of the tape's internal adjoint vector that can be used as custom adjoints.
Definition primalValueBaseTape.hpp:736
typename ConstantValueData::Position NestedPosition
See PrimalValueTapeTypes.
Definition primalValueBaseTape.hpp:165
std::vector< Real > primalsCopy
Copy of primal values for AD evaluations.
Definition primalValueBaseTape.hpp:191
typename TapeTypes::EvalHandle EvalHandle
See PrimalValueTapeTypes.
Definition primalValueBaseTape.hpp:156
static bool constexpr RequiresPrimalRestore
See PrimalEvaluationTapeInterface.
Definition primalValueBaseTape.hpp:176
void beginUseAdjointVector()
Declare that the adjoint vector is being used. See Adjoint vector management.
Definition primalValueBaseTape.hpp:772
void internalEvaluateReverse(Position const &start, Position const &end, AdjointVector &&data)
Internal method for the reverse evaluation of the whole tape.
Definition primalValueBaseTape.hpp:688
static Real statementEvaluateForwardFull(Func const &evalInner, size_t const &maxActiveArgs, size_t const &maxConstantArgs, Real *primalVector, Gradient *adjointVector, Gradient &lhsTangent, Config::ArgumentSize numberOfPassiveArguments, size_t &curConstantPos, PassiveReal const *const constantValues, size_t &curPassivePos, Real const *const passiveValues, size_t &curRhsIdentifiersPos, Identifier const *const rhsIdentifiers)
Load the expression data and evaluate the expression in a forward mode.
Definition primalValueBaseTape.hpp:1360
void resetTo(Position const &pos, bool resetAdjoints=true, AdjointsManagement adjointsManagement=AdjointsManagement::Automatic)
Reset the tape to the provided position.
Definition primalValueBaseTape.hpp:1197
PrimalValueBaseTape()
Constructor.
Definition primalValueBaseTape.hpp:233
void createStatementManual(Identifier const &lhsIndex, Real const &lhsValue, 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:1090
void evaluate(Position const &start, Position const &end, AdjointVector &&data)
Perform a reverse evaluation for a part of the tape. It hast to hold start >= end.
Definition primalValueBaseTape.hpp:725
static void statementEvaluateReverseFull(Func const &evalInner, size_t const &maxActiveArgs, size_t const &maxConstantArgs, Real *primalVector, Gradient *adjointVector, Gradient lhsAdjoint, Config::ArgumentSize numberOfPassiveArguments, size_t &curConstantPos, PassiveReal const *const constantValues, size_t &curPassivePos, Real const *const passiveValues, size_t &curRhsIdentifiersPos, Identifier const *const rhsIdentifiers)
Load the expression data and evaluate the expression in a reverse mode.
Definition primalValueBaseTape.hpp:1438
PassiveValueData passiveValueData
Data stream for passive argument value data.
Definition primalValueBaseTape.hpp:186
Gradient * selectAdjointVector(VectorAccess< AdjointVector > *vectorAccess, AdjointVector data)
Select the configured adjoint vector, see codi::Config::VariableAdjointInterfaceInPrimalTapes.
Definition primalValueBaseTape.hpp:595
T_Impl Impl
See PrimalValueBaseTape.
Definition primalValueBaseTape.hpp:145
static void statementEvaluateReverseInner(Real *primalVector, Gradient *adjointVector, Gradient lhsAdjoint, size_t &curConstantPos, PassiveReal const *const constantValues, size_t &curRhsIdentifiersPos, Identifier const *const rhsIdentifiers)
Evaluate expression in a reverse mode.
Definition primalValueBaseTape.hpp:1420
void registerInput(LhsExpressionInterface< Real, Gradient, Impl, Lhs > &value)
Definition primalValueBaseTape.hpp:516
void deleteAdjointVector()
Delete the adjoint vector. See Adjoint vector management.
Definition primalValueBaseTape.hpp:761
Real registerExternalFunctionOutput(LhsExpressionInterface< Real, Gradient, Impl, Lhs > &value)
Definition primalValueBaseTape.hpp:866
Real const & primal(Identifier const &identifier) const
Read only reference to primal value.
Definition primalValueBaseTape.hpp:1296
static bool constexpr HasPrimalValues
See PrimalEvaluationTapeInterface.
Definition primalValueBaseTape.hpp:173
typename TapeTypes::StatementEvaluator StatementEvaluator
See PrimalValueTapeTypes.
Definition primalValueBaseTape.hpp:153
static Real statementEvaluatePrimalInner(Real *primalVector, size_t &curConstantPos, PassiveReal const *const constantValues, size_t &curRhsIdentifiersPos, Identifier const *const rhsIdentifiers)
Evaluate expression in a primal setting.
Definition primalValueBaseTape.hpp:1384
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:1249
typename TapeTypes::PassiveValueData PassiveValueData
See PrimalValueTapeTypes.
Definition primalValueBaseTape.hpp:160
std::vector< Real > primals
Current state of primal values in the program.
Definition primalValueBaseTape.hpp:190
typename TapeTypes::Real Real
See TapeTypesInterface.
Definition primalValueBaseTape.hpp:150
static void internalEvaluateReverse_EvalStatements(Args &&... args)
Perform a reverse evaluation of the tape. Arguments are from the recursive eval methods of the DataIn...
std::vector< Gradient > adjoints
Evaluation vector for AD.
Definition primalValueBaseTape.hpp:189
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:1236
void evaluate(Position const &start, Position const &end, AdjointsManagement adjointsManagement=AdjointsManagement::Automatic)
Perform a reverse evaluation for a part of the tape. It hast to hold start >= end.
Definition primalValueBaseTape.hpp:1183
static Real statementEvaluateForwardInner(Real *primalVector, Gradient *adjointVector, Gradient &lhsTangent, size_t &curConstantPos, PassiveReal const *const constantValues, size_t &curRhsIdentifiersPos, Identifier const *const rhsIdentifiers)
Evaluate expression in a forward mode.
Definition primalValueBaseTape.hpp:1342
typename TapeTypes::Identifier Identifier
See PrimalValueTapeTypes.
Definition primalValueBaseTape.hpp:154
T_TapeTypes TapeTypes
See PrimalValueBaseTape.
Definition primalValueBaseTape.hpp:141
void pushStmtData(Identifier const &index, Config::ArgumentSize const &numberOfPassiveArguments, Real const &oldPrimalValue, EvalHandle evalHandle)
Add statement specific data to the data streams.
static bool constexpr AllowJacobianOptimization
See InternalStatementRecordingTapeInterface.
Definition primalValueBaseTape.hpp:172
RhsIdentifierData rhsIdentifierData
Data stream for argument identifier data.
Definition primalValueBaseTape.hpp:185
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:1225
VectorAccess< Adjoint * > * createVectorAccessCustomAdjoints(Adjoint *data)
Definition primalValueBaseTape.hpp:850
static void statementEvaluateReverse(Real *primalVector, Gradient *adjointVector, Gradient lhsAdjoint, Config::ArgumentSize numberOfPassiveArguments, size_t &curConstantPos, PassiveReal const *const constantValues, size_t &curPassivePos, Real const *const passiveValues, size_t &curRhsIdentifiersPos, Identifier const *const rhsIdentifiers)
Evaluate expression in a reverse mode.
Definition primalValueBaseTape.hpp:1499
typename TapeTypes::RhsIdentifierData RhsIdentifierData
See PrimalValueTapeTypes.
Definition primalValueBaseTape.hpp:159
Gradient const & gradient(Identifier const &identifier, AdjointsManagement adjointsManagement=AdjointsManagement::Automatic) const
Constant reference access to gradient.
Definition primalValueBaseTape.hpp:283
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:1212
TapeValues internalGetTapeValues() const
Definition primalValueBaseTape.hpp:551
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:880
void initIdentifier(Real &value, Identifier &identifier)
Definition primalValueBaseTape.hpp:301
void deleteVectorAccess(VectorAccessInterface< Real, Identifier > *access)
See Adjoint vector access.
Definition primalValueBaseTape.hpp:855
void evaluatePrimal(Position const &start, Position const &end)
Perform a full (forward) reevaluation of the primals in the tape.
Definition primalValueBaseTape.hpp:1276
void reset(bool resetAdjoints=true, AdjointsManagement adjointsManagement=AdjointsManagement::Automatic)
Reset the tape to the initial state for a fresh recording.
Definition primalValueBaseTape.hpp:536
void store(LhsExpressionInterface< Real, Gradient, Impl, Lhs > &lhs, Real const &rhs)
Has to be called by an AD variable every time it is assigned.
Definition primalValueBaseTape.hpp:468
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:1138
static void internalEvaluatePrimal_EvalStatements(Args &&... args)
Perform a primal evaluation of the tape. Arguments are from the recursive eval methods of the DataInt...
void setParameter(TapeParameters parameter, size_t value)
See Parameters functions.
Definition primalValueBaseTape.hpp:808
Real & primal(Identifier const &identifier)
Writable reference to primal value.
Definition primalValueBaseTape.hpp:1291
VectorAccess< AdjointVector > * createVectorAccessCustomAdjoints(AdjointVector &&data)
Definition primalValueBaseTape.hpp:843
static void internalEvaluateForward_EvalStatements(Args &&... args)
Perform a forward evaluation of the tape. Arguments are from the recursive eval methods of the DataIn...
static bool constexpr LinearIndexHandling
See IdentifierInformationTapeInterface.
Definition primalValueBaseTape.hpp:174
void internalEvaluateForward(Position const &start, Position const &end, AdjointVector &&data)
Internal method for the forward evaluation of the whole tape.
Definition primalValueBaseTape.hpp:634
void internalResetPrimalValues(Position const &pos)
Reset the primal values to the given position.
void swap(Impl &other)
Swap all data with an other tape.
Definition primalValueBaseTape.hpp:746
void store(LhsExpressionInterface< Real, Gradient, Impl, Lhs > &lhs, LhsExpressionInterface< Real, Gradient, Impl, Rhs > const &rhs)
Has to be called by an AD variable every time it is assigned.
Definition primalValueBaseTape.hpp:449
RealTraits::PassiveReal< Real > PassiveReal
Basic computation type.
Definition primalValueBaseTape.hpp:163
typename Base::Position Position
See TapeTypesInterface.
Definition primalValueBaseTape.hpp:166
typename TapeTypes::Gradient Gradient
See TapeTypesInterface.
Definition primalValueBaseTape.hpp:151
VectorAccess< Gradient * > * createVectorAccess()
See Adjoint vector access.
Definition primalValueBaseTape.hpp:837
void store(LhsExpressionInterface< Real, Gradient, Impl, Lhs > &lhs, ExpressionInterface< Real, Rhs > const &rhs)
Has to be called by an AD variable every time it is assigned.
Definition primalValueBaseTape.hpp:393
void resizeAdjointVector()
Explicitly trigger resizing of the adjoint vector. See Adjoint vector management.
Definition primalValueBaseTape.hpp:766
typename TapeTypes::StatementData StatementData
See PrimalValueTapeTypes.
Definition primalValueBaseTape.hpp:158
void endUseAdjointVector()
Declare that the adjoint vector is no longer used. See Adjoint vector management.
Definition primalValueBaseTape.hpp:776
void destroyIdentifier(Real &value, Identifier &identifier)
Has to be called for each identifier, before it is deallocated.
Definition primalValueBaseTape.hpp:309
static Real statementEvaluateForward(Real *primalVector, Gradient *adjointVector, Gradient &lhsTangent, Config::ArgumentSize numberOfPassiveArguments, size_t &curConstantPos, PassiveReal const *const constantValues, size_t &curPassivePos, Real const *const passiveValues, size_t &curRhsIdentifiersPos, Identifier const *const rhsIdentifiers)
Evaluate expression in a forward mode.
Definition primalValueBaseTape.hpp:1469
void 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:731
void clearAdjoints(AdjointsManagement adjointsManagement=AdjointsManagement::Automatic)
Clear all adjoint values, that is, set them to zero.
Definition primalValueBaseTape.hpp:524
static EvalHandle const jacobianExpressions[Config::MaxArgumentSize]
Expressions for manual statement pushes.
Definition primalValueBaseTape.hpp:181
Gradient & gradient(Identifier const &identifier, AdjointsManagement adjointsManagement=AdjointsManagement::Automatic)
Reference access to gradient.
Definition primalValueBaseTape.hpp:269
Real internalRegisterInput(LhsExpressionInterface< Real, Gradient, Impl, Lhs > &value, bool unusedIndex)
Add a new input to the tape and update the primal value vector.
Definition primalValueBaseTape.hpp:483
void storeManual(Real const &lhsValue, Identifier &lhsIndex, Config::ArgumentSize const &size)
Definition primalValueBaseTape.hpp:1062
void pushJacobianManual(Real const &jacobian, Real const &value, Identifier const &index)
Definition primalValueBaseTape.hpp:1036
StatementData statementData
Data stream for statement specific data.
Definition primalValueBaseTape.hpp:184
static Real statementEvaluatePrimal(Real *primalVector, Config::ArgumentSize numberOfPassiveArguments, size_t &curConstantPos, PassiveReal const *const constantValues, size_t &curPassivePos, Real const *const passiveValues, size_t &curRhsIdentifiersPos, Identifier const *const rhsIdentifiers)
Evaluate primal expression.
Definition primalValueBaseTape.hpp:1485
void pushLowLevelFunction(Config::LowLevelFunctionToken token, size_t size, ByteDataView &data)
Push a low level function to the tape.
Definition primalValueBaseTape.hpp:1163
typename TapeTypes::ConstantValueData ConstantValueData
See PrimalValueTapeTypes.
Definition primalValueBaseTape.hpp:161
friend Base
Allow the base class to call protected and private methods.
Definition primalValueBaseTape.hpp:148
size_t getParameter(TapeParameters parameter) const
See Parameters functions.
Definition primalValueBaseTape.hpp:779
IndexManager & getIndexManager()
Returns a reference to the Index Manager.
Definition primalValueBaseTape.hpp:1153
static Real statementEvaluatePrimalFull(Func const &evalInner, size_t const &maxActiveArgs, size_t const &maxConstantArgs, Real *primalVector, Config::ArgumentSize numberOfPassiveArguments, size_t &curConstantPos, PassiveReal const *const constantValues, size_t &curPassivePos, Real const *const passiveValues, size_t &curRhsIdentifiersPos, Identifier const *const rhsIdentifiers)
Load the expression data and evaluate the expression in a primal setting.
Definition primalValueBaseTape.hpp:1398
typename TapeTypes::IndexManager IndexManager
See TapeTypesInterface.
Definition primalValueBaseTape.hpp:152
ConstantValueData constantValueData
Data stream for constant argument data.
Definition primalValueBaseTape.hpp:187
Type definitions for the primal value tapes.
Definition primalValueBaseTape.hpp:78
T_Gradient Gradient
See PrimalValueTapeTypes.
Definition primalValueBaseTape.hpp:82
typename IndexManager::Index Identifier
See IndexManagerInterface.
Definition primalValueBaseTape.hpp:90
Data< PassiveValueChunk, RhsIdentifierData > PassiveValueData
Passive values data vector.
Definition primalValueBaseTape.hpp:110
typename std::conditional< IsLinearIndexHandler, Chunk2< Config::ArgumentSize, EvalHandle >, Chunk4< Identifier, Config::ArgumentSize, Real, EvalHandle > >::type StatementChunk
Definition primalValueBaseTape.hpp:101
T_Data< Chunk, Nested > Data
See PrimalValueTapeTypes.
Definition primalValueBaseTape.hpp:87
static constexpr bool IsLinearIndexHandler
True if the index manager is linear.
Definition primalValueBaseTape.hpp:93
RealTraits::PassiveReal< Real > PassiveReal
Basic computation type.
Definition primalValueBaseTape.hpp:91
T_Real Real
See PrimalValueTapeTypes.
Definition primalValueBaseTape.hpp:81
Data< IdentifierChunk, StatementData > RhsIdentifierData
Rhs identifiers data vector.
Definition primalValueBaseTape.hpp:107
Data< StatementChunk, IndexManager > StatementData
Statement data vector.
Definition primalValueBaseTape.hpp:104
ConstantValueData NestedData
See TapeTypesInterface.
Definition primalValueBaseTape.hpp:115
T_IndexManager IndexManager
See PrimalValueTapeTypes.
Definition primalValueBaseTape.hpp:83
Data< ConstantValueChunk, PassiveValueData > ConstantValueData
Constant values data vector.
Definition primalValueBaseTape.hpp:113
static constexpr bool IsStaticIndexHandler
True if the index manager must be stored statically in the tape.
Definition primalValueBaseTape.hpp:94
typename StatementEvaluator::Handle EvalHandle
Handle type returned by the statement generator.
Definition primalValueBaseTape.hpp:97
T_StatementEvaluator< Real > StatementEvaluator
See PrimalValueTapeTypes.
Definition primalValueBaseTape.hpp:84
Tape side interface for StatementEvaluatorInterface.
Definition statementEvaluatorTapeInterface.hpp:95
Creation of handles for the evaluation of expressions in a context where the expression type is not a...
Definition statementEvaluatorInterface.hpp:104
Tape side interface for StatementEvaluatorInterface.
Definition statementEvaluatorTapeInterface.hpp:55
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:128
virtual void start(Tape &tape)
Destructor.
Definition tapeReaderWriterInterface.hpp:143
virtual void finish()
After all the statements have been written, the finish method finalizes the writing process.
Definition tapeReaderWriterInterface.hpp:176
void eval(NodeInterface< Node > const &node, Args &&... args)
Start the evaluation of the logic on the given expression.
Definition traversalLogic.hpp:70
void node(Node const &node, Args &&... args)
Called for each node in the expression.
Definition traversalLogic.hpp:86
Unified access to the adjoint vector and primal vector in a tape evaluation.
Definition vectorAccessInterface.hpp:91
This class is used during the writing process of a primal value tape. The WriteInfo is returned by co...
Definition tapeReaderWriterInterface.hpp:69
size_t numberOfActiveArguments
Number of active arguments.
Definition tapeReaderWriterInterface.hpp:70
std::string stmtExpression
Used to generate a .hpp file for reading back a primal value tape.
Definition tapeReaderWriterInterface.hpp:72
std::string mathRepresentation
Definition tapeReaderWriterInterface.hpp:73
size_t numberOfConstantArguments
Number of constant arguments.
Definition tapeReaderWriterInterface.hpp:71