Program: 57113
Project: 57113
Buggy source:
/** 
 * <p>Loads model x and y sample data from a flat input array, overriding any previous sample. </p> <p>Assumes that rows are concatenated with y values first in each row.  For example, an input <code>data</code> array containing the sequence of values (1, 2, 3, 4, 5, 6, 7, 8, 9) with <code>nobs = 3</code> and <code>nvars = 2</code> creates a regression dataset with two independent variables, as below: <pre> y   x[0]  x[1] -------------- 1     2     3 4     5     6 7     8     9 </pre> </p> <p>Note that there is no need to add an initial unitary column (column of 1's) when specifying a model including an intercept term.  If   {@link #isNoIntercept()} is <code>true</code>,the X matrix will be created without an initial column of "1"s; otherwise this column will be added. </p> <p>Throws IllegalArgumentException if any of the following preconditions fail: <ul><li><code>data</code> cannot be null</li> <li><code>data.length = nobs * (nvars + 1)</code></li> <li><code>nobs > nvars</code></li></ul>
 * @param data input data array
 * @param nobs number of observations (rows)
 * @param nvars number of independent variables (columns, not counting y)
 * @throws NullArgumentException if the data array is null
 * @throws DimensionMismatchException if the length of the data array is not equalto <code>nobs * (nvars + 1)</code>
 * @throws InsufficientDataException if <code>nobs</code> is less than<code>nvars + 1</code>
 */
public void newSampleData(double[] data,int nobs,int nvars){
  if (data == null) {
    throw new NullArgumentException();
  }
  if (data.length != nobs * (nvars + 1)) {
    throw new DimensionMismatchException(data.length,nobs * (nvars + 1));
  }
  if (nobs <= nvars) {
    throw new InsufficientDataException(LocalizedFormats.INSUFFICIENT_OBSERVED_POINTS_IN_SAMPLE,nobs,nvars + 1);
  }
  double[] y=new double[nobs];
  final int cols=noIntercept ? nvars : nvars + 1;
  double[][] x=new double[nobs][cols];
  int pointer=0;
  for (int i=0; i < nobs; i++) {
    y[i]=data[pointer++];
    if (!noIntercept) {
      x[i][0]=1.0d;
    }
    for (int j=noIntercept ? 0 : 1; j < cols; j++) {
      x[i][j]=data[pointer++];
    }
  }
  this.xMatrix=new Array2DRowRealMatrix(x);
  this.yVector=new ArrayRealVector(y);
}

Fixed version (ground truth):
/** 
 * <p>Loads model x and y sample data from a flat input array, overriding any previous sample. </p> <p>Assumes that rows are concatenated with y values first in each row.  For example, an input <code>data</code> array containing the sequence of values (1, 2, 3, 4, 5, 6, 7, 8, 9) with <code>nobs = 3</code> and <code>nvars = 2</code> creates a regression dataset with two independent variables, as below: <pre> y   x[0]  x[1] -------------- 1     2     3 4     5     6 7     8     9 </pre> <p>Note that there is no need to add an initial unitary column (column of 1's) when specifying a model including an intercept term.  If   {@link #isNoIntercept()} is <code>true</code>,the X matrix will be created without an initial column of "1"s; otherwise this column will be added. </p> <p>Throws IllegalArgumentException if any of the following preconditions fail: <ul><li><code>data</code> cannot be null</li> <li><code>data.length = nobs * (nvars + 1)</code></li> <li> {@code nobs > nvars}</li></ul>
 * @param data input data array
 * @param nobs number of observations (rows)
 * @param nvars number of independent variables (columns, not counting y)
 * @throws NullArgumentException if the data array is null
 * @throws DimensionMismatchException if the length of the data array is not equalto <code>nobs * (nvars + 1)</code>
 * @throws InsufficientDataException if <code>nobs</code> is less than<code>nvars + 1</code>
 */
public void newSampleData(double[] data,int nobs,int nvars){
  if (data == null) {
    throw new NullArgumentException();
  }
  if (data.length != nobs * (nvars + 1)) {
    throw new DimensionMismatchException(data.length,nobs * (nvars + 1));
  }
  if (nobs <= nvars) {
    throw new InsufficientDataException(LocalizedFormats.INSUFFICIENT_OBSERVED_POINTS_IN_SAMPLE,nobs,nvars + 1);
  }
  double[] y=new double[nobs];
  final int cols=noIntercept ? nvars : nvars + 1;
  double[][] x=new double[nobs][cols];
  int pointer=0;
  for (int i=0; i < nobs; i++) {
    y[i]=data[pointer++];
    if (!noIntercept) {
      x[i][0]=1.0d;
    }
    for (int j=noIntercept ? 0 : 1; j < cols; j++) {
      x[i][j]=data[pointer++];
    }
  }
  this.xMatrix=new Array2DRowRealMatrix(x);
  this.yVector=new ArrayRealVector(y);
}