Esempio n. 1
0
linearOffsetMatcher::linearOffsetMatcher(
	int nFaces_,int nPer,const int *facesA,const int *facesB,int idxBase,
	int nNodes_,const CkVector3d *nodeLocs):
	a(nFaces_,nPer,facesA,idxBase,nodeLocs),
	b(nFaces_,nPer,facesB,idxBase,nodeLocs),
	nNodes(nNodes_),nFaces(nFaces_)
{
	//Compute the offset from A to B by taking the difference of their centroids:
	CkVector3d a_sum(0.0), b_sum(0.0);
	for (int f=0;f<nFaces;f++) {
		a_sum+=a.getFaceLoc(f); 
		b_sum+=b.getFaceLoc(f);
	}
	a2b_del=(b_sum-a_sum)*(1.0/nFaces);
	
	//Derive the matching tolerance from the edge length (for either face set)
	minTol=a.getMinEdgeLength()*0.001;
}
/*
 * fft_bandpower_calculate
 *    data: the signal of 1 dimension vector
 *    Fs: the frequency provide
 *    band: the band provided, should have upper and lower bound
 * Arguments    : const double data[256]
 *                double Fs
 *                double band[2]
 *                double *totalpower
 *                double *pband
 * Return Type  : void
 */
void fft_bandpower_calculate(const double data[256], double Fs, double band[2],
  double *totalpower, double *pband)
{
  creal_T A[256];
  double y;
  double f[129];
  int i;
  creal_T b_A[256];
  creal_T c_A[129];
  double c_power[129];
  boolean_T bv0[129];
  boolean_T bv1[129];
  double dv0[129];
  unsigned char tmp_data[129];
  int trueCount;
  int partialTrueCount;
  double power_data[129];
  int power_size[2];
  int tmp_size[2];
  double b_tmp_data[129];

  /*  get of the data */
  fft(data, A);
  y = Fs / 2.0;
  linspace(f);
  for (i = 0; i < 129; i++) {
    f[i] *= y;
  }

  for (i = 0; i < 256; i++) {
    if (A[i].im == 0.0) {
      b_A[i].re = A[i].re / 256.0;
      b_A[i].im = 0.0;
    } else if (A[i].re == 0.0) {
      b_A[i].re = 0.0;
      b_A[i].im = A[i].im / 256.0;
    } else {
      b_A[i].re = A[i].re / 256.0;
      b_A[i].im = A[i].im / 256.0;
    }
  }

  memcpy(&c_A[0], &b_A[0], 129U * sizeof(creal_T));
  b_abs(c_A, c_power);
  for (i = 0; i < 129; i++) {
    c_power[i] *= 2.0;
  }

  /*  see if band power is in side the frequency range */
  if (band[1] > f[128]) {
    band[1] = f[128];
  }

  if (band[0] < f[0]) {
    /*  if the band lower bound is less than f(1) */
    band[0] = f[0];
  }

  for (i = 0; i < 129; i++) {
    bv0[i] = (f[i] >= band[0]);
    bv1[i] = (f[i] <= band[1]);
  }

  power(c_power, dv0);
  *totalpower = sum(dv0);
  trueCount = 0;
  for (i = 0; i < 129; i++) {
    if (bv0[i] && bv1[i]) {
      trueCount++;
    }
  }

  partialTrueCount = 0;
  for (i = 0; i < 129; i++) {
    if (bv0[i] && bv1[i]) {
      tmp_data[partialTrueCount] = (unsigned char)(i + 1);
      partialTrueCount++;
    }
  }

  power_size[0] = 1;
  power_size[1] = trueCount;
  for (i = 0; i < trueCount; i++) {
    power_data[i] = c_power[tmp_data[i] - 1];
  }

  b_power(power_data, power_size, b_tmp_data, tmp_size);
  *pband = b_sum(b_tmp_data, tmp_size);
}
Esempio n. 3
0
bool CartoonEngine::Convert2Painting(int neighbor, int levels) {
  if ((image_.empty()) || (CV_8UC3 != image_.type()))
    return false;
  
  // Resize image for fast processing.
  cv::Size2i small_size(cols_, rows_);
  cv::Mat img = image_;
  if ((rows_ > 300) || (cols_ > 300)) {
    if (rows_ > cols_) {
      small_size.height = 300;
      small_size.width =
      static_cast<int>(300 * (static_cast<float>(cols_) / rows_));
    } else {
      small_size.width = 300;
      small_size.height =
      static_cast<int>(300 * (static_cast<float>(rows_) / cols_));
    }
    cv::resize(img, img, small_size);
  }
  painting_.create(small_size.height, small_size.width, CV_8UC3);
  vector<int> hist(levels, 0);
  vector<int> b_sum(levels, 0);
  vector<int> g_sum(levels, 0);
  vector<int> r_sum(levels, 0);
  
  for (int r = 0; r < small_size.height; ++r) {
    for (int c = 0; c < small_size.width; ++c) {
      for (int i = 0; i < levels; ++i) {
        hist[i] = 0;
        b_sum[i] = g_sum[i] = r_sum[i] = 0;
      }
      int r_start = std::max(0, r - neighbor);
      int r_end = std::min(small_size.height, r + neighbor);
      int c_start = std::max(0, c - neighbor);
      int c_end = std::min(small_size.width, c + neighbor);
      for (int rr = r_start; rr < r_end; ++rr) {
        for (int cc = c_start; cc < c_end; ++cc) {
          cv::Vec3b pixel = img.at<cv::Vec3b>(rr, cc);
          int ind = static_cast<int>((pixel[0] + pixel[1] + pixel[2]) / 3) * (levels - 1) / 255;
          ++hist[ind];
          b_sum[ind] += static_cast<int>(pixel[0]);
          g_sum[ind] += static_cast<int>(pixel[1]);
          r_sum[ind] += static_cast<int>(pixel[2]);
        }
      }
      
      int new_ind = 0;
      int cur_max = hist[0];
      for (int l = 1; l < levels; ++l) {
        if (hist[l] > hist[new_ind]) {
          new_ind = l;
          cur_max = hist[l];
        }
      }
      
      painting_.at<cv::Vec3b>(r, c)[0] =
      static_cast<uchar>(b_sum[new_ind] / cur_max);
      painting_.at<cv::Vec3b>(r, c)[1] =
      static_cast<uchar>(g_sum[new_ind] / cur_max);
      painting_.at<cv::Vec3b>(r, c)[2] =
      static_cast<uchar>(r_sum[new_ind] / cur_max);
    }
  }
  if (small_size.width != cols_) {
    cv::resize(painting_, painting_, cv::Size2i(cols_, rows_));
  }
  return true;
}
Esempio n. 4
0
/*
 * function [lp]=gaussmixp(y,m,v,w)
 *  y = cat(1, testSamples(1).mfcc{:});
 *  m = gmm.M;
 *  v = gmm.V;
 *  w = gmm.W;
 */
void gaussmixp(const real_T y[2004], const real_T m[108], const real_T v[108],
               const real_T w[9], real_T lp[167])
{
  real_T b[108];
  real_T dv0[108];
  real_T b_b[9];
  real_T lvm[9];
  int32_T ix;
  real_T mx[167];
  real_T kk[1503];
  real_T km[1503];
  static real_T b_y[18036];
  int32_T iy;
  real_T dv1[18036];
  real_T x[1503];
  int32_T i;
  int32_T ixstart;
  int32_T ixstop;
  real_T mtmp;
  int32_T b_ix;
  boolean_T exitg1;
  real_T ps[167];

  /* GAUSSMIXP calculate probability densities from a Gaussian mixture model */
  /*  */
  /*  Inputs: n data values, k mixtures, p parameters, q data vector size */
  /*  */
  /*    Y(n,q) = input data */
  /*    M(k,p) = mixture means for x(p) */
  /*    V(k,p) or V(p,p,k) variances (diagonal or full) */
  /*    W(k,1) = weights */
  /*    A(q,p), B(q) = transformation: y=x*a'+b' (where y and x are row vectors) */
  /*             if A is omitted, it is assumed to be the first q rows of the */
  /*             identity matrix. B defaults to zero. */
  /*    Note that most commonly, q=p and A and B are omitted entirely. */
  /*  */
  /*  Outputs */
  /*  */
  /*   LP(n,1) = log probability of each data point */
  /*   RP(n,k) = relative probability of each mixture */
  /*   KH(n,1) = highest probability mixture */
  /*   KP(n,1) = relative probability of highest probability mixture */
  /*       Copyright (C) Mike Brookes 2000-2009 */
  /*       Version: $Id: gaussmixp.m,v 1.3 2009/04/08 07:51:21 dmb Exp $ */
  /*  */
  /*    VOICEBOX is a MATLAB toolbox for speech processing. */
  /*    Home page: http://www.ee.ic.ac.uk/hp/staff/dmb/voicebox/voicebox.html */
  /*  */
  /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% */
  /*    This program is free software; you can redistribute it and/or modify */
  /*    it under the terms of the GNU General Public License as published by */
  /*    the Free Software Foundation; either version 2 of the License, or */
  /*    (at your option) any later version. */
  /*  */
  /*    This program is distributed in the hope that it will be useful, */
  /*    but WITHOUT ANY WARRANTY; without even the implied warranty of */
  /*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the */
  /*    GNU General Public License for more details. */
  /*  */
  /*    You can obtain a copy of the GNU General Public License from */
  /*    http://www.gnu.org/copyleft/gpl.html or by writing to */
  /*    Free Software Foundation, Inc.,675 Mass Ave, Cambridge, MA 02139, USA. */
  /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% */
  /* 'gaussmixp:49' [n,q]=size(y); */
  /* 'gaussmixp:50' [k,p]=size(m); */
  /* 'gaussmixp:51' memsize=voicebox('memsize'); */
  voicebox();

  /*  set memory size to use */
  /* 'gaussmixp:53' lp=zeros(n,1); */
  memset((void *)&lp[0], 0, 167U * sizeof(real_T));

  /* 'gaussmixp:54' wk=ones(k,1); */
  /* 'gaussmixp:56' vi=-0.5*v.^(-1); */
  power(v, b);

  /*  data-independent scale factor in exponent */
  /* 'gaussmixp:57' lvm=log(w)-0.5*sum(log(v),2); */
  memcpy((void *)&dv0[0], (void *)&v[0], 108U * sizeof(real_T));
  c_log(dv0);
  sum(dv0, b_b);
  memcpy((void *)&lvm[0], (void *)&w[0], 9U * sizeof(real_T));
  b_log(lvm);
  for (ix = 0; ix < 9; ix++) {
    lvm[ix] -= 0.5 * b_b[ix];
  }

  /*  log of external scale factor (excluding -0.5*q*log(2pi) term) */
  /* 'gaussmixp:58' ii=1:n; */
  /* 'gaussmixp:59' wnj=ones(1,n); */
  /* 'gaussmixp:60' kk=repmat(ii,k,1); */
  for (ix = 0; ix < 167; ix++) {
    mx[ix] = 1.0 + (real_T)ix;
  }

  repmat(mx, kk);

  /* 'gaussmixp:61' km=repmat(1:k,1,n); */
  for (ix = 0; ix < 9; ix++) {
    b_b[ix] = 1.0 + (real_T)ix;
  }

  b_repmat(b_b, km);

  /* 'gaussmixp:62' py=reshape(sum((y(kk(:),:)-m(km(:),:)).^2.*vi(km(:),:),2),k,n)+lvm(:,wnj); */
  for (ix = 0; ix < 12; ix++) {
    for (iy = 0; iy < 1503; iy++) {
      b_y[iy + 1503 * ix] = y[((int32_T)kk[iy] + 167 * ix) - 1] - m[((int32_T)
        km[iy] + 9 * ix) - 1];
    }
  }

  b_power(b_y, dv1);
  for (ix = 0; ix < 12; ix++) {
    for (iy = 0; iy < 1503; iy++) {
      b_y[iy + 1503 * ix] = dv1[iy + 1503 * ix] * (-0.5 * b[((int32_T)km[iy] + 9
        * ix) - 1]);
    }
  }

  b_sum(b_y, x);
  memcpy((void *)&kk[0], (void *)&x[0], 1503U * sizeof(real_T));
  for (ix = 0; ix < 167; ix++) {
    for (iy = 0; iy < 9; iy++) {
      km[iy + 9 * ix] = kk[iy + 9 * ix] + lvm[iy];
    }
  }

  /* 'gaussmixp:63' mx=max(py,[],1); */
  ix = -8;
  iy = -1;
  for (i = 0; i < 167; i++) {
    ix += 9;
    ixstart = ix;
    ixstop = ix + 8;
    mtmp = km[ix - 1];
    if (rtIsNaN(km[ix - 1])) {
      b_ix = ix;
      exitg1 = 0U;
      while ((exitg1 == 0U) && (b_ix + 1 <= ixstop)) {
        ixstart = b_ix + 1;
        if (!rtIsNaN(km[b_ix])) {
          mtmp = km[b_ix];
          exitg1 = 1U;
        } else {
          b_ix++;
        }
      }
    }

    if (ixstart < ixstop) {
      while (ixstart + 1 <= ixstop) {
        if (km[ixstart] > mtmp) {
          mtmp = km[ixstart];
        }

        ixstart++;
      }
    }

    iy++;
    mx[iy] = mtmp;
  }

  /*  find normalizing factor for each data point to prevent underflow when using exp() */
  /* 'gaussmixp:64' px=exp(py-mx(wk,:)); */
  for (ix = 0; ix < 167; ix++) {
    for (iy = 0; iy < 9; iy++) {
      kk[iy + 9 * ix] = km[iy + 9 * ix] - mx[ix];
    }
  }

  b_exp(kk);

  /*  find normalized probability of each mixture for each datapoint */
  /* 'gaussmixp:65' ps=sum(px,1); */
  c_sum(kk, ps);

  /*  total normalized likelihood of each data point */
  /* 'gaussmixp:66' lp(ii)=log(ps)+mx; */
  d_log(ps);
  for (ix = 0; ix < 167; ix++) {
    /* 'gaussmixp:67' lp=lp-0.5*q*log(2*pi); */
    lp[ix] = (ps[ix] + mx[ix]) - 11.027262398456072;
  }
}
Esempio n. 5
0
void sammon(sammonStackData *SD, const real_T x[1000000], real_T y[2000], real_T
            *E)
{
  real_T B;
  int32_T i;
  real_T dv0[1000];
  int32_T b_i;
  boolean_T exitg1;
  real_T alpha1;
  real_T beta1;
  char_T TRANSB;
  char_T TRANSA;
  ptrdiff_t m_t;
  ptrdiff_t n_t;
  ptrdiff_t k_t;
  ptrdiff_t lda_t;
  ptrdiff_t ldb_t;
  ptrdiff_t ldc_t;
  double * alpha1_t;
  double * Aia0_t;
  double * Bib0_t;
  double * beta1_t;
  double * Cic0_t;
  real_T g[2000];
  real_T y2[2000];
  real_T b_y[2000];
  real_T c_y[2000];
  real_T d_y[2000];
  real_T e_y[2000];
  real_T b_g[2000];
  int32_T j;
  int32_T b_j;
  boolean_T exitg2;
  real_T dv1[1000];
  real_T E_new;

  /* #codgen */
  /*  */
  /*  SAMMON - apply Sammon's nonlinear mapping  */
  /*  */
  /*     Y = SAMMON(X) applies Sammon's nonlinear mapping procedure on */
  /*     multivariate data X, where each row represents a pattern and each column */
  /*     represents a feature.  On completion, Y contains the corresponding */
  /*     co-ordinates of each point on the map.  By default, a two-dimensional */
  /*     map is created.  Note if X contains any duplicated rows, SAMMON will */
  /*     fail (ungracefully).  */
  /*  */
  /*     [Y,E] = SAMMON(X) also returns the value of the cost function in E (i.e. */
  /*     the stress of the mapping). */
  /*  */
  /*     An N-dimensional output map is generated by Y = SAMMON(X,N) . */
  /*  */
  /*     A set of optimisation options can also be specified using a third */
  /*     argument, Y = SAMMON(X,N,OPTS) , where OPTS is a structure with fields: */
  /*  */
  /*        MaxIter        - maximum number of iterations */
  /*        TolFun         - relative tolerance on objective function */
  /*        MaxHalves      - maximum number of step halvings */
  /*        Input          - {'raw','distance'} if set to 'distance', X is  */
  /*                         interpreted as a matrix of pairwise distances. */
  /*        Display        - {'off', 'on', 'iter'} */
  /*        Initialisation - {'pca', 'random'} */
  /*  */
  /*     The default options structure can be retrieved by calling SAMMON with */
  /*     no parameters. */
  /*  */
  /*     References : */
  /*  */
  /*        [1] Sammon, John W. Jr., "A Nonlinear Mapping for Data Structure */
  /*            Analysis", IEEE Transactions on Computers, vol. C-18, no. 5, */
  /*            pp 401-409, May 1969. */
  /*  */
  /*     See also : SAMMON_TEST */
  /*  */
  /*  File        : sammon.m */
  /*  */
  /*  Date        : Monday 12th November 2007. */
  /*  */
  /*  Author      : Gavin C. Cawley and Nicola L. C. Talbot */
  /*  */
  /*  Description : Simple vectorised MATLAB implementation of Sammon's non-linear */
  /*                mapping algorithm [1]. */
  /*  */
  /*  References  : [1] Sammon, John W. Jr., "A Nonlinear Mapping for Data */
  /*                    Structure Analysis", IEEE Transactions on Computers, */
  /*                    vol. C-18, no. 5, pp 401-409, May 1969. */
  /*  */
  /*  History     : 10/08/2004 - v1.00 */
  /*                11/08/2004 - v1.10 Hessian made positive semidefinite */
  /*                13/08/2004 - v1.11 minor optimisation */
  /*                12/11/2007 - v1.20 initialisation using the first n principal */
  /*                                   components. */
  /*  */
  /*  Thanks      : Dr Nick Hamilton ([email protected]) for supplying the */
  /*                code for implementing initialisation using the first n */
  /*                principal components (introduced in v1.20). */
  /*  */
  /*  To do       : The current version does not take advantage of the symmetry */
  /*                of the distance matrix in order to allow for easy */
  /*                vectorisation.  This may not be a good choice for very large */
  /*                datasets, so perhaps one day I'll get around to doing a MEX */
  /*                version using the BLAS library etc. for very large datasets. */
  /*  */
  /*  Copyright   : (c) Dr Gavin C. Cawley, November 2007. */
  /*  */
  /*     This program is free software; you can redistribute it and/or modify */
  /*     it under the terms of the GNU General Public License as published by */
  /*     the Free Software Foundation; either version 2 of the License, or */
  /*     (at your option) any later version. */
  /*  */
  /*     This program is distributed in the hope that it will be useful, */
  /*     but WITHOUT ANY WARRANTY; without even the implied warranty of */
  /*     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the */
  /*     GNU General Public License for more details. */
  /*  */
  /*     You should have received a copy of the GNU General Public License */
  /*     along with this program; if not, write to the Free Software */
  /*     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
  /*  */
  /*  use the default options structure */
  /*  create distance matrix unless given by parameters */
  emlrtPushRtStackR2012b(&emlrtRSI, emlrtRootTLSGlobal);
  euclid(SD, x, x, SD->f2.D);
  emlrtPopRtStackR2012b(&emlrtRSI, emlrtRootTLSGlobal);

  /*  remaining initialisation */
  B = b_sum(SD->f2.D);
  eye(SD->f2.delta);
  for (i = 0; i < 1000000; i++) {
    SD->f2.D[i] += SD->f2.delta[i];
  }

  rdivide(1.0, SD->f2.D, SD->f2.Dinv);
  emlrtPushRtStackR2012b(&b_emlrtRSI, emlrtRootTLSGlobal);
  randn(y);
  emlrtPopRtStackR2012b(&b_emlrtRSI, emlrtRootTLSGlobal);
  emlrtPushRtStackR2012b(&c_emlrtRSI, emlrtRootTLSGlobal);
  b_euclid(SD, y, y, SD->f2.d);
  eye(SD->f2.delta);
  for (i = 0; i < 1000000; i++) {
    SD->f2.d[i] += SD->f2.delta[i];
  }

  emlrtPopRtStackR2012b(&c_emlrtRSI, emlrtRootTLSGlobal);
  rdivide(1.0, SD->f2.d, SD->f2.dinv);
  for (i = 0; i < 1000000; i++) {
    SD->f2.b_D[i] = SD->f2.D[i] - SD->f2.d[i];
  }

  power(SD->f2.b_D, SD->f2.delta);
  for (i = 0; i < 1000000; i++) {
    SD->f2.d[i] = SD->f2.delta[i] * SD->f2.Dinv[i];
  }

  d_sum(SD->f2.d, dv0);
  *E = e_sum(dv0);

  /*  get on with it */
  b_i = 0;
  exitg1 = FALSE;
  while ((exitg1 == FALSE) && (b_i < 500)) {
    /*  compute gradient, Hessian and search direction (note it is actually */
    /*  1/4 of the gradient and Hessian, but the step size is just the ratio */
    /*  of the gradient and the diagonal of the Hessian so it doesn't matter). */
    for (i = 0; i < 1000000; i++) {
      SD->f2.delta[i] = SD->f2.dinv[i] - SD->f2.Dinv[i];
    }

    emlrtPushRtStackR2012b(&d_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&i_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&j_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&k_emlrtRSI, emlrtRootTLSGlobal);
    alpha1 = 1.0;
    beta1 = 0.0;
    TRANSB = 'N';
    TRANSA = 'N';
    for (i = 0; i < 2000; i++) {
      SD->f2.y_old[i] = 1.0;
      SD->f2.deltaone[i] = 0.0;
    }

    emlrtPushRtStackR2012b(&l_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal);
    m_t = (ptrdiff_t)(1000);
    emlrtPopRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPopRtStackR2012b(&l_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&m_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal);
    n_t = (ptrdiff_t)(2);
    emlrtPopRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPopRtStackR2012b(&m_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&n_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal);
    k_t = (ptrdiff_t)(1000);
    emlrtPopRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPopRtStackR2012b(&n_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&o_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal);
    lda_t = (ptrdiff_t)(1000);
    emlrtPopRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPopRtStackR2012b(&o_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&p_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal);
    ldb_t = (ptrdiff_t)(1000);
    emlrtPopRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPopRtStackR2012b(&p_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&q_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal);
    ldc_t = (ptrdiff_t)(1000);
    emlrtPopRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPopRtStackR2012b(&q_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&r_emlrtRSI, emlrtRootTLSGlobal);
    alpha1_t = (double *)(&alpha1);
    emlrtPopRtStackR2012b(&r_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&s_emlrtRSI, emlrtRootTLSGlobal);
    Aia0_t = (double *)(&SD->f2.delta[0]);
    emlrtPopRtStackR2012b(&s_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&t_emlrtRSI, emlrtRootTLSGlobal);
    Bib0_t = (double *)(&SD->f2.y_old[0]);
    emlrtPopRtStackR2012b(&t_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&u_emlrtRSI, emlrtRootTLSGlobal);
    beta1_t = (double *)(&beta1);
    emlrtPopRtStackR2012b(&u_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&v_emlrtRSI, emlrtRootTLSGlobal);
    Cic0_t = (double *)(&SD->f2.deltaone[0]);
    emlrtPopRtStackR2012b(&v_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&w_emlrtRSI, emlrtRootTLSGlobal);
    dgemm(&TRANSA, &TRANSB, &m_t, &n_t, &k_t, alpha1_t, Aia0_t, &lda_t, Bib0_t,
          &ldb_t, beta1_t, Cic0_t, &ldc_t);
    emlrtPopRtStackR2012b(&w_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPopRtStackR2012b(&k_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPopRtStackR2012b(&j_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPopRtStackR2012b(&i_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPopRtStackR2012b(&d_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&e_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&i_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&j_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&k_emlrtRSI, emlrtRootTLSGlobal);
    alpha1 = 1.0;
    beta1 = 0.0;
    TRANSB = 'N';
    TRANSA = 'N';
    memset(&g[0], 0, 2000U * sizeof(real_T));
    emlrtPushRtStackR2012b(&l_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal);
    m_t = (ptrdiff_t)(1000);
    emlrtPopRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPopRtStackR2012b(&l_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&m_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal);
    n_t = (ptrdiff_t)(2);
    emlrtPopRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPopRtStackR2012b(&m_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&n_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal);
    k_t = (ptrdiff_t)(1000);
    emlrtPopRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPopRtStackR2012b(&n_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&o_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal);
    lda_t = (ptrdiff_t)(1000);
    emlrtPopRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPopRtStackR2012b(&o_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&p_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal);
    ldb_t = (ptrdiff_t)(1000);
    emlrtPopRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPopRtStackR2012b(&p_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&q_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal);
    ldc_t = (ptrdiff_t)(1000);
    emlrtPopRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPopRtStackR2012b(&q_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&r_emlrtRSI, emlrtRootTLSGlobal);
    alpha1_t = (double *)(&alpha1);
    emlrtPopRtStackR2012b(&r_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&s_emlrtRSI, emlrtRootTLSGlobal);
    Aia0_t = (double *)(&SD->f2.delta[0]);
    emlrtPopRtStackR2012b(&s_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&t_emlrtRSI, emlrtRootTLSGlobal);
    Bib0_t = (double *)(&y[0]);
    emlrtPopRtStackR2012b(&t_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&u_emlrtRSI, emlrtRootTLSGlobal);
    beta1_t = (double *)(&beta1);
    emlrtPopRtStackR2012b(&u_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&v_emlrtRSI, emlrtRootTLSGlobal);
    Cic0_t = (double *)(&g[0]);
    emlrtPopRtStackR2012b(&v_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&w_emlrtRSI, emlrtRootTLSGlobal);
    dgemm(&TRANSA, &TRANSB, &m_t, &n_t, &k_t, alpha1_t, Aia0_t, &lda_t, Bib0_t,
          &ldb_t, beta1_t, Cic0_t, &ldc_t);
    emlrtPopRtStackR2012b(&w_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPopRtStackR2012b(&k_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPopRtStackR2012b(&j_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPopRtStackR2012b(&i_emlrtRSI, emlrtRootTLSGlobal);
    for (i = 0; i < 2000; i++) {
      g[i] -= y[i] * SD->f2.deltaone[i];
    }

    emlrtPopRtStackR2012b(&e_emlrtRSI, emlrtRootTLSGlobal);
    c_power(SD->f2.dinv, SD->f2.delta);
    b_power(y, y2);
    emlrtPushRtStackR2012b(&f_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&i_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&j_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&k_emlrtRSI, emlrtRootTLSGlobal);
    alpha1 = 1.0;
    beta1 = 0.0;
    TRANSB = 'N';
    TRANSA = 'N';
    memset(&b_y[0], 0, 2000U * sizeof(real_T));
    emlrtPushRtStackR2012b(&l_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal);
    m_t = (ptrdiff_t)(1000);
    emlrtPopRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPopRtStackR2012b(&l_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&m_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal);
    n_t = (ptrdiff_t)(2);
    emlrtPopRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPopRtStackR2012b(&m_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&n_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal);
    k_t = (ptrdiff_t)(1000);
    emlrtPopRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPopRtStackR2012b(&n_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&o_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal);
    lda_t = (ptrdiff_t)(1000);
    emlrtPopRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPopRtStackR2012b(&o_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&p_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal);
    ldb_t = (ptrdiff_t)(1000);
    emlrtPopRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPopRtStackR2012b(&p_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&q_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal);
    ldc_t = (ptrdiff_t)(1000);
    emlrtPopRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPopRtStackR2012b(&q_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&r_emlrtRSI, emlrtRootTLSGlobal);
    alpha1_t = (double *)(&alpha1);
    emlrtPopRtStackR2012b(&r_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&s_emlrtRSI, emlrtRootTLSGlobal);
    Aia0_t = (double *)(&SD->f2.delta[0]);
    emlrtPopRtStackR2012b(&s_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&t_emlrtRSI, emlrtRootTLSGlobal);
    Bib0_t = (double *)(&y2[0]);
    emlrtPopRtStackR2012b(&t_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&u_emlrtRSI, emlrtRootTLSGlobal);
    beta1_t = (double *)(&beta1);
    emlrtPopRtStackR2012b(&u_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&v_emlrtRSI, emlrtRootTLSGlobal);
    Cic0_t = (double *)(&b_y[0]);
    emlrtPopRtStackR2012b(&v_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&w_emlrtRSI, emlrtRootTLSGlobal);
    dgemm(&TRANSA, &TRANSB, &m_t, &n_t, &k_t, alpha1_t, Aia0_t, &lda_t, Bib0_t,
          &ldb_t, beta1_t, Cic0_t, &ldc_t);
    emlrtPopRtStackR2012b(&w_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPopRtStackR2012b(&k_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPopRtStackR2012b(&j_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPopRtStackR2012b(&i_emlrtRSI, emlrtRootTLSGlobal);
    for (i = 0; i < 2000; i++) {
      c_y[i] = 2.0 * y[i];
    }

    emlrtPushRtStackR2012b(&i_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&j_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&k_emlrtRSI, emlrtRootTLSGlobal);
    alpha1 = 1.0;
    beta1 = 0.0;
    TRANSB = 'N';
    TRANSA = 'N';
    memset(&d_y[0], 0, 2000U * sizeof(real_T));
    emlrtPushRtStackR2012b(&l_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal);
    m_t = (ptrdiff_t)(1000);
    emlrtPopRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPopRtStackR2012b(&l_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&m_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal);
    n_t = (ptrdiff_t)(2);
    emlrtPopRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPopRtStackR2012b(&m_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&n_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal);
    k_t = (ptrdiff_t)(1000);
    emlrtPopRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPopRtStackR2012b(&n_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&o_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal);
    lda_t = (ptrdiff_t)(1000);
    emlrtPopRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPopRtStackR2012b(&o_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&p_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal);
    ldb_t = (ptrdiff_t)(1000);
    emlrtPopRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPopRtStackR2012b(&p_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&q_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal);
    ldc_t = (ptrdiff_t)(1000);
    emlrtPopRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPopRtStackR2012b(&q_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&r_emlrtRSI, emlrtRootTLSGlobal);
    alpha1_t = (double *)(&alpha1);
    emlrtPopRtStackR2012b(&r_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&s_emlrtRSI, emlrtRootTLSGlobal);
    Aia0_t = (double *)(&SD->f2.delta[0]);
    emlrtPopRtStackR2012b(&s_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&t_emlrtRSI, emlrtRootTLSGlobal);
    Bib0_t = (double *)(&y[0]);
    emlrtPopRtStackR2012b(&t_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&u_emlrtRSI, emlrtRootTLSGlobal);
    beta1_t = (double *)(&beta1);
    emlrtPopRtStackR2012b(&u_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&v_emlrtRSI, emlrtRootTLSGlobal);
    Cic0_t = (double *)(&d_y[0]);
    emlrtPopRtStackR2012b(&v_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&w_emlrtRSI, emlrtRootTLSGlobal);
    dgemm(&TRANSA, &TRANSB, &m_t, &n_t, &k_t, alpha1_t, Aia0_t, &lda_t, Bib0_t,
          &ldb_t, beta1_t, Cic0_t, &ldc_t);
    emlrtPopRtStackR2012b(&w_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPopRtStackR2012b(&k_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPopRtStackR2012b(&j_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPopRtStackR2012b(&i_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&i_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&j_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&k_emlrtRSI, emlrtRootTLSGlobal);
    alpha1 = 1.0;
    beta1 = 0.0;
    TRANSB = 'N';
    TRANSA = 'N';
    for (i = 0; i < 2000; i++) {
      SD->f2.y_old[i] = 1.0;
      e_y[i] = 0.0;
    }

    emlrtPushRtStackR2012b(&l_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal);
    m_t = (ptrdiff_t)(1000);
    emlrtPopRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPopRtStackR2012b(&l_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&m_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal);
    n_t = (ptrdiff_t)(2);
    emlrtPopRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPopRtStackR2012b(&m_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&n_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal);
    k_t = (ptrdiff_t)(1000);
    emlrtPopRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPopRtStackR2012b(&n_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&o_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal);
    lda_t = (ptrdiff_t)(1000);
    emlrtPopRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPopRtStackR2012b(&o_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&p_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal);
    ldb_t = (ptrdiff_t)(1000);
    emlrtPopRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPopRtStackR2012b(&p_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&q_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal);
    ldc_t = (ptrdiff_t)(1000);
    emlrtPopRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPopRtStackR2012b(&q_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&r_emlrtRSI, emlrtRootTLSGlobal);
    alpha1_t = (double *)(&alpha1);
    emlrtPopRtStackR2012b(&r_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&s_emlrtRSI, emlrtRootTLSGlobal);
    Aia0_t = (double *)(&SD->f2.delta[0]);
    emlrtPopRtStackR2012b(&s_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&t_emlrtRSI, emlrtRootTLSGlobal);
    Bib0_t = (double *)(&SD->f2.y_old[0]);
    emlrtPopRtStackR2012b(&t_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&u_emlrtRSI, emlrtRootTLSGlobal);
    beta1_t = (double *)(&beta1);
    emlrtPopRtStackR2012b(&u_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&v_emlrtRSI, emlrtRootTLSGlobal);
    Cic0_t = (double *)(&e_y[0]);
    emlrtPopRtStackR2012b(&v_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&w_emlrtRSI, emlrtRootTLSGlobal);
    dgemm(&TRANSA, &TRANSB, &m_t, &n_t, &k_t, alpha1_t, Aia0_t, &lda_t, Bib0_t,
          &ldb_t, beta1_t, Cic0_t, &ldc_t);
    emlrtPopRtStackR2012b(&w_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPopRtStackR2012b(&k_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPopRtStackR2012b(&j_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPopRtStackR2012b(&i_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPopRtStackR2012b(&f_emlrtRSI, emlrtRootTLSGlobal);
    for (i = 0; i < 2000; i++) {
      SD->f2.y_old[i] = ((b_y[i] - SD->f2.deltaone[i]) - c_y[i] * d_y[i]) + y2[i]
        * e_y[i];
      b_g[i] = -g[i];
    }

    b_abs(SD->f2.y_old, y2);
    for (i = 0; i < 2000; i++) {
      SD->f2.deltaone[i] = y2[i];
      SD->f2.y_old[i] = y[i];
    }

    b_rdivide(b_g, SD->f2.deltaone, y2);

    /*  use step-halving procedure to ensure progress is made */
    j = 1;
    b_j = 0;
    exitg2 = FALSE;
    while ((exitg2 == FALSE) && (b_j < 20)) {
      j = b_j + 1;
      for (i = 0; i < 2000; i++) {
        y[i] = SD->f2.y_old[i] + y2[i];
      }

      emlrtPushRtStackR2012b(&g_emlrtRSI, emlrtRootTLSGlobal);
      b_euclid(SD, y, y, SD->f2.d);
      eye(SD->f2.delta);
      for (i = 0; i < 1000000; i++) {
        SD->f2.d[i] += SD->f2.delta[i];
      }

      emlrtPopRtStackR2012b(&g_emlrtRSI, emlrtRootTLSGlobal);
      rdivide(1.0, SD->f2.d, SD->f2.dinv);
      for (i = 0; i < 1000000; i++) {
        SD->f2.b_D[i] = SD->f2.D[i] - SD->f2.d[i];
      }

      power(SD->f2.b_D, SD->f2.delta);
      for (i = 0; i < 1000000; i++) {
        SD->f2.d[i] = SD->f2.delta[i] * SD->f2.Dinv[i];
      }

      d_sum(SD->f2.d, dv1);
      E_new = e_sum(dv1);
      if (E_new < *E) {
        exitg2 = TRUE;
      } else {
        for (i = 0; i < 2000; i++) {
          y2[i] *= 0.5;
        }

        b_j++;
        emlrtBreakCheckFastR2012b(emlrtBreakCheckR2012bFlagVar,
          emlrtRootTLSGlobal);
      }
    }

    /*  bomb out if too many halving steps are required */
    if ((j == 20) || (muDoubleScalarAbs((*E - E_new) / *E) < 1.0E-9)) {
      exitg1 = TRUE;
    } else {
      /*  evaluate termination criterion */
      /*  report progress */
      *E = E_new;
      b_i++;
      emlrtBreakCheckFastR2012b(emlrtBreakCheckR2012bFlagVar, emlrtRootTLSGlobal);
    }
  }

  /*  fiddle stress to match the original Sammon paper */
  *E *= 0.5 / B;
}
Esempio n. 6
0
/* Function Definitions */
static void b_euclid(const emxArray_real_T *x, const emxArray_real_T *y,
                     emxArray_real_T *d)
{
  emxArray_real_T *a;
  emxArray_real_T *b;
  emxArray_real_T *r2;
  emxArray_real_T *r3;
  int32_T i7;
  int32_T unnamed_idx_1;
  int32_T br;
  emxArray_real_T *b_b;
  int32_T ar;
  emxArray_real_T *b_y;
  uint32_T unnamed_idx_0;
  uint32_T b_unnamed_idx_1;
  int32_T cr;
  int32_T ic;
  int32_T ib;
  int32_T ia;
  emxArray_real_T *b_a;
  emxArray_real_T *r4;
  b_emxInit_real_T(&a, 1);
  emxInit_real_T(&b, 2);
  emxInit_real_T(&r2, 2);
  b_emxInit_real_T(&r3, 1);

  /*  all done */
  b_power(x, r2);
  b_sum(r2, a);
  b_power(y, r2);
  b_sum(r2, r3);
  i7 = b->size[0] * b->size[1];
  b->size[0] = 1;
  emxEnsureCapacity((emxArray__common *)b, i7, (int32_T)sizeof(real_T));
  unnamed_idx_1 = r3->size[0];
  i7 = b->size[0] * b->size[1];
  b->size[1] = unnamed_idx_1;
  emxEnsureCapacity((emxArray__common *)b, i7, (int32_T)sizeof(real_T));
  br = r3->size[0];
  emxFree_real_T(&r2);
  for (i7 = 0; i7 < br; i7++) {
    b->data[i7] = r3->data[i7];
  }

  emxFree_real_T(&r3);
  emxInit_real_T(&b_b, 2);
  i7 = b_b->size[0] * b_b->size[1];
  b_b->size[0] = 2;
  b_b->size[1] = y->size[0];
  emxEnsureCapacity((emxArray__common *)b_b, i7, (int32_T)sizeof(real_T));
  br = y->size[0];
  for (i7 = 0; i7 < br; i7++) {
    for (ar = 0; ar < 2; ar++) {
      b_b->data[ar + b_b->size[0] * i7] = y->data[i7 + y->size[0] * ar];
    }
  }

  emxInit_real_T(&b_y, 2);
  unnamed_idx_0 = (uint32_T)x->size[0];
  b_unnamed_idx_1 = (uint32_T)b_b->size[1];
  i7 = b_y->size[0] * b_y->size[1];
  b_y->size[0] = (int32_T)unnamed_idx_0;
  emxEnsureCapacity((emxArray__common *)b_y, i7, (int32_T)sizeof(real_T));
  i7 = b_y->size[0] * b_y->size[1];
  b_y->size[1] = (int32_T)b_unnamed_idx_1;
  emxEnsureCapacity((emxArray__common *)b_y, i7, (int32_T)sizeof(real_T));
  br = (int32_T)unnamed_idx_0 * (int32_T)b_unnamed_idx_1;
  for (i7 = 0; i7 < br; i7++) {
    b_y->data[i7] = 0.0;
  }

  if ((x->size[0] == 0) || (b_b->size[1] == 0)) {
  } else {
    unnamed_idx_1 = x->size[0] * (b_b->size[1] - 1);
    cr = 0;
    while ((x->size[0] > 0) && (cr <= unnamed_idx_1)) {
      i7 = cr + x->size[0];
      for (ic = cr; ic + 1 <= i7; ic++) {
        b_y->data[ic] = 0.0;
      }

      cr += x->size[0];
    }

    br = 0;
    cr = 0;
    while ((x->size[0] > 0) && (cr <= unnamed_idx_1)) {
      ar = -1;
      for (ib = br; ib + 1 <= br + 2; ib++) {
        if (b_b->data[ib] != 0.0) {
          ia = ar;
          i7 = cr + x->size[0];
          for (ic = cr; ic + 1 <= i7; ic++) {
            ia++;
            b_y->data[ic] += b_b->data[ib] * x->data[ia];
          }
        }

        ar += x->size[0];
      }

      br += 2;
      cr += x->size[0];
    }
  }

  emxFree_real_T(&b_b);
  emxInit_real_T(&b_a, 2);
  emxInit_real_T(&r4, 2);
  unnamed_idx_1 = y->size[0];
  cr = x->size[0];
  i7 = b_a->size[0] * b_a->size[1];
  b_a->size[0] = a->size[0];
  b_a->size[1] = unnamed_idx_1;
  emxEnsureCapacity((emxArray__common *)b_a, i7, (int32_T)sizeof(real_T));
  br = a->size[0];
  for (i7 = 0; i7 < br; i7++) {
    for (ar = 0; ar < unnamed_idx_1; ar++) {
      b_a->data[i7 + b_a->size[0] * ar] = a->data[i7];
    }
  }

  emxFree_real_T(&a);
  i7 = r4->size[0] * r4->size[1];
  r4->size[0] = cr;
  r4->size[1] = b->size[1];
  emxEnsureCapacity((emxArray__common *)r4, i7, (int32_T)sizeof(real_T));
  for (i7 = 0; i7 < cr; i7++) {
    br = b->size[1];
    for (ar = 0; ar < br; ar++) {
      r4->data[i7 + r4->size[0] * ar] = b->data[b->size[0] * ar];
    }
  }

  emxFree_real_T(&b);
  i7 = d->size[0] * d->size[1];
  d->size[0] = b_a->size[0];
  d->size[1] = b_a->size[1];
  emxEnsureCapacity((emxArray__common *)d, i7, (int32_T)sizeof(real_T));
  br = b_a->size[1];
  for (i7 = 0; i7 < br; i7++) {
    unnamed_idx_1 = b_a->size[0];
    for (ar = 0; ar < unnamed_idx_1; ar++) {
      d->data[ar + d->size[0] * i7] = (b_a->data[ar + b_a->size[0] * i7] +
        r4->data[ar + r4->size[0] * i7]) - 2.0 * b_y->data[ar + b_y->size[0] *
        i7];
    }
  }

  emxFree_real_T(&r4);
  emxFree_real_T(&b_a);
  emxFree_real_T(&b_y);
  b_sqrt(d);
}