Changeset 2994 for trunk/test_more
 Timestamp:
 Oct 23, 2013 11:47:20 AM (6 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

trunk/test_more/optimize.cpp
r2993 r2994 17 17 18 18 namespace { 19 //  20 // Test for bug where checkpoint function did not depend on 21 // the operands in the logical comparison because of the CondExp 22 // sparsity pattern. 23 void j_algo( 24 const CppAD::vector< CppAD::AD<double> >& ax , 25 CppAD::vector< CppAD::AD<double> >& ay ) 26 { ay[0] = CondExpGt(ax[0], ax[1], ax[2], ax[3]); } 27 28 bool cond_exp_sparsity(void) 29 { bool ok = true; 30 using CppAD::AD; 31 using CppAD::vector; 32 33 // Create a checkpoint version of the function g 34 vector< AD<double> > au(4), av(1); 35 for(size_t i = 0; i < 4; i++) 36 au[i] = AD<double>(i); 37 CppAD::checkpoint<double> j_check("j_check", j_algo, au, av); 38 39 // independent variable vector 40 vector< AD<double> > ax(2), ay(1); 41 ax[0] = 1.; 42 ax[1] = 1.; 43 Independent(ax); 44 45 // call atomic function that does not get used 46 for(size_t i = 0; i < 4; i++) 47 au[i] = ax[0] + AD<double>(i + 1) * ax[1]; 48 j_check(au, ay); 49 50 // create function object f : ax > ay 51 CppAD::ADFun<double> f(ax, ay); 52 53 // now optimize the operation sequence 54 f.optimize(); 55 56 // check result where true case is used; i.e., au[0] > au[1] 57 vector<double> x(2), y(1); 58 x[0] = 1.; 59 x[1] = 1; 60 y = f.Forward(0, x); 61 ok &= y[0] == x[0] + double(3) * x[1]; 62 63 64 // check result where false case is used; i.e., au[0] <= au[1] 65 x[0] = 1.; 66 x[1] = 1; 67 y = f.Forward(0, x); 68 ok &= y[0] == x[0] + double(4) * x[1]; 69 70 return ok; 71 } 19 72 //  20 73 // Test conditional optimizing out call to an atomic function call … … 1006 1059 1007 1060 // Y[2] 1008 // 2DO: There is a subtitle issue that has to do with using reverse1009 // jacobian sparsity patterns during the optimization process.1010 // We need an option to include X[0] in the sparsity pattern1011 // so the optimizer can know it affects the results.1012 1061 Y[index] = CondExpLe(X[0], X[1], X[1]+X[1], X[2]X[2]); 1013 1062 Check[index * n + 0] = false; … … 1319 1368 bool optimize(void) 1320 1369 { bool ok = true; 1370 // check conditional expression sparsity pattern 1371 // (used to optimize calls to atomic functions). 1372 ok &= cond_exp_sparsity(); 1321 1373 // check optimizing out entire atomic function 1322 1374 ok &= atomic_cond_exp();
Note: See TracChangeset
for help on using the changeset viewer.