Exemplo n.º 1
0
  void ComputeAdjoint(){
    size_t tape_stats[STAT_SIZE];

    /* --- Get information about the current number of inputs/outputs --- */

    tapestats(1, tape_stats);

    /* --- Create temporary arrays to hold the adjoints of the input/output variables --- */

    double* gradient = new double[tape_stats[0]];
    double* adjoint  = new double[tape_stats[1]];

    /* --- Initialize the adjoint values --- */

    for (int i = 0; i < tape_stats[0]; ++i) {
      gradient[i] = 0.0;
    }

    for(int i = 0; i < tape_stats[1]; ++i) {
      adjoint[i] = seedVector[i];
    }

    /* --- Reverse interpretation of the computational graph --- */

    fos_reverse(1,tape_stats[1], tape_stats[0],adjoint, gradient);

    adjointVector          = gradient;
    adjointVector_Position = 0;

    inputVariables.clear();
    seedVector.clear();

    delete [] adjoint;
  }
Exemplo n.º 2
0
/*--------------------------------------------------------------------------*/
fint fos_reverse_(fint* ftag,
                  fint* fm,
                  fint* fn,
                  fdouble* fu,
                  fdouble* fz) {
    int rc=-1;
    int tag=*ftag, m=*fm, n=*fn;
    double* u = myalloc1(m);
    double* Z = myalloc1(n);
    spread1(m,fu,u);
    rc=fos_reverse(tag,m,n,u,Z);
    pack1(n,Z,fz);
    free((char*)Z);
    free((char*)u);
    return rc;
}