Skip to content

Commit

Permalink
Bugfixes for preaccumulation.
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxSagebaum committed May 18, 2020
1 parent cd6511f commit b8ddede
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Doxyfile
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ PROJECT_NAME = "CoDiPack"
# could be handy for archiving the generated documentation or if some version
# control system is used.

PROJECT_NUMBER = 1.9.2
PROJECT_NUMBER = 1.9.3

# Using the PROJECT_BRIEF tag one can provide an optional one line description
# for a project that appears at the top of each page and should give viewer a
Expand Down
6 changes: 6 additions & 0 deletions documentation/Changelog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
Changelog {#Changelog}
===========================

### v 1.9.3 - 2020-05-18
- Bufix:
* PreaccumulationHelper with changing sizes could give a segmentation fault
* PreaccumulationHelper with changing zero patterns gave wrong results
* Dirty adjoint vector after computeJacobian call in Algorithms with a forward evaluation

### v 1.9.2 - 2020-04-28
- Core functionality:
* Support for remainder and round function.
Expand Down
4 changes: 2 additions & 2 deletions include/codi/configure.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ namespace codi {

#define CODI_MAJOR_VERSION 1
#define CODI_MINOR_VERSION 9
#define CODI_BUILD_VERSION 2
#define CODI_VERSION "1.9.2"
#define CODI_BUILD_VERSION 3
#define CODI_VERSION "1.9.3"

/**
* @brief Constant for the conversion from byte to megabyte.
Expand Down
3 changes: 3 additions & 0 deletions include/codi/tools/algorithms.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,9 @@ namespace codi {

setGradientOnGradientData(tape, j, input, inputSize, typename GT::Data());
}

tape.clearAdjoints(end, start);

} else if(EvaluationType::Reverse == evalType) {

for(size_t i = 0; i < outputSize; i += gradDim) {
Expand Down
26 changes: 25 additions & 1 deletion include/codi/tools/data/jacobian.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,23 @@ namespace codi {
values.resize(m*n);
}

/**
* @brief Change the size of the Jacobian to the new input and output values.
*
* Keeps the size of the internal value vector if new shape is smaller than the old one.
*
* @param[in] m Number of function outputs
* @param[in] n Number of function inputs
*/
CODI_INLINE void reshape(size_t const m, size_t const n) {
if(values.size() < m * n) {
this->resize(m, n);
} else {
this->m = m;
this->n = n;
}
}

/**
* @brief The number of entries of the Jacobian.
*
Expand Down Expand Up @@ -299,6 +316,13 @@ namespace codi {
nonZerosRow.resize(m);
}

/** \copydoc Jacobian::reshape */
CODI_INLINE void reshape(size_t const m, size_t const n) {
Jacobian<Vec>::reshape(m, n);
if(nonZerosRow.size() < m) {
nonZerosRow.resize(m);
}
}
/**
* @brief Reference to the number of non zero entries for the specified row.
*
Expand All @@ -320,8 +344,8 @@ namespace codi {
CODI_INLINE void setLogic(const size_t i, const size_t j, T const& v) {
if(T() != v) {
nonZerosRow[i] += 1;
Jacobian<Vec>::operator ()(i,j) = v;
}
Jacobian<Vec>::operator ()(i,j) = v;
}
};

Expand Down
6 changes: 3 additions & 3 deletions include/codi/tools/preaccumulationHelper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -317,8 +317,8 @@ namespace codi {
Tape& tape = CoDiType::getGlobalTape();

Position endPos = tape.getPosition();
if(jacobie.size() < inputData.size() * outputData.size()) {
jacobie.resize(outputData.size(), inputData.size());
if(jacobie.getM() != outputData.size() || jacobie.getN() != inputData.size()) {
jacobie.reshape(outputData.size(), inputData.size());
}

Algorithms<CoDiType, false>::computeJacobian(startPos, endPos,
Expand Down Expand Up @@ -356,7 +356,7 @@ namespace codi {
jacobiesForStatement -= 1;
}
}
nonZerosLeft -= jacobiesForStatement; /* update non zeros so that we now if it is the last round */
nonZerosLeft -= jacobiesForStatement; /* update non zeros so that we know if it is the last round */

GradientData storedGradientData = lastGradientData;
tape.storeManual(value.getValue(), lastGradientData, jacobiesForStatement + (int)staggeringActive);
Expand Down

0 comments on commit b8ddede

Please sign in to comment.