Changeset 3371 for trunk/test_more
 Timestamp:
 Sep 28, 2014 7:40:49 AM (5 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

trunk/test_more/optimize.cpp
r3368 r3371 1458 1458 } 1459 1459 //  1460 // Test bug where atomic functions were not properly conditionally skipped.1461 1460 void i_algo( 1462 1461 const CppAD::vector< CppAD::AD<double> >& ax , 1463 1462 CppAD::vector< CppAD::AD<double> >& ay ) 1464 1463 { ay[0] = 1.0 / ax[0]; } 1465 1464 // 1465 // Test bug where atomic functions were not properly conditionally skipped. 1466 1466 bool cond_exp_skip_atomic(void) 1467 1467 { bool ok = true; … … 1502 1502 ok &= y_before[0] == y_after[0]; 1503 1503 1504 return ok; 1505 } 1506 // 1507 // Test bug where conditional dependence did not pass through 1508 // atomic functions 1509 bool cond_exp_atomic_dependence(void) 1510 { bool ok = true; 1511 using CppAD::AD; 1512 using CppAD::vector; 1513 1514 // Create a checkpoint version of the function i_algo 1515 vector< AD<double> > au(1), av(1), aw(1); 1516 au[0] = 1.0; 1517 CppAD::checkpoint<double> i_check("i_check", i_algo, au, av); 1518 1519 vector< AD<double> > ax(2), ay(1); 1520 AD<double> zero = 0.0; 1521 ax[0] = 1.0; 1522 ax[1] = 1.0; 1523 Independent(ax); 1524 av[0] = ax[0] + ax[1]; 1525 i_check(av, aw); 1526 ay[0] = CondExpGt(aw[0], zero, zero, aw[0]); 1527 CppAD::ADFun<double> f; 1528 f.Dependent(ax, ay); 1529 1530 // run case that skips the second call to afun 1531 // (but not for order zero) 1532 vector<double> x(2), y_before(1), y_after(1); 1533 vector<double> dx(2), dy_before(1), dy_after(1); 1534 x[0] = 1.0; 1535 x[1] = 1.0; 1536 y_before = f.Forward(0, x); 1537 dx[0] = 2.0; 1538 dx[1] = 2.0; 1539 dy_before = f.Forward(1, dx); 1540 f.optimize(); 1541 y_after = f.Forward(0, x); 1542 dy_after = f.Forward(1, dx); 1543 1544 ok &= y_before[0] == y_after[0]; 1545 ok &= dy_before[0] == dy_after[0]; 1546 1504 1547 return ok; 1505 1548 } … … 1551 1594 // check conditional skip of an atomic function 1552 1595 ok &= cond_exp_skip_atomic(); 1596 // check conditional dependence through atomic function 1597 ok &= cond_exp_atomic_dependence(); 1553 1598 // 1554 1599 CppAD::user_atomic<double>::clear();
Note: See TracChangeset
for help on using the changeset viewer.