Changeset 3002 for trunk/test_more
 Timestamp:
 Oct 29, 2013 12:45:36 PM (6 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

trunk/test_more/optimize.cpp
r2994 r3002 17 17 18 18 namespace { 19 //  20 // Test nested conditional expressions. 21 int nested_cond_exp(void) 22 { bool ok = true; 23 using CppAD::AD; 24 using CppAD::vector; 25 26 // independent variable vector 27 vector< AD<double> > ax(2), ay(1); 28 ax[0] = 1.0; 29 ax[1] = 2.0; 30 Independent(ax); 31 32 // first conditional expression 33 AD<double> ac1 = CondExpLe(ax[0], ax[1], 2.0 * ax[0], 3.0 * ax[1] ); 34 35 // second conditional expression 36 AD<double> ac2 = CondExpGe(ax[0], ax[1], 4.0 * ax[0], 5.0 * ax[1] ); 37 38 // third conditional expression 39 AD<double> ac3 = CondExpLt(ax[0], ax[1], 6.0 * ac1, 7.0 * ac2 ); 40 41 // create function object f : ax > ay 42 ay[0] = ac3; 43 CppAD::ADFun<double> f(ax, ay); 44 45 // now optimize the operation sequence 46 f.optimize(); 47 48 // now zero order forward 49 vector<double> x(2), y(1); 50 for(size_t i = 0; i < 3; i++) 51 { x[0] = 1.0  double(i); 52 x[1] =  x[0]; 53 y = f.Forward(0, x); 54 // 55 // first conditional expression 56 double c1; 57 if( x[0] <= x[1] ) 58 c1 = 2.0 * x[0]; 59 else c1 = 3.0 * x[1]; 60 // 61 // second conditional expression 62 double c2; 63 if( x[0] >= x[1] ) 64 c2 = 4.0 * x[0]; 65 else c2 = 5.0 * x[1]; 66 67 // third conditional expression 68 double c3; 69 if( x[0] < x[1] ) 70 c3 = 6.0 * c1; 71 else c3 = 7.0 * c2; 72 73 ok &= y[0] == c3; 74 } 75 return ok; 76 } 19 77 //  20 78 // Test for bug where checkpoint function did not depend on … … 1368 1426 bool optimize(void) 1369 1427 { bool ok = true; 1428 // check nested conditional expressions 1429 ok &= nested_cond_exp(); 1370 1430 // check conditional expression sparsity pattern 1371 1431 // (used to optimize calls to atomic functions).
Note: See TracChangeset
for help on using the changeset viewer.