Skip to content

Commit

Permalink
Add assertions about insufficient adjoint vector size.
Browse files Browse the repository at this point in the history
Add assertions to gradient methods.
Add assertions to evaluate methods.
  • Loading branch information
jblueh committed Aug 23, 2023
1 parent c30f195 commit 8ee822a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
8 changes: 8 additions & 0 deletions include/codi/tapes/jacobianBaseTape.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,12 +241,16 @@ namespace codi {
checkAdjointSize(identifier);
}

codiAssert(identifier < (Identifier)adjoints.size());

return adjoints[identifier];
}

/// \copydoc codi::GradientAccessTapeInterface::gradient(Identifier const&, AdjointsManagement) const
CODI_INLINE Gradient const& gradient(
Identifier const& identifier, AdjointsManagement adjointsManagement = AdjointsManagement::Automatic) const {
codiAssert(identifier < (Identifier)adjoints.size());

if (AdjointsManagement::Automatic == adjointsManagement && identifier >= (Identifier)adjoints.size()) {
return adjoints[0];
} else {
Expand Down Expand Up @@ -730,6 +734,8 @@ namespace codi {
adjoints.beginUse();
}

codiAssert(indexManager.get().getLargestCreatedIndex() < (Identifier)adjoints.size());

cast().evaluateForward(start, end, adjoints.data());

if (AdjointsManagement::Automatic == adjointsManagement) {
Expand Down Expand Up @@ -794,6 +800,8 @@ namespace codi {
adjoints.beginUse();
}

codiAssert(indexManager.get().getLargestCreatedIndex() < (Identifier)adjoints.size());

evaluate(start, end, adjoints.data());

if (AdjointsManagement::Automatic == adjointsManagement) {
Expand Down
12 changes: 12 additions & 0 deletions include/codi/tapes/primalValueBaseTape.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,8 @@ namespace codi {
checkAdjointSize(identifier);
}

codiAssert(identifier < (Identifier)adjoints.size());

return adjoints[identifier];
}

Expand All @@ -282,6 +284,8 @@ namespace codi {
/// implement adjoints locking.
CODI_INLINE Gradient const& gradient(
Identifier const& identifier, AdjointsManagement adjointsManagement = AdjointsManagement::Automatic) const {
codiAssert(identifier < (Identifier)adjoints.size());

if (AdjointsManagement::Automatic == adjointsManagement && identifier >= (Identifier)adjoints.size()) {
return adjoints[0];
} else {
Expand Down Expand Up @@ -875,6 +879,8 @@ namespace codi {
checkAdjointSize(indexManager.get().getLargestCreatedIndex());
}

codiAssert(indexManager.get().getLargestCreatedIndex() < (Identifier)adjoints.size());

cast().evaluateForward(start, end, adjoints.data());
}

Expand Down Expand Up @@ -1068,6 +1074,8 @@ namespace codi {
checkAdjointSize(indexManager.get().getLargestCreatedIndex());
}

codiAssert(indexManager.get().getLargestCreatedIndex() < (Identifier)adjoints.size());

evaluate(start, end, adjoints.data());
}

Expand Down Expand Up @@ -1095,6 +1103,8 @@ namespace codi {
checkAdjointSize(indexManager.get().getLargestCreatedIndex());
}

codiAssert(indexManager.get().getLargestCreatedIndex() < (Identifier)adjoints.size());

internalEvaluateReverse<false>(start, end, adjoints.data());

if (!TapeTypes::IsLinearIndexHandler) {
Expand All @@ -1111,6 +1121,8 @@ namespace codi {
checkAdjointSize(indexManager.get().getLargestCreatedIndex());
}

codiAssert(indexManager.get().getLargestCreatedIndex() < (Identifier)adjoints.size());

if (!TapeTypes::IsLinearIndexHandler) {
cast().internalResetPrimalValues(end);
}
Expand Down

0 comments on commit 8ee822a

Please sign in to comment.