| 85 | } |
| 86 | |
| 87 | bool forward_active(void) |
| 88 | { bool ok = true; |
| 89 | using CppAD::AD; |
| 90 | using CppAD::NearEqual; |
| 91 | double eps10 = 10.0 * std::numeric_limits<double>::epsilon(); |
| 92 | |
| 93 | // domain space vector |
| 94 | size_t n = 3; |
| 95 | CPPAD_TESTVECTOR(AD<double>) ax(n); |
| 96 | ax[0] = 0.5; |
| 97 | ax[1] = 1.5; |
| 98 | ax[2] = 2.0; |
| 99 | |
| 100 | // declare independent variables and start tape recording |
| 101 | CppAD::Independent(ax); |
| 102 | |
| 103 | // range space vector |
| 104 | size_t m = 1; |
| 105 | CPPAD_TESTVECTOR(AD<double>) ay(m); |
| 106 | tape_size before, after; |
| 107 | fun(ax, ay, before, after); |
| 108 | |
| 109 | // create f: x -> y and stop tape recording |
| 110 | CppAD::ADFun<double> f(ax, ay); |
| 111 | ok &= f.size_order() == 1; // this constructor does 0 order forward |
| 112 | ok &= f.size_var() == before.n_var; |
| 113 | ok &= f.size_op() == before.n_op; |
| 114 | |
| 115 | // Optimize the operation sequence |
| 116 | // Note that, for this case, all the optimization was done during |
| 117 | // the recording and there is no benefit to the optimization. |
| 118 | f.optimize(); |
| 119 | ok &= f.size_order() == 0; // 0 order forward not present |
| 120 | ok &= f.size_var() == after.n_var; |
| 121 | ok &= f.size_op() == after.n_op; |
| 122 | |
| 123 | // check zero order forward with different argument value |
| 124 | CPPAD_TESTVECTOR(double) x(n), y(m), check(m); |
| 125 | for(size_t i = 0; i < n; i++) |
| 126 | x[i] = double(i + 2); |
| 127 | y = f.Forward(0, x); |
| 128 | fun(x, check, before, after); |
| 129 | ok &= NearEqual(y[0], check[0], eps10, eps10); |
| 130 | |
| 131 | return ok; |
| 132 | } |
| 133 | // END C++ |
nothing calls this directly
no test coverage detected