Changeset 3504 for trunk/test_more


Ignore:
Timestamp:
Dec 25, 2014 9:41:45 AM (5 years ago)
Author:
bradbell
Message:

Detect the case where a variable that can be conditioinally skipped has
been removed and another variable is used in its place.

optimize.cpp: case that demonstrates this bug.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/test_more/optimize.cpp

    r3494 r3504  
    15941594                // f(x) = x[0] + x[0] if x[0] >= 3
    15951595                //      = x[0] + x[1] otherwise
    1596                 vector< AD<double> > ax(2), ay(1);
     1596                vector< AD<double> > ax(2), ay(2);
    15971597                ax[0] = 1.0;
    15981598                ax[1] = 2.0;
     
    16001600                AD<double> three(3);
    16011601                AD<double> value = ax[0] + ax[1];
    1602                 ay[0] = CppAD::CondExpGe(ax[0], three, value, value);
     1602                ay[0]  = CppAD::CondExpGe(ax[0], three, value, value);
     1603                ay[1]  = CppAD::CondExpGe(ax[0], three, ax[0]+ax[1], ax[0]+ax[1]);
    16031604                CppAD::ADFun<double> f(ax, ay);
    16041605                f.optimize();
    16051606
    16061607                // check case where x[0] >= 3
    1607                 vector<double> x(2), y(1);
     1608                vector<double> x(2), y(2);
    16081609                x[0] = 4.0;
    16091610                x[1] = 2.0;
    16101611                y    = f.Forward(0, x);
    16111612                ok  &= y[0] == x[0] + x[1];
     1613                ok  &= y[1] == x[0] + x[1];
    16121614
    16131615                // check case where x[0] < 3
     
    16161618                y    = f.Forward(0, x);
    16171619                ok  &= y[0] == x[0] + x[1];
     1620                ok  &= y[1] == x[0] + x[1];
    16181621
    16191622                return ok;
     
    16231626bool optimize(void)
    16241627{       bool ok = true;
     1628
    16251629        atomic_sparsity_option = CppAD::atomic_base<double>::bool_sparsity_enum;
    16261630        for(size_t i = 0; i < 2; i++)
Note: See TracChangeset for help on using the changeset viewer.