MCPcopy Create free account
hub / github.com/cvanaret/Uno / evaluate_objective_gradient

Method evaluate_objective_gradient

interfaces/Python/cpp_classes/PythonModel.cpp:82–97  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

80 }
81
82 void PythonModel::evaluate_objective_gradient(const Vector<double>& x, Vector<double>& gradient) const {
83 if (this->user_model.objective_gradient.has_value()) {
84 const auto x_py = to_const_array(x.data(), this->number_variables);
85 auto gradient_py = to_array(gradient.data(), this->number_variables);
86
87 // evaluate objective gradient
88 try {
89 (*this->user_model.objective_gradient)(x_py, gradient_py);
90 view(gradient, 0, this->number_variables).scale(this->optimization_sense);
91 ++this->number_model_evaluations.objective_gradient;
92 }
93 catch (const std::exception&) {
94 throw GradientEvaluationError();
95 }
96 }
97 }
98
99 void PythonModel::compute_jacobian_sparsity(uno_int * row_indices, uno_int * column_indices, uno_int row_offset,
100 uno_int column_offset, uno_int solver_indexing, MatrixOrder /*matrix_format*/) const {

Callers

nothing calls this directly

Calls 6

to_const_arrayFunction · 0.85
to_arrayFunction · 0.85
viewFunction · 0.85
dataMethod · 0.45
scaleMethod · 0.45

Tested by

no test coverage detected