<commit_before>// This file is part of Eigen, a lightweight C++ template library
// for linear algebra.
//
// Copyright (C) 2009 <NAME> <<EMAIL>>

#include <stdio.h>

#include "main.h"
#include <unsupported/Eigen/NonLinear>

int fcn_chkder(int /*m*/, int /*n*/, const double *x, double *fvec, double *fjac, int ldfjac, int iflag)
{
    /*      subroutine fcn for chkder example. */

    int i;
    double tmp1, tmp2, tmp3, tmp4;
    double y[15]={1.4e-1, 1.8e-1, 2.2e-1, 2.5e-1, 2.9e-1, 3.2e-1, 3.5e-1,
        3.9e-1, 3.7e-1, 5.8e-1, 7.3e-1, 9.6e-1, 1.34, 2.1, 4.39};


    if (iflag == 0) 
        return 0;

    if (iflag != 2) 
        for (i=1; i<=15; i++) {
            tmp1 = i;
            tmp2 = 16 - i;
            tmp3 = tmp1;
            if (i > 8) tmp3 = tmp2;
            fvec[i-1] = y[i-1] - (x[1-1] + tmp1/(x[2-1]*tmp2 + x[3-1]*tmp3));
        }
    else {
        for (i = 1; i <= 15; i++) {
            tmp1 = i;
            tmp2 = 16 - i;

            /* error introduced into next statement for illustration. */
            /* corrected statement should read    tmp3 = tmp1 . */

            tmp3 = tmp2;
            if (i > 8) tmp3 = tmp2;
            tmp4 = (x[2-1]*tmp2 + x[3-1]*tmp3); tmp4=tmp4*tmp4;
            fjac[i-1+ ldfjac*(1-1)] = -1.;
            fjac[i-1+ ldfjac*(2-1)] = tmp1*tmp2/tmp4;
            fjac[i-1+ ldfjac*(3-1)] = tmp1*tmp3/tmp4;
        }
    }
    return 0;
}

void testChkder()
{
  const int m=15, n=3;
  VectorXd x(n), fvec(m), xp, fvecp(m), err;
  MatrixXd fjac(m,n);
  VectorXi ipvt;

  /*      the following values should be suitable for */
  /*      checking the jacobian matrix. */
  x << 9.2e-1, 1.3e-1, 5.4e-1;

  ei_chkder(x, fvec, fjac, xp, fvecp, 1, err);
  fcn_chkder(m, n, x.data(), fvec.data(), fjac.data(), m, 1);
  fcn_chkder(m, n, x.data(), fvec.data(), fjac.data(), m, 2);
  fcn_chkder(m, n, xp.data(), fvecp.data(), fjac.data(), m, 1);
  ei_chkder(x, fvec, fjac, xp, fvecp, 2, err);

  fvecp -= fvec;

  // check those
  VectorXd fvec_ref(m), fvecp_ref(m), err_ref(m);
  fvec_ref <<
      -1.181606, -1.429655, -1.606344,
      -1.745269, -1.840654, -1.921586,
      -1.984141, -2.022537, -2.468977,
      -2.827562, -3.473582, -4.437612,
      -6.047662, -9.267761, -18.91806;
  fvecp_ref <<
      -7.724666e-09, -3.432406e-09, -2.034843e-10,<commit_msg>fix bounds using c standard instead of fortran's<commit_after>// This file is part of Eigen, a lightweight C++ template library
// for linear algebra.
//
// Copyright (C) 2009 <NAME> <<EMAIL>>

#include <stdio.h>

#include "main.h"
#include <unsupported/Eigen/NonLinear>

int fcn_chkder(int /*m*/, int /*n*/, const double *x, double *fvec, double *fjac, int ldfjac, int iflag)
{
    /*      subroutine fcn for chkder example. */

    int i;
    double tmp1, tmp2, tmp3, tmp4;
    double y[15]={1.4e-1, 1.8e-1, 2.2e-1, 2.5e-1, 2.9e-1, 3.2e-1, 3.5e-1,
        3.9e-1, 3.7e-1, 5.8e-1, 7.3e-1, 9.6e-1, 1.34, 2.1, 4.39};


    if (iflag == 0) 
        return 0;

    if (iflag != 2) 
        for (i=0; i<15; i++) {
            tmp1 = i+1;
            tmp2 = 16-i-1;
            tmp3 = tmp1;
            if (i >= 8) tmp3 = tmp2;
            fvec[i] = y[i] - (x[0] + tmp1/(x[1]*tmp2 + x[2]*tmp3));
        }
    else {
        for (i = 0; i < 15; i++) {
            tmp1 = i+1;
            tmp2 = 16-i-1;

            /* error introduced into next statement for illustration. */
            /* corrected statement should read    tmp3 = tmp1 . */

            tmp3 = tmp2;
            if (i >= 8) tmp3 = tmp2;
            tmp4 = (x[1]*tmp2 + x[2]*tmp3); tmp4=tmp4*tmp4;
            fjac[i+ ldfjac*(0)] = -1.;
            fjac[i+ ldfjac*(1)] = tmp1*tmp2/tmp4;
            fjac[i+ ldfjac*(2)] = tmp1*tmp3/tmp4;
        }
    }
    return 0;
}


void testChkder()
{
  const int m=15, n=3;
  VectorXd x(n), fvec(m), xp, fvecp(m), err;
  MatrixXd fjac(m,n);
  VectorXi ipvt;

  /*      the following values should be suitable for */
  /*      checking the jacobian matrix. */
  x << 9.2e-1, 1.3e-1, 5.4e-1;

  ei_chkder(x, fvec, fjac, xp, fvecp, 1, err);
  fcn_chkder(m, n, x.data(), fvec.data(), fjac.data(), m, 1);
  fcn_chkder(m, n, x.data(), fvec.data(), fjac.data(), m, 2);
  fcn_chkder(m, n, xp.data(), fvecp.data(), fjac.data(), m, 1);
  ei_chkder(x, fvec, fjac, xp, fvecp, 2, err);

  fvecp -= fvec;

  // check those
  VectorXd fvec_ref(m), fvecp_ref(m), err_ref(m);
  fvec_ref <<
      -1.181606, -1.429655, -1.606344,
      -1.745269, -1.840654, -1.921586,
      -1.984141, -2.022537, -2.468977,
      -2.827562, -3.473582, -4.437612,
      -6.047662, -9.267761, -18.91806;
  fvecp_ref <<
      -7.724666e-09, -3.432406e-09, -2.034843e-10,
{'fraction_non_alphanumeric': 0.192274678111588, 'fraction_numerical': 0.11394849785407725, 'mean_word_length': 1.935138539042821, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 18, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2244896', 'n_tokens_mistral': 2369, 'n_tokens_neox': 2098, 'n_words': 484}