Changeset 1589 for trunk/test_more


Ignore:
Timestamp:
Nov 24, 2009 10:15:10 PM (11 years ago)
Author:
bradbell
Message:

trunk: Fix optimize.hpp bug, special operations to indicate ends of tape.

optimize.cpp: test a reverse mode case (demonstrates bug).

Use EndOp? (BeginOp?) as indication of end of a forward (reverse) sweep:
for_jac_sweep.hpp, optimize.hpp, forward0sweep.hpp, forward_sweep.hpp,
rev_jac_sweep.hpp, rev_hes_sweep.hpp, reverse_sweep.hpp

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/test_more/optimize.cpp

    r1581 r1589  
    1111-------------------------------------------------------------------------- */
    1212
     13# include <limits>
    1314# include <cppad/cppad.hpp>
    1415
     
    211212       
    212213                for(j = 0; j < n; j++)
    213                         X[j] = x[j] = double(j+1);
     214                        X[j] = x[j] = double(j+2);
    214215       
    215216                CppAD::Independent(X);
     
    228229                for(j = 0; j < n; j++)
    229230                        ok &= ( y[j] == Value(Y[j]) );
     231
     232                // check reverse mode derivative
     233                vector<double>   w(n), dw(n);
     234                w[0] = 0.;
     235                w[1] = 0.;
     236                w[2] = 1.;
     237                dw = F.Reverse(1, w);
     238
     239                double eps = 20. * std::numeric_limits<double>::epsilon();
     240                double check = x[1] * pow( x[0], x[1] - 1. );
     241                ok &= CppAD::NearEqual( dw[0], check, eps, eps );
     242
     243                check = log( x[0] ) * pow( x[0], x[1] );
     244                ok &= CppAD::NearEqual( dw[1], check, eps, eps );
     245
     246                check = 0.;
     247                ok &= CppAD::NearEqual( dw[2], check, eps, eps );
    230248       
    231249                return ok;
Note: See TracChangeset for help on using the changeset viewer.