Program: 3325
Project: 3325
Buggy source:
/** 
 * Create a copy of the matrix where the new offset is zero
 * @param arr the array to copy to offset 0
 * @return the same array if offset is zerootherwise a copy of the array with elements set to zero
 */
public static INDArray toOffsetZeroCopy(INDArray arr){
  if (arr.isRowVector()) {
    if (arr instanceof IComplexNDArray) {
      IComplexNDArray ret=Nd4j.createComplex(arr.shape());
      for (int i=0; i < ret.length(); i++)       ret.putScalar(i,((IComplexNDArray)arr).getComplex(i));
      return ret;
    }
 else {
      INDArray ret=Nd4j.create(arr.shape());
      for (int i=0; i < ret.length(); i++)       ret.putScalar(i,arr.getDouble(i));
      return ret;
    }
  }
  if (arr instanceof IComplexNDArray) {
    IComplexNDArray ret=Nd4j.createComplex(arr.shape());
    for (int i=0; i < ret.slices(); i++)     ret.putSlice(i,arr.slice(i));
    return ret;
  }
 else {
    if (arr.offset() == 0 && arr.data().allocationMode() == AllocationMode.HEAP && arr.length() == arr.data().length() && arr.ordering() == Nd4j.ORDER) {
      Object array=arr.data().array();
      if (array instanceof float[]) {
        float[] orig=(float[])array;
        float[] out=Arrays.copyOf(orig,orig.length);
        DataBuffer floatBuffer=Nd4j.createBuffer(out);
        int[] newShape=arr.shape();
        newShape=Arrays.copyOf(newShape,newShape.length);
        int[] newStride=arr.stride();
        newStride=Arrays.copyOf(newStride,newStride.length);
        return Nd4j.create(floatBuffer,newShape,newStride,0,arr.ordering());
      }
 else       if (array instanceof double[]) {
        double[] orig=(double[])array;
        double[] out=Arrays.copyOf(orig,orig.length);
        DataBuffer doubleBuffer=Nd4j.createBuffer(out);
        int[] newShape=arr.shape();
        newShape=Arrays.copyOf(newShape,newShape.length);
        int[] newStride=arr.stride();
        newStride=Arrays.copyOf(newStride,newStride.length);
        return Nd4j.create(doubleBuffer,newShape,newStride,0,arr.ordering());
      }
    }
    INDArray ret=Nd4j.create(arr.shape());
    for (int i=0; i < arr.vectorsAlongDimension(0); i++) {
      ret.vectorAlongDimension(i,0).assign(arr.vectorAlongDimension(i,0));
    }
    return ret;
  }
}

Fixed version (ground truth):
/** 
 * Create a copy of the matrix where the new offset is zero
 * @param arr the array to copy to offset 0
 * @return the same array if offset is zerootherwise a copy of the array with elements set to zero
 */
public static INDArray toOffsetZeroCopy(INDArray arr){
  if (arr.isRowVector()) {
    if (arr instanceof IComplexNDArray) {
      IComplexNDArray ret=Nd4j.createComplex(arr.shape());
      for (int i=0; i < ret.length(); i++)       ret.putScalar(i,((IComplexNDArray)arr).getComplex(i));
      return ret;
    }
 else {
      INDArray ret=Nd4j.create(arr.shape());
      for (int i=0; i < ret.length(); i++)       ret.putScalar(i,arr.getDouble(i));
      return ret;
    }
  }
  if (arr instanceof IComplexNDArray) {
    IComplexNDArray ret=Nd4j.createComplex(arr.shape());
    for (int i=0; i < ret.slices(); i++)     ret.putSlice(i,arr.slice(i));
    return ret;
  }
 else {
    if (arr.offset() == 0 && arr.data().allocationMode() == AllocationMode.HEAP && arr.length() == arr.data().length() && arr.ordering() == Nd4j.order() && strideDescendingCAscendingF(arr.ordering(),arr.stride())) {
      Object array=arr.data().array();
      if (array instanceof float[]) {
        float[] orig=(float[])array;
        float[] out=Arrays.copyOf(orig,orig.length);
        DataBuffer floatBuffer=Nd4j.createBuffer(out);
        int[] newShape=arr.shape();
        newShape=Arrays.copyOf(newShape,newShape.length);
        int[] newStride=arr.stride();
        newStride=Arrays.copyOf(newStride,newStride.length);
        return Nd4j.create(floatBuffer,newShape,newStride,0,arr.ordering());
      }
 else       if (array instanceof double[]) {
        double[] orig=(double[])array;
        double[] out=Arrays.copyOf(orig,orig.length);
        DataBuffer doubleBuffer=Nd4j.createBuffer(out);
        int[] newShape=arr.shape();
        newShape=Arrays.copyOf(newShape,newShape.length);
        int[] newStride=arr.stride();
        newStride=Arrays.copyOf(newStride,newStride.length);
        return Nd4j.create(doubleBuffer,newShape,newStride,0,arr.ordering());
      }
    }
    INDArray ret=Nd4j.create(arr.shape());
    for (int i=0; i < arr.vectorsAlongDimension(0); i++) {
      ret.vectorAlongDimension(i,0).assign(arr.vectorAlongDimension(i,0));
    }
    return ret;
  }
}