Changeset 3894 for trunk/test_more
 Timestamp:
 Mar 4, 2017 9:56:53 PM (3 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

trunk/test_more/optimize.cpp
r3871 r3894 1875 1875 ok &= NearEqual(y[1], x[0]  x[1], eps10, eps10); 1876 1876 ok &= NearEqual(y[2], exp(x[0]), eps10, eps10); 1877 1878 return ok; 1879 } 1880 1881 // Test case where a variable is removed during optimization 1882 // (bug fixed 20170304) 1883 bool cond_exp_skip_remove_var(void) 1884 { bool ok = true; 1885 using CppAD::vector; 1886 using CppAD::AD; 1887 using CppAD::NearEqual; 1888 double eps10 = 10.0 * std::numeric_limits<double>::epsilon(); 1889 1890 vector< AD<double> > ax(2), ay(2); 1891 ax[0] = 1.0; 1892 ax[1] = 2.0; 1893 Independent(ax); 1894 // 1895 AD<double> var_1 = ax[0] + ax[1]; 1896 AD<double> var_2 = ax[0] + ax[1]; // gets removed during optimization 1897 AD<double> var_3 = ax[0]  ax[1]; 1898 AD<double> par_1 = 1.0; 1899 // 1900 // first conditional expression depends on var_1 1901 // 6 * x_0 if x_0 + x_1 >= 1.0, 7 * x_1 otherwise 1902 ay[0] = CppAD::CondExpGe(var_1, par_1, 6.0 * ax[0], 7.0 * ax[1]); 1903 // 1904 // second conditional expression depends on var_3 1905 // 8 * x_0 if x_0  x_1 >= x_0 + x_1, 9 * x_1 otherwise 1906 ay[1] = CppAD::CondExpGe(var_3, par_1, 8.0 * ax[0], 9.0 * ax[1]); 1907 CppAD::ADFun<double> f(ax, ay); 1908 // 1909 if( conditional_skip_ ) 1910 f.optimize(); 1911 else 1912 f.optimize("no_conditional_skip"); 1913 1914 // check case where x[0] = 2, x[1] = 4 1915 vector<double> x(2), y(2); 1916 x[0] = 2.0; 1917 x[1] = 4.0; 1918 y = f.Forward(0, x); 1919 ok &= NearEqual(y[0], 6.0 * x[0], eps10, eps10); 1920 ok &= NearEqual(y[1], 9.0 * x[1], eps10, eps10); 1877 1921 1878 1922 return ok; … … 1950 1994 ok &= cond_exp_reverse(); 1951 1995 // check case where an expresion needed by both true and false case 1952 ok &= cond_exp_both_true_and_false(); 1953 } 1996 ok &= cond_exp_both_true_and_false(); 1997 // check case were a variable in left or right expressions 1998 // is removed during the optimization 1999 ok &= cond_exp_skip_remove_var(); 2000 } 2001 ok &= cond_exp_skip_remove_var(); 1954 2002 // 1955 2003 CppAD::user_atomic<double>::clear();
Note: See TracChangeset
for help on using the changeset viewer.