Changeset 3494 for trunk/test_more
 Timestamp:
 Dec 22, 2014 9:10:44 AM (5 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

trunk/test_more/optimize.cpp
r3373 r3494 1583 1583 ok &= dx[j] == 0.0; 1584 1584 } 1585 return ok; 1586 } 1587 // Test case where an expression depends on both the true 1588 // and false cases (bug fixed 20141222) 1589 bool cond_exp_both_true_and_false(void) 1590 { bool ok = true; 1591 using CppAD::vector; 1592 using CppAD::AD; 1593 1594 // f(x) = x[0] + x[0] if x[0] >= 3 1595 // = x[0] + x[1] otherwise 1596 vector< AD<double> > ax(2), ay(1); 1597 ax[0] = 1.0; 1598 ax[1] = 2.0; 1599 Independent(ax); 1600 AD<double> three(3); 1601 AD<double> value = ax[0] + ax[1]; 1602 ay[0] = CppAD::CondExpGe(ax[0], three, value, value); 1603 CppAD::ADFun<double> f(ax, ay); 1604 f.optimize(); 1605 1606 // check case where x[0] >= 3 1607 vector<double> x(2), y(1); 1608 x[0] = 4.0; 1609 x[1] = 2.0; 1610 y = f.Forward(0, x); 1611 ok &= y[0] == x[0] + x[1]; 1612 1613 // check case where x[0] < 3 1614 x[0] = 1.0; 1615 x[1] = 2.0; 1616 y = f.Forward(0, x); 1617 ok &= y[0] == x[0] + x[1]; 1618 1585 1619 return ok; 1586 1620 } … … 1635 1669 // check reverse mode conditional skipping 1636 1670 ok &= cond_exp_reverse(); 1671 // check case where an expresion needed by both true and false case 1672 ok &= cond_exp_both_true_and_false(); 1637 1673 // 1638 1674 CppAD::user_atomic<double>::clear();
Note: See TracChangeset
for help on using the changeset viewer.