@@ -147,8 +147,6 @@ struct CallbackEvaluator
147147 std::vector<KNINT> indexCons;
148148
149149 CppAD::ADFun<V> fun;
150-
151- std::vector<size_t > fun_rows;
152150 CppAD::sparse_rc<std::vector<size_t >> jac_pattern_;
153151 CppAD::sparse_rcv<std::vector<size_t >, std::vector<V>> jac_;
154152 CppAD::sparse_jac_work jac_work_;
@@ -163,11 +161,10 @@ struct CallbackEvaluator
163161 void setup ()
164162 {
165163 fun.optimize ();
166- CppAD::sparse_rc<std::vector<size_t >> jac_pattern_in (fun.Range (), fun_rows.size (),
167- fun_rows.size ());
168- for (size_t k = 0 ; k < fun_rows.size (); k++)
164+ CppAD::sparse_rc<std::vector<size_t >> jac_pattern_in (fun.Range (), fun.Range (), fun.Range ());
165+ for (size_t k = 0 ; k < fun.Range (); k++)
169166 {
170- jac_pattern_in.set (k, fun_rows[k], fun_rows[k] );
167+ jac_pattern_in.set (k, k, k );
171168 }
172169 fun.rev_jac_sparsity (jac_pattern_in, false , false , true , jac_pattern_);
173170 jac_pattern_in.resize (fun.Domain (), fun.Domain (), fun.Domain ());
@@ -177,11 +174,7 @@ struct CallbackEvaluator
177174 }
178175 CppAD::sparse_rc<std::vector<size_t >> jac_pattern_out;
179176 fun.for_jac_sparsity (jac_pattern_in, false , false , true , jac_pattern_out);
180- std::vector<bool > select_rows (fun.Range (), false );
181- for (size_t k = 0 ; k < fun_rows.size (); k++)
182- {
183- select_rows[fun_rows[k]] = true ;
184- }
177+ std::vector<bool > select_rows (fun.Range (), true );
185178 fun.rev_hes_sparsity (select_rows, false , true , hess_pattern_);
186179 for (size_t k = 0 ; k < hess_pattern_.nnz (); k++)
187180 {
@@ -205,15 +198,15 @@ struct CallbackEvaluator
205198 x[i] = req_x[indexVars[i]];
206199 }
207200 auto y = fun.Forward (0 , x);
208- for (size_t k = 0 ; k < fun_rows. size (); k++)
201+ for (size_t k = 0 ; k < fun. Range (); k++)
209202 {
210203 if (aggregate)
211204 {
212- res_y[0 ] += y[fun_rows[k] ];
205+ res_y[0 ] += y[k ];
213206 }
214207 else
215208 {
216- res_y[k] = y[fun_rows[k] ];
209+ res_y[k] = y[k ];
217210 }
218211 }
219212 }
@@ -238,15 +231,15 @@ struct CallbackEvaluator
238231 {
239232 x[i] = req_x[indexVars[i]];
240233 }
241- for (size_t k = 0 ; k < fun_rows. size (); k++)
234+ for (size_t k = 0 ; k < fun. Range (); k++)
242235 {
243236 if (aggregate)
244237 {
245- w[fun_rows[k] ] = req_w[0 ];
238+ w[k ] = req_w[0 ];
246239 }
247240 else
248241 {
249- w[fun_rows[k] ] = req_w[indexCons[k]];
242+ w[k ] = req_w[indexCons[k]];
250243 }
251244 }
252245 fun.sparse_hes (x, w, hess_, hess_pattern_, hess_coloring_, hess_work_);
@@ -696,14 +689,12 @@ class KNITROModel : public OnesideLinearConstraintMixin<KNITROModel>,
696689 }
697690
698691 template <typename T, typename F, typename G, typename H>
699- void _add_callback_impl (const ExpressionGraph &graph, const std::vector<size_t > &rows,
700- const std::vector<ConstraintIndex> cons, const T &trace, const F f,
701- const G g, const H h)
692+ void _add_callback_impl (const ExpressionGraph &graph, const std::vector<ConstraintIndex> cons,
693+ const T &trace, const F f, const G g, const H h)
702694 {
703695 auto evaluator_ptr = std::make_unique<CallbackEvaluator<double >>();
704696 auto *evaluator = evaluator_ptr.get ();
705697 evaluator->fun = trace (graph);
706- evaluator->fun_rows = rows;
707698 evaluator->indexVars .resize (graph.n_variables ());
708699 for (size_t i = 0 ; i < graph.n_variables (); i++)
709700 {
0 commit comments