<commit_before>#include <mex.h>

#include <stdlib.h>  // for win
#include <stdint.h>  // for win

/* barycentricInterpolation
 *  Looks up the indices and weighted coefficients for a barycentric
 * interpolation on an ndgrid:
 *  [indices, coefs, dcoefs] = barycentricInterpolation(bins, pts)
 *
 * @param bins is an m-element cell array with bins{i} describing the mesh
 *             discretization along dimention i.  Bin elements must be
 *             sorted in ascending order.
 * @param pts is an m-by-n matrix with m pts to be interpolated
 * @retval indices is a d-by-n list of indices into the ndarray, with
 *             element (i, j) being the ith interpolant of the point j.
 *             For triangulated interpolation (the only one implemented so
 *             far), d = m+1
 * @retval coefs is a d-by-n list of weights for each interpolant, such
 *             that, for instance, the original pts(:, i) could be
 *             reconstructed using
 *         pt(:, j) = sum_i coefs(i, j) * gridpoint(:, indices(i, j));
 *           aka pt(:, j) = gridpoint(:, indices(:, j))*coefs(:, j)
 * @retval dcoefs is a (d*n)-by-m matrix which is the gradient of coefs
 *              using the geval convention
 * Note that points off the grid are cropped to the closest point (in an
 * l0 sense) on the grid
 *
 * For a simple description of barycentric interpolation, see
 *  <NAME>, "Multidimensional Triangulation... ", NIPS, 1996
 */

/* helpers for qsort */
typedef struct {
  int dim;
  double fracway;
  double dfracway;
} bary;
int barycomp(const void* b1, const void* b2) {
  bary* bb1 = (bary*)b1, * bb2 = (bary*)b2;
  int order;
  if (bb1->fracway > bb2->fracway)
    order = 1;
  else if (bb1->fracway < bb2->fracway)
    order = -1;
  else
    order = 0;
  return order;
}

void mexFunction(int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[]) {
  if (nrhs < 2) {
    mexPrintf("Usage: [indices, coefs] = barycentricInterpolation(bins, pts)\n");
    return;
  }

  double* pts = mxGetPr(prhs[1]);

  int i, j;
  int m = static_cast<int>(mxGetM(prhs[1])),
      n = static_cast<int>(mxGetN(prhs[1])), d = m + 1;

  if (mxGetNumberOfElements(prhs[0]) != m)
    mexErrMsgIdAndTxt(
        "Drake:barycentricInterpolation:BadInput",
        "the number of bins must equal the dimension of the points");

  int* binsize = new int[m];
  double** bins = new double* [m];
  mxArray* pbin;
  int* nskip = new int[m];  // offsets for inline sub2ind
  for (i = 0; i < m; i++) {
    pbin = mxGetCell(prhs[0], i);
    binsize[i] = static_cast<int>(mxGetNumberOfElements(pbin));
    bins[i] = mxGetPr(pbin);
    if (i == 0)
      nskip[i] = 1;<commit_msg>Manually fix some overly-long line(s).<commit_after>#include <mex.h>

#include <stdlib.h>  // for win
#include <stdint.h>  // for win

/* barycentricInterpolation
 *  Looks up the indices and weighted coefficients for a barycentric
 * interpolation on an ndgrid:
 *  [indices, coefs, dcoefs] = barycentricInterpolation(bins, pts)
 *
 * @param bins is an m-element cell array with bins{i} describing the mesh
 *             discretization along dimention i.  Bin elements must be
 *             sorted in ascending order.
 * @param pts is an m-by-n matrix with m pts to be interpolated
 * @retval indices is a d-by-n list of indices into the ndarray, with
 *             element (i, j) being the ith interpolant of the point j.
 *             For triangulated interpolation (the only one implemented so
 *             far), d = m+1
 * @retval coefs is a d-by-n list of weights for each interpolant, such
 *             that, for instance, the original pts(:, i) could be
 *             reconstructed using
 *         pt(:, j) = sum_i coefs(i, j) * gridpoint(:, indices(i, j));
 *           aka pt(:, j) = gridpoint(:, indices(:, j))*coefs(:, j)
 * @retval dcoefs is a (d*n)-by-m matrix which is the gradient of coefs
 *              using the geval convention
 * Note that points off the grid are cropped to the closest point (in an
 * l0 sense) on the grid
 *
 * For a simple description of barycentric interpolation, see
 *  <NAME>, "Multidimensional Triangulation... ", NIPS, 1996
 */

/* helpers for qsort */
typedef struct {
  int dim;
  double fracway;
  double dfracway;
} bary;
int barycomp(const void* b1, const void* b2) {
  bary* bb1 = (bary*)b1, * bb2 = (bary*)b2;
  int order;
  if (bb1->fracway > bb2->fracway)
    order = 1;
  else if (bb1->fracway < bb2->fracway)
    order = -1;
  else
    order = 0;
  return order;
}

void mexFunction(int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[]) {
  if (nrhs < 2) {
    mexPrintf(
        "Usage: [indices, coefs] = barycentricInterpolation(bins, pts)\n");
    return;
  }

  double* pts = mxGetPr(prhs[1]);

  int i, j;
  int m = static_cast<int>(mxGetM(prhs[1])),
      n = static_cast<int>(mxGetN(prhs[1])), d = m + 1;

  if (mxGetNumberOfElements(prhs[0]) != m)
    mexErrMsgIdAndTxt(
        "Drake:barycentricInterpolation:BadInput",
        "the number of bins must equal the dimension of the points");

  int* binsize = new int[m];
  double** bins = new double* [m];
  mxArray* pbin;
  int* nskip = new int[m];  // offsets for inline sub2ind
  for (i = 0; i < m; i++) {
    pbin = mxGetCell(prhs[0], i);
    binsize[i] = static_cast<int>(mxGetNumberOfElements(pbin));
    bins[i] = mxGetPr(pbin);
    if (i == 0)
      nskip[i] = 1;
{'fraction_non_alphanumeric': 0.12602230483271376, 'fraction_numerical': 0.011152416356877323, 'mean_word_length': 2.904934687953556, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 27, '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': '2219587', 'n_tokens_mistral': 1965, 'n_tokens_neox': 1864, 'n_words': 632}