Changeset 2976


Ignore:
Timestamp:
Oct 20, 2013 8:42:25 AM (6 years ago)
Author:
bradbell
Message:

Add test for case that was missed by simplification (that had to be backed out).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/test_more/optimize.cpp

    r2892 r2976  
    3636
    3737                // start recording a new function
    38                 ax[0] = 3.0;
    39                 ax[1] = 4.0;
    4038                CppAD::Independent(ax);
    4139
    4240                // now use algo_check during the recording
    43                 au[0] = ax[0];
    44                 au[1] = ax[0] + ax[1];
     41                au[0] = ax[0] + ax[1]; // this argument requires a new variable
     42                au[1] = ax[0] - ax[1]; // this argument also requires a new variable
    4543                algo_check(au, aw);
    4644
    47                 // now create a function that does not depend on au[1]
     45                // now create f(x) = x_0 - x_1
    4846                ay[0] = aw[0];
    4947                CppAD::ADFun<double> f(ax, ay);
     48
     49                // number of variables before optimization
     50                size_t n_before = f.size_var();
    5051 
    5152                // now optimize f so that the calculation of au[1] is removed
    5253                f.optimize();
     54
     55                // check difference in number of variables
     56                size_t n_after = f.size_var();
     57                ok &= n_before == n_after + 1;
    5358
    5459                // now compute and check a forward mode calculation
     
    5762                x[1] = 6.0;
    5863                y    = f.Forward(0, x);
    59                 ok  &= (y[0] == x[0]);
     64                ok  &= (y[0] == x[0] + x[1]);
    6065
    6166                return ok;
Note: See TracChangeset for help on using the changeset viewer.