------------------------------------------------------------------------
| 41 | typedef CppAD::sparse_rcv<s_vector, d_vector> sparse_matrix; |
| 42 | // ------------------------------------------------------------------------ |
| 43 | void create_fun( |
| 44 | const d_vector& x , |
| 45 | const s_vector& row , |
| 46 | const s_vector& col , |
| 47 | CppAD::ADFun<double>& fun ) |
| 48 | { |
| 49 | // initialize a1double version of independent variables |
| 50 | size_t n = x.size(); |
| 51 | a1vector a1x(n); |
| 52 | for(size_t j = 0; j < n; j++) |
| 53 | a1x[j] = x[j]; |
| 54 | // |
| 55 | // optimization options |
| 56 | std::string optimize_options = |
| 57 | "no_conditional_skip no_compare_op no_print_for_op"; |
| 58 | if( global_option["val_graph"] ) |
| 59 | optimize_options += " val_graph"; |
| 60 | // |
| 61 | // order of derivative in sparse_hes_fun |
| 62 | size_t order = 0; |
| 63 | // |
| 64 | // do not even record comparison operators |
| 65 | size_t abort_op_index = 0; |
| 66 | bool record_compare = false; |
| 67 | // |
| 68 | if( ! global_option["hes2jac"] ) |
| 69 | { |
| 70 | // declare independent variables |
| 71 | Independent(a1x, abort_op_index, record_compare); |
| 72 | // |
| 73 | // AD computation of y |
| 74 | a1vector a1y(1); |
| 75 | CppAD::sparse_hes_fun<a1double>(n, a1x, row, col, order, a1y); |
| 76 | // |
| 77 | // create function object f : X -> Y |
| 78 | fun.Dependent(a1x, a1y); |
| 79 | // |
| 80 | if( global_option["optimize"] ) |
| 81 | fun.optimize(optimize_options); |
| 82 | // |
| 83 | // skip comparison operators |
| 84 | fun.compare_change_count(0); |
| 85 | // |
| 86 | // fun corresponds to f(x) |
| 87 | return; |
| 88 | } |
| 89 | // declare independent variables for f(x) |
| 90 | a2vector a2x(n); |
| 91 | for(size_t j = 0; j < n; j++) |
| 92 | a2x[j] = a1x[j]; |
| 93 | Independent(a2x, abort_op_index, record_compare); |
| 94 | // |
| 95 | // a2double computation of y |
| 96 | a2vector a2y(1); |
| 97 | CppAD::sparse_hes_fun<a2double>(n, a2x, row, col, order, a2y); |
| 98 | // |
| 99 | // create function object corresponding to y = f(x) |
| 100 | CppAD::ADFun<a1double> a1f; |
no test coverage detected