Changeset 2976
 Timestamp:
 Oct 20, 2013 8:42:25 AM (6 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

trunk/test_more/optimize.cpp
r2892 r2976 36 36 37 37 // start recording a new function 38 ax[0] = 3.0;39 ax[1] = 4.0;40 38 CppAD::Independent(ax); 41 39 42 40 // now use algo_check during the recording 43 au[0] = ax[0] ;44 au[1] = ax[0] + ax[1];41 au[0] = ax[0] + ax[1]; // this argument requires a new variable 42 au[1] = ax[0]  ax[1]; // this argument also requires a new variable 45 43 algo_check(au, aw); 46 44 47 // now create a function that does not depend on au[1]45 // now create f(x) = x_0  x_1 48 46 ay[0] = aw[0]; 49 47 CppAD::ADFun<double> f(ax, ay); 48 49 // number of variables before optimization 50 size_t n_before = f.size_var(); 50 51 51 52 // now optimize f so that the calculation of au[1] is removed 52 53 f.optimize(); 54 55 // check difference in number of variables 56 size_t n_after = f.size_var(); 57 ok &= n_before == n_after + 1; 53 58 54 59 // now compute and check a forward mode calculation … … 57 62 x[1] = 6.0; 58 63 y = f.Forward(0, x); 59 ok &= (y[0] == x[0] );64 ok &= (y[0] == x[0] + x[1]); 60 65 61 66 return ok;
Note: See TracChangeset
for help on using the changeset viewer.