Changeset 3369


Ignore:
Timestamp:
Sep 28, 2014 5:07:02 AM (6 years ago)
Author:
bradbell
Message:

opt_atomic.sh: another bug report.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bug/opt_atomic.sh

    r3367 r3369  
    1515EOF
    1616cat << EOF > bug.$$
     17// Another bug (reported by Kasper Kristensen) optimizing combination of
     18// conditional expressions and atomic functions.
    1719# include <cppad/cppad.hpp>
    1820
     
    8284
    8385
    84 int main(){
    85         // Create the atomic function
     86int main()
     87{       bool ok = true;
    8688        atomic_reciprocal afun("reciprocal");
    8789
    88         AD<double> zero = 0.0;
    89 
    90         vector< AD<double> > ax(2);
     90        vector< AD<double> > av(1), aw(1), ax(2), ay(1);
     91        AD<double> zero = 0.0; 
    9192        ax[0] = 1.0;
    92         ax[1] = 2.0;
     93        ax[1] = 1.0;
    9394        Independent(ax);
    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);
     95        av[0] = ax[0] + ax[1];
     96        afun(av, aw);
     97        ay[0] = CondExpGt(aw[0], zero, zero, aw[0]);
     98        ADFun<double> f;
     99        f.Dependent(ax, ay);
    104100
    105101        // run case that skips the second call to afun
    106         // (can use trace in forward0sweep.hpp to see this).
     102        // (but not for order zero)
    107103        vector<double> x(2), y_before(1), y_after(1);
    108104        x[0]      = 1.0;
    109         x[1]      = 2.0;
     105        x[1]      = 1.0;
    110106        y_before  = f.Forward(0, x);
    111107        f.optimize();
    112108        y_after   = f.Forward(0, x);
     109       
     110        ok &= y_before[0] == y_after[0];
    113111
    114         assert( y_before[0] == y_after[0] );
     112        return( ! ok );
    115113}
    116114EOF
Note: See TracChangeset for help on using the changeset viewer.