<commit_before>#include "drake/solvers/NloptSolver.h"

#include <stdexcept>
#include <list>
#include <vector>

#include <nlopt.hpp>

#include "drake/common/drake_assert.h"
#include "drake/core/Gradient.h"
#include "drake/solvers/Optimization.h"

using Drake::TaylorVecXd;

namespace drake {
namespace solvers {

namespace {
Eigen::VectorXd MakeEigenVector(const std::vector<double>& x) {
  Eigen::VectorXd xvec(x.size());
  for (size_t i = 0; i < x.size(); i++) {
    xvec[i] = x[i];
  }
  return xvec;
}

TaylorVecXd MakeInputTaylorVec(const Eigen::VectorXd& xvec,
                               const VariableList& variable_list) {
  size_t var_count = 0;
  for (const DecisionVariableView& v : variable_list) {
    var_count += v.size();
  }

  auto tx = Drake::initializeAutoDiff(xvec);
  TaylorVecXd this_x(var_count);
  size_t index = 0;
  for (const DecisionVariableView& v : variable_list) {
      this_x.segment(index, v.size()) = tx.segment(v.index(), v.size());
      index += v.size();
    }
  return this_x;
}

// This function meets the signature requirements for nlopt::vfunc as
// described in
// http://ab-initio.mit.edu/wiki/index.php/NLopt_C-plus-plus_Reference#Objective_function
double EvaluateCosts(const std::vector<double>& x,
                     std::vector<double>& grad,
                     void* f_data) {
  const OptimizationProblem* prog =
      reinterpret_cast<const OptimizationProblem*>(f_data);<commit_msg>additional comment added<commit_after>#include "drake/solvers/NloptSolver.h"

#include <stdexcept>
#include <list>
#include <vector>

#include <nlopt.hpp>

#include "drake/common/drake_assert.h"
#include "drake/core/Gradient.h"
#include "drake/solvers/Optimization.h"

using Drake::TaylorVecXd;

namespace drake {
namespace solvers {

namespace {
Eigen::VectorXd MakeEigenVector(const std::vector<double>& x) {
  Eigen::VectorXd xvec(x.size());
  for (size_t i = 0; i < x.size(); i++) {
    xvec[i] = x[i];
  }
  return xvec;
}

TaylorVecXd MakeInputTaylorVec(const Eigen::VectorXd& xvec,
                               const VariableList& variable_list) {
  size_t var_count = 0;
  for (const DecisionVariableView& v : variable_list) {
    var_count += v.size();
  }

  auto tx = Drake::initializeAutoDiff(xvec);
  TaylorVecXd this_x(var_count);
  size_t index = 0;
  for (const DecisionVariableView& v : variable_list) {
      this_x.segment(index, v.size()) = tx.segment(v.index(), v.size());
      index += v.size();
    }
  return this_x;
}

// This function meets the signature requirements for nlopt::vfunc as
// described in
// http://ab-initio.mit.edu/wiki/index.php/NLopt_C-plus-plus_Reference#Objective_function
// Note : NLopt uses the term "Objective" which corresponds to the Drake usage
// of "Cost".
double EvaluateCosts(const std::vector<double>& x,
                     std::vector<double>& grad,
                     void* f_data) {
  const OptimizationProblem* prog =
      reinterpret_cast<const OptimizationProblem*>(f_data);
{'fraction_non_alphanumeric': 0.13444816053511705, 'fraction_numerical': 0.002006688963210702, 'mean_word_length': 3.6661466458658345, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4201408', 'n_tokens_mistral': 1062, 'n_tokens_neox': 1015, 'n_words': 221}