Changeset 3637 for trunk/test_more
 Timestamp:
 Feb 9, 2015 7:48:56 PM (5 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

trunk/test_more/optimize.cpp
r3607 r3637 17 17 18 18 namespace { 19 // accuracy for almost equal checks 20 double eps = 10. * std::numeric_limits<double>::epsilon(); 21 using CppAD::NearEqual; 22 19 23 // note this enum type is not part of the API (but its values are) 20 24 CppAD::atomic_base<double>::option_enum atomic_sparsity_option; … … 396 400 depend_fun(x, check, original, opt); 397 401 for(i = 0; i < m; i++) 398 ok &= (y[i] == check[i]);402 ok &= NearEqual(y[i], check[i], eps, eps); 399 403 400 404 // Check size before optimization … … 411 415 y = F.Forward(0, x); 412 416 for(i = 0; i < m; i++) 413 ok &= (y[i] == check[i]);417 ok &= NearEqual(y[i], check[i], eps, eps); 414 418 415 419 return ok; … … 528 532 dw = F.Reverse(1, w); 529 533 530 double eps = 20. * std::numeric_limits<double>::epsilon();531 534 double check = x[1] * pow( x[0], x[1]  1. ); 532 ok &= CppAD::NearEqual( dw[0], check, eps, eps );535 ok &= NearEqual( dw[0], check, eps, eps ); 533 536 534 537 check = log( x[0] ) * pow( x[0], x[1] ); 535 ok &= CppAD::NearEqual( dw[1], check, eps, eps );538 ok &= NearEqual( dw[1], check, eps, eps ); 536 539 537 540 check = 0.; 538 ok &= CppAD::NearEqual( dw[2], check, eps, eps );541 ok &= NearEqual( dw[2], check, eps, eps ); 539 542 540 543 return ok; … … 645 648 duplicate_fun(x, check, original, opt); 646 649 for(i = 0; i < m; i++) 647 ok &= (y[i] == check[i]);650 ok &= NearEqual(y[i], check[i], eps, eps); 648 651 649 652 // Check size before optimization … … 660 663 y = F.Forward(0, x); 661 664 for(i = 0; i < m; i++) 662 ok &= (y[i] == check[i]);665 ok &= NearEqual(y[i], check[i], eps, eps); 663 666 664 667 return ok; … … 936 939 x0[1] = 4.; 937 940 y0 = F.Forward(0, x0); 938 ok &= NearEqual(y0[0] , x0[0]+x0[0]+x0[1], 1e10, 1e10);941 ok &= NearEqual(y0[0] , x0[0]+x0[0]+x0[1], eps, eps); 939 942 940 943 // evaluate derivative of F in X[0] direction … … 944 947 x1[1] = 0.; 945 948 y1 = F.Forward(1, x1); 946 ok &= NearEqual(y1[0] , x1[0]+x1[0]+x1[1], 1e10, 1e10);949 ok &= NearEqual(y1[0] , x1[0]+x1[0]+x1[1], eps, eps); 947 950 948 951 // evaluate second derivative of F in X[0] direction … … 953 956 y2 = F.Forward(2, x2); 954 957 double F_00 = 2. * y2[0]; 955 ok &= NearEqual(F_00, 0., 1e10, 1e10);958 ok &= NearEqual(F_00, 0., eps, eps); 956 959 957 960 return ok; … … 985 988 x0[1] = 4.; 986 989 y0 = F.Forward(0, x0); 987 ok &= NearEqual(y0[0] , x0[0]x0[0]+x0[1], 1e10, 1e10);990 ok &= NearEqual(y0[0] , x0[0]x0[0]+x0[1], eps, eps); 988 991 989 992 // evaluate derivative of F … … 992 995 w[0] = 1.; 993 996 dF = F.Reverse(1, w); 994 ok &= NearEqual(dF[0] , 0., 1e10, 1e10);995 ok &= NearEqual(dF[1] , 1., 1e10, 1e10);997 ok &= NearEqual(dF[0] , 0., eps, eps); 998 ok &= NearEqual(dF[1] , 1., eps, eps); 996 999 997 1000 return ok;
Note: See TracChangeset
for help on using the changeset viewer.