Ignore:
Timestamp:
Feb 11, 2015 9:37:10 AM (5 years ago)
Author:
bradbell
Message:

merge to branch: trunk
from repository: https://github.com/coin-or/CppAD
start hash code: 22c1453e46e3eb16e9a96d679a0a1fd459c849c0
end hash code: ee39862aa18207f6085df3cfacf8353d7a0682c3

commit ee39862aa18207f6085df3cfacf8353d7a0682c3
Author: Brad Bell <bradbell@…>
Date: Wed Feb 11 07:15:13 2015 -0700

optimize.hpp: fixed bug in optimization of conditional expressions.
optimize.cpp: test that demonstrates bug.

commit 2578d9745b6261d802337bd14b38efedacf680b0
Author: Brad Bell <bradbell@…>
Date: Wed Feb 11 04:45:33 2015 -0700

cond_exp.sh: a new bug report.

commit 0ab482aef633270ebfc3db2e2533d5ad8d696aaa
Author: Brad Bell <bradbell@…>
Date: Wed Feb 11 04:32:05 2015 -0700

erf.sh: This bug was fixed; see whats new 2015-02-10.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/test_more/optimize.cpp

    r3638 r3642  
    12841284                return ok;
    12851285        }
     1286        // check that CondExp properly handels expressions that get
     1287        // removed during opitmization
     1288        bool cond_exp_removed(void)
     1289        {       bool ok = true;
     1290                using CppAD::AD;
     1291                AD<double> zero(0.);
     1292       
     1293                size_t n = 1;
     1294                CppAD::vector< AD<double> > X(n);
     1295                X[0] = 1.0;
     1296                CppAD::Independent(X);
     1297       
     1298                size_t m = 1;
     1299                CppAD::vector< AD<double> > Y(m);
     1300
     1301                AD<double> true_case  = sin(X[0]) + sin(X[0]);
     1302                AD<double> false_case = cos(X[0]) + cos(X[0]);
     1303                Y[0] = CondExpLt(X[0],  zero,  true_case, false_case);
     1304
     1305                CppAD::ADFun<double> f(X, Y);
     1306                f.optimize();
     1307
     1308                CppAD::vector<double> x(n), y(m), w(m), dw(n);
     1309                x[0] = 1.0;
     1310                y    = f.Forward(0, x);
     1311                ok &= NearEqual(y[0], false_case, eps, eps);
     1312
     1313                w[0] = 1.0;
     1314                dw   = f.Reverse(1, w);
     1315                // derivative of cos is minus sin
     1316                ok &= NearEqual(dw[0], - true_case, eps, eps);
     1317
     1318                return ok;
     1319        }
    12861320        // -------------------------------------------------------------------
    12871321        void my_union(
     
    16571691bool optimize(void)
    16581692{       bool ok = true;
    1659 
    16601693        atomic_sparsity_option = CppAD::atomic_base<double>::bool_sparsity_enum;
    16611694        for(size_t i = 0; i < 2; i++)
     
    16931726        // check that CondExp properly detects dependencies
    16941727        ok     &= cond_exp_depend();
     1728        // check that it properly handles expressions that have been removed
     1729        ok     &= cond_exp_removed();
    16951730        // check old_atomic functions
    16961731        ok     &= old_atomic_test();
Note: See TracChangeset for help on using the changeset viewer.