Changeset 2891 for trunk/test_more


Ignore:
Timestamp:
Aug 11, 2013 11:06:55 AM (6 years ago)
Author:
bradbell
Message:

jenkins.sh: Postpone Sacado test until we figure out how to install trillions on coin-jenkins.
op_code.hpp: fix bug in tracing operation sequence with atomic functions.
optimize.hpp: fix bug in optimizing out atomic function arguments that are not used.
optimize.cpp: test for bug that was fixed during this commit.
optimize.sh: This test has been moved into test_more/optimize.cpp.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/test_more/optimize.cpp

    r2859 r2891  
    1717
    1818namespace {
     19        // -------------------------------------------------------------------
     20        // Test of optimizing out arguments to an atomic function
     21        void algo(
     22                const CppAD::vector< CppAD::AD<double> >& ax ,
     23                      CppAD::vector< CppAD::AD<double> >& ay )
     24        {       CppAD::AD<double> zero(0.);
     25
     26                // Arguments that are not used are mapped to nan
     27                // but zero order forward mode does not like this.
     28                for(size_t i = 0; i < ax.size(); i++)
     29                {       // convert nan to zero in a way that get stored in op sequence
     30                        ay[i] = CondExpEq(ax[i], ax[i], ax[i], zero);
     31                }
     32        }
     33        bool atomic_arguments(void)
     34        {       bool ok = true;
     35                using CppAD::AD;
     36                using CppAD::vector;
     37                vector< AD<double> > au(2), aw(2), ax(2), ay(1);
     38
     39                // create atomic function corresponding to algo
     40                au[0] = 1.0;
     41                au[1] = 2.0;
     42                CppAD::checkpoint<double> algo_check("algo", algo, au, ax);
     43
     44                // start recording a new function
     45                ax[0] = 3.0;
     46                ax[1] = 4.0;
     47                CppAD::Independent(ax);
     48
     49                // now use algo_check during the recording
     50                au[0] = ax[0];
     51                au[1] = ax[0] + ax[1];
     52                algo_check(au, aw);
     53
     54                // now create a function that does not depend on au[1]
     55                ay[0] = aw[0];
     56                CppAD::ADFun<double> f(ax, ay);
     57 
     58                // now optimize f so that the calculation of au[1] is removed
     59                f.optimize();
     60
     61                // now compute and check a forward mode calculation
     62                vector<double> x(2), y(1);
     63                x[0] = 5.0;
     64                x[1] = 6.0;
     65                y    = f.Forward(0, x);
     66                ok  &= (y[0] == x[0]);
     67
     68                return ok;
     69        }
    1970
    2071        // -------------------------------------------------------------------
     
    11171168bool optimize(void)
    11181169{       bool ok = true;
     1170        // check optimizing out atomic arguments
     1171        ok     &= atomic_arguments();
    11191172        // check reverse dependency analysis optimization
    11201173        ok     &= depend_one();
Note: See TracChangeset for help on using the changeset viewer.