/**
       * @brief The delete function that is registered on the tape.
       *
       * It calls delete on the data object.
       *
       * @param[in] t  unused
       * @param[in] d  An instance of this class.
       */
      static void delFunc(void* t, void* d) {
        CODI_UNUSED(t);

        ExternalFunctionData<CoDiType>* data = (ExternalFunctionData<CoDiType>*)d;

        delete data;
      }
      /**
       * @brief The reverse evaluation function.
       *
       * This function retrieves the adjoint values of the output. Afterwards the user defined evaluation function is
       * called. The adjoint of the input values is then used for the update of the tape adjoints.
       *
       * If the adjoint interface specifies a vector mode the function is evaluated multiple times.
       *
       * @param[in,out]  t  The tape which evaluates this function.
       * @param[in,out] ra  The helper structure for the access to the adjoint and primal vector.
       */
      void evalRevFunc(Tape* t, AdjointInterface<Real, GradientData>* ra) {
        CODI_UNUSED(t);

        Real* x_b = new Real[inputIndices.size()];
        Real* y_b = new Real[outputIndices.size()];

        for(size_t dim = 0; dim < ra->getVectorSize(); ++dim) {

          for(size_t i = 0; i < outputIndices.size(); ++i) {
            y_b[i] = ra->getAdjoint(outputIndices[i], dim);
            ra->resetAdjoint(outputIndices[i], dim);
          }

          revFunc(inputValues.data(), x_b, inputIndices.size(), outputValues.data(), y_b, outputIndices.size(), &userData);

          for(size_t i = 0; i < inputIndices.size(); ++i) {
            ra->updateAdjoint(inputIndices[i], dim, x_b[i]);
          }
        }

        if(Tape::RequiresPrimalReset) {
          for(size_t i = 0; i < outputIndices.size(); ++i) {
            ra->setPrimal(outputIndices[i], oldPrimals[i]);
          }
        }

        delete [] x_b;
        delete [] y_b;
      }
Example #3
0
 /**
  * @brief The expression is unfolded to *this -= 1.0
  *
  * @param u Indicator for postfix operator.
  */
 inline ActiveReal<Real, Tape> operator--(int u) {
   CODI_UNUSED(u);
   ActiveReal<Real, Tape> r(*this);
   *this = *this - 1.0;
   return r;
 }
Example #4
0
 /**
  * @brief Will do nothing.
  */
 inline void reset(const Position& pos) {
   CODI_UNUSED(pos);
 }