Changeset 3367


Ignore:
Timestamp:
Sep 27, 2014 7:55:27 AM (6 years ago)
Author:
bradbell
Message:

Fix bug in conditional skipping of calls to atomic functions.

opt_atomic.sh: test fix here.
optimize.hpp: fix bug here.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/bug/opt_atomic.sh

    r3366 r3367  
    8484int main(){
    8585        // Create the atomic function
    86         atomic_reciprocal afun("atomic_reciprocal");
     86        atomic_reciprocal afun("reciprocal");
    8787
    88         vector< AD<double> > ax(1), ay(1);
    89         ax[0]=1;
     88        AD<double> zero = 0.0;
     89
     90        vector< AD<double> > ax(2);
     91        ax[0] = 1.0;
     92        ax[1] = 2.0;
    9093        Independent(ax);
    91         afun(ax, ay);
    92         AD<double> az = 0.0; 
    93         ay[0] = CondExpGt(ay[0], az, az, ay[0]);
    94         ADFun<double> F(ax, ay);
    95  
    96         F.optimize();
     94
     95        vector< AD<double> > au(1), av(1), aw(1);
     96        au[0] = ax[0];
     97        afun(au, av);
     98        au[0] = ax[1];
     99        afun(au, aw);
     100
     101        vector< AD<double> > ay(1);
     102        ay[0] = CondExpGt(av[0], zero, av[0], aw[0]);
     103        ADFun<double> f(ax, ay);
     104
     105        // run case that skips the second call to afun
     106        // (can use trace in forward0sweep.hpp to see this).
     107        vector<double> x(2), y_before(1), y_after(1);
     108        x[0]      = 1.0;
     109        x[1]      = 2.0;
     110        y_before  = f.Forward(0, x);
     111        f.optimize();
     112        y_after   = f.Forward(0, x);
     113
     114        assert( y_before[0] == y_after[0] );
    97115}
    98116EOF
  • trunk/cppad/local/optimize.hpp

    r3364 r3367  
    20352035                // determine if we should insert a conditional skip here
    20362036                bool skip = cskip_info_next < cskip_info.size();
    2037                 skip     &= (op != BeginOp) & (op != InvOp);
     2037                skip     &= op != BeginOp;
     2038                skip     &= op != InvOp;
     2039                skip     &= user_state == user_start;
    20382040                if( skip )
    20392041                {       j     = cskip_info_order[cskip_info_next];
  • trunk/omh/whats_new/whats_new_14.omh

    r3359 r3367  
    5555assist you in learning about changes between various versions of CppAD.
    5656
     57$head 09-27$$
     58Fix a bug that occurred when
     59$cref/f.optimize/optimize/$$ was used with a function $icode f$$
     60that contained calls to user defined $cref atomic$$ operations.
     61
    5762$head 09-25$$
    58 Fix a bug when
     63Fix a bug that occurred when
    5964$cref/f.optimize/optimize/$$ was used with a function $icode f$$
    6065that contained $cref discrete$$ functions.
Note: See TracChangeset for help on using the changeset viewer.