Ignore:
Timestamp:
Sep 20, 2014 5:45:43 AM (6 years ago)
Author:
bradbell
Message:

Implement and test first order forward mode.

cache.sh: Erase taylor coefficient when create cache.
forward1sweep.hpp: copy more information from forward0sweep.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/cache/bug/cache.sh

    r3343 r3344  
    3939        using CppAD::ADFun;
    4040       
    41         vector< AD<double> > ax(2), ay(2);
     41        size_t n = 2;
     42        size_t m = 2;
     43        vector< AD<double> > ax(n), ay(m);
    4244
    4345        ax[0] = 0.0;
     
    5153        f.Dependent(ax, ay);
    5254
    53         vector<double> x(2), y(2), w(2), dw(2);
     55        // zero order forward, no cache
     56        vector<double> x(n), y(m);
    5457        x[0] = 1.0;
    5558        x[1] = 2.0;
    5659        y = f.Forward(0, x);
    57         w[0] = 1.0;
    58         w[1] = 2.0;
    59         dw = f.Reverse(1, w);
    6060
     61        // first order forward, no cache
     62        vector<double> dx(n), dy(m);
     63        dx[0] = 3.0;
     64        dx[1] = 4.0;
     65        dy = f.Forward(1, dx);
     66
     67        // create cache
    6168        f.cache();
    6269
    63         // test zero order forward mode
    64         vector<double> y_cache(2);
     70        // zero order forward, with cache
     71        vector<double> y_cache(m);
    6572        y_cache = f.Forward(0, x);
    6673        ok &= y[0] == y_cache[0];
    6774        ok &= y[1] == y_cache[1];
     75        // std::cout << "y       = " << y       << std::endl;
     76        // std::cout << "y_cache = " << y_cache << std::endl;
     77
     78
     79        // first order forward, with cache
     80        vector<double> dy_cache(m);
     81        dy_cache = f.Forward(1, dx);
     82        ok &= dy[0] == dy_cache[0];
     83        ok &= dy[1] == dy_cache[1];
     84        // std::cout << "dy       = " << dy       << std::endl;
     85        // std::cout << "dy_cache = " << dy_cache << std::endl;
    6886
    6987        return ok;
     
    7593}
    7694EOF
    77 # Turn on tracing
    78 forward='../../cppad/local/forward0sweep.hpp'
    79 sed \
    80         -e 's|^\(# define CPPAD_FORWARD0SWEEP_TRACE\) 0|\1 1|' \
    81         -i $forward
    82 reverse='../../cppad/local/reverse_sweep.hpp'
    83 sed \
    84         -e 's|^\(# define CPPAD_REVERSE_SWEEP_TRACE\) 0|\1 1|' \
    85         -i $reverse
    86 #
    8795echo "g++ -g $name.cpp -I../.. -fopenmp -std=c++11 -o $name"
    8896g++ -g $name.cpp -I../.. -fopenmp -std=c++11 -o $name
     
    9098echo "./$name"
    9199./$name
    92 #
    93 #
    94 sed \
    95         -e 's|^\(# define CPPAD_FORWARD0SWEEP_TRACE\) 1|\1 0|' \
    96         -i $forward
    97 #
    98 sed \
    99         -e 's|^\(# define CPPAD_REVERSE_SWEEP_TRACE\) 1|\1 0|' \
    100         -i $reverse
Note: See TracChangeset for help on using the changeset viewer.