40#include "../../misc/eventSystem.hpp"
42#include "../data/dataInterface.hpp"
43#include "indexManagerInterface.hpp"
65 template<
typename T_Index>
94 Index reservedIndices;
108 TapeValues::LocalReductionOperation
constexpr operation =
109 NeedsStaticStorage ? TapeValues::LocalReductionOperation::Max : TapeValues::LocalReductionOperation::Sum;
116 template<
typename Tape>
127 template<
typename Tape>
130 CODI_EXCEPTION(
"Overflow in linear index handler. Use a larger index type or a reuse index manager.");
144 template<
typename Tape>
150 template<
typename Tape>
200 template<
typename TargetPosition>
218 return count - startPos;
224 return reservedIndices;
251 count = reservedIndices;
256 count = reservedIndices;
273 std::swap(reservedIndices, other.reservedIndices);
274 std::swap(count, other.count);
279 template<
int selectedDepth = -1,
typename FunctionObject,
typename... Args>
282 function(std::forward<Args>(args)..., start, end);
287 template<
int selectedDepth = -1,
typename FunctionObject,
typename... Args>
290 function(std::forward<Args>(args)..., start, end);
294 template<
typename FunctionObject,
typename... Args>
301 template<
typename FunctionObject,
typename... Args>
308 template<
typename FunctionObject,
typename... Args>
#define CODI_INLINE
See codi::Config::ForcedInlines.
Definition config.h:469
#define codiAssert(x)
See codi::Config::EnableAssert.
Definition config.h:441
#define CODI_DD(Type, Default)
Abbreviation for CODI_DECLARE_DEFAULT.
Definition macros.hpp:97
#define CODI_ENABLE_CHECK(option, condition)
Definition macros.hpp:62
bool constexpr IndexEvents
Enable index management events. Disabled by default.
Definition config.h:336
bool constexpr OverflowCheck
Check in the index manager if an overflow occurred.
Definition config.h:248
CoDiPack - Code Differentiation Package.
Definition codi.hpp:97
inlinevoid CODI_UNUSED(Args const &...)
Disable unused warnings for an arbitrary number of arguments.
Definition macros.hpp:55
Data stream interface for tape data. Encapsulates data that is written e.g. for each statement or arg...
Definition dataInterface.hpp:149
static inlinevoid notifyIndexCopyListeners(Index const &index)
Invoke callbacks for IndexCopy events.
Definition eventSystem.hpp:833
static inlinevoid notifyIndexAssignListeners(Index const &index)
Invoke callbacks for IndexAssign events.
Definition eventSystem.hpp:778
static inlinevoid notifyIndexFreeListeners(Index const &index)
Invoke callbacks for IndexFree events.
Definition eventSystem.hpp:806
Indices enable the mapping of primal values to their adjoint counterparts.
Definition indexManagerInterface.hpp:78
static Index constexpr InactiveIndex
Definition indexManagerInterface.hpp:87
static Index constexpr InvalidIndex
Definition indexManagerInterface.hpp:88
inlineIndex const & getIndex(ActiveTypeIndexData const &data)
Extract index from data stored in active type.
Definition linearIndexManager.hpp:180
LinearIndexManager(Index reservedIndices)
Constructor.
Definition linearIndexManager.hpp:99
size_t InternalPosHandle
Internal positions coincide with positions.
Definition linearIndexManager.hpp:88
inlinePosition getZeroPosition() const
Definition linearIndexManager.hpp:223
IndexManagerInterface< Index > Base
Base class abbreviation.
Definition linearIndexManager.hpp:71
void validateRhsIndex(ActiveTypeIndexData const &data) const
Check if the rhs index is valid.
Definition linearIndexManager.hpp:190
void swap(LinearIndexManager< Index > &other)
Definition linearIndexManager.hpp:272
void NestedData
Terminator, no further nested data.
Definition linearIndexManager.hpp:87
void addToTapeValues(TapeValues &values) const
Add storage and other information to the tape values.
Definition linearIndexManager.hpp:107
inlinebool assignUnusedIndex(Index &index)
Call on registering input values.
Definition linearIndexManager.hpp:145
inlinevoid copyIndex(Index &lhs, Index const &rhs)
Call on copy of a primal value, e.g. w = a.
Definition linearIndexManager.hpp:151
static bool constexpr CopyNeedsStatement
Copy optimization is implemented.
Definition linearIndexManager.hpp:77
inlinevoid resetTo(Position const &pos)
Definition linearIndexManager.hpp:243
inlinebool assignIndex(Index &index)
Call on assignment of a primal value, e.g. on w for w = a + b.
Definition linearIndexManager.hpp:128
T_Index Index
See LinearIndexManager.
Definition linearIndexManager.hpp:69
inlinesize_t getPushedDataCount(InternalPosHandle const &startPos)
Definition linearIndexManager.hpp:217
Index Position
Positions coincide with indices.
Definition linearIndexManager.hpp:86
inlinevoid forEachReverse(Position const &start, Position const &end, FunctionObject function, Args &&... args)
Calls the function object for each item in the data stream. This call is not recursive.
Definition linearIndexManager.hpp:309
inlinevoid reset()
Definition linearIndexManager.hpp:250
inlinevoid forEachForward(Position const &start, Position const &end, FunctionObject function, Args &&... args)
Calls the function object for each item in the data stream. This call is not recursive.
Definition linearIndexManager.hpp:302
inlinevoid forEachChunk(FunctionObject &function, bool recursive, Args &&... args)
Calls the function object for each continuous segment of data.
Definition linearIndexManager.hpp:295
inlinePosition getPosition() const
Definition linearIndexManager.hpp:212
inlinesize_t getDataSize() const
Definition linearIndexManager.hpp:206
inlineIndex getLargestCreatedIndex() const
Returns the largest created index.
Definition linearIndexManager.hpp:165
void erase(Position const &start, Position const &end, bool recursive=true)
Definition linearIndexManager.hpp:262
inlinevoid evaluateForward(Position const &start, Position const &end, FunctionObject function, Args &&... args)
Evaluates the function object with segments of continuous and valid data for all nested DataInterface...
Definition linearIndexManager.hpp:280
inlinevoid pushData()
Add data to the storage allocated by the implementation. The method can only be called after a call t...
Definition linearIndexManager.hpp:228
void resize(size_t const &totalSize)
Definition linearIndexManager.hpp:238
inlinevoid resetHard()
Definition linearIndexManager.hpp:255
static bool constexpr NeedsStaticStorage
Linear indices are not meaningful across tape instances.
Definition linearIndexManager.hpp:79
inlineIndex & getIndex(ActiveTypeIndexData &data)
Extract index from data stored in active type.
Definition linearIndexManager.hpp:185
inlinevoid freeIndex(Index &index) const
Definition linearIndexManager.hpp:117
inlinevoid evaluateReverse(Position const &start, Position const &end, FunctionObject function, Args &&... args)
Evaluates the function object with segments of continuous and valid data for all nested DataInterface...
Definition linearIndexManager.hpp:288
inlineInternalPosHandle reserveItems(size_t const &items)
Reserve this many items on the data stream. See pushData for details.
Definition linearIndexManager.hpp:231
static bool constexpr IsLinear
Tightly coupled to statements.
Definition linearIndexManager.hpp:78
inlinevoid initIndex(Index &index)
Initialize the index data. Usually zero everything.
Definition linearIndexManager.hpp:170
inlinevoid updateLargestCreatedIndex(Index const &index)
Update the largest generated index.
Definition linearIndexManager.hpp:175
void setNested(NestedData *v)
Definition linearIndexManager.hpp:267
Index ActiveTypeIndexData
Same as the index.
Definition linearIndexManager.hpp:70
inlineTargetPosition extractPosition(Position const &pos) const
Extract the position of a nested DataInterface from the global position object provide by this interf...
Definition linearIndexManager.hpp:201
Tape information that can be printed in a pretty print format or a table format.
Definition tapeValues.hpp:75
void addLongEntry(std::string const &name, long const &value, LocalReductionOperation operation=LocalReductionOperation::Sum)
Add long entry.
Definition tapeValues.hpp:152