Changeset 1453 for trunk/test_more


Ignore:
Timestamp:
Jul 6, 2009 12:57:14 PM (11 years ago)
Author:
bradbell
Message:

trunk: New interface to LdvOp? operation (and fix bug in reverse_sweep).

vec_ad.cpp: add new test that checks for bug.
whats_new_09.omh. User's view of the changes.
prototype_op.hpp. Combine documentation for zero order forward Ldp and Ldv.
load_op.hpp: new LdvOp? interface.
forward0sweep.hpp: use new Ldv interface.
forward_sweep.hpp: use new Ldv interface.
reverse_sweep.hpp: use new Ldv interface.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/test_more/vec_ad.cpp

    r1452 r1453  
    188188        CppAD::Independent(X);
    189189
    190         size_t m = 1;
     190        size_t m = 2;
    191191        CPPAD_TEST_VECTOR< AD<double> > Y(m);
    192192
    193193        // The LdpOp instruction corresponds to operations with VecAD vectors.
    194         CppAD::VecAD<double> Z(1);
     194        CppAD::VecAD<double> Z(2);
    195195        AD<double> zero = 0;
    196196        Z[zero] = X[0] + 1;
     197
     198        // The LdvOp instruction corresponds to the index being a variable.
     199        AD<double> one = X[0] - 1; // one in a variable here
     200        Z[one]  = X[0] + 1.;
     201       
    197202
    198203        // Compute a function where the second order partial for y
     
    201206        // access to z is the parameter zero.
    202207        Y[0] = Z[zero] * Z[zero];
     208        Y[1] = Z[one]  * Z[one];
    203209
    204210        CppAD::ADFun<double> f(X, Y);
     
    210216        f.Forward(p, dx);
    211217
     218        // Test LdpOp
    212219        // second order reverse (test exp_if_true case)
    213220        CPPAD_TEST_VECTOR<double> w(m), dw(2 * n);
    214221        w[0] = 1.;
     222        w[1] = 0.;
    215223        p    = 2;
    216224        dw = f.Reverse(p, w);
     
    218226        // check first derivative in dw
    219227        double check = 2. * (Value( X[0] ) + 1.);
     228        ok &= NearEqual(dw[0], check, eps, eps);
     229
     230        // check second derivative in dw
     231        check = 2.;
     232        ok &= NearEqual(dw[1], check, eps, eps);
     233
     234        // Test LdvOp
     235        // second order reverse (test exp_if_true case)
     236        w[0] = 0.;
     237        w[1] = 1.;
     238        p    = 2;
     239        dw = f.Reverse(p, w);
     240
     241        // check first derivative in dw
     242        check = 2. * (Value( X[0] ) + 1.);
    220243        ok &= NearEqual(dw[0], check, eps, eps);
    221244
Note: See TracChangeset for help on using the changeset viewer.