nus-yam/ex-repair huggingface dataset:
Program: 3293
Project: 3293
Buggy source:
@Override public void invokeAsync(){
  if (n > threshold) {
    int nSubTasks=1 + n / threshold;
    subTasks=new ArrayList<>(nSubTasks);
    int taskSize=n / nSubTasks;
    int soFar=0;
    for (int i=0; i < nSubTasks; i++) {
      int nInTask;
      if (i == nSubTasks - 1) {
        nInTask=n - soFar;
      }
 else {
        nInTask=taskSize;
      }
      int offsetXNew=offsetX + soFar * incrX;
      int offsetYNew=offsetY + soFar * incrY;
      Task<Pair<Double,Integer>> t=new CPUIndexAccumulationTask(op,threshold,nInTask,offsetXNew,offsetYNew,incrX,incrY,soFar,false);
      t.invokeAsync();
      subTasks.add(t);
      soFar+=nInTask;
    }
  }
 else {
    future=TaskExecutorProvider.getTaskExecutor().executeAsync(this);
  }
}

Fixed version (ground truth):
@Override public void invokeAsync(){
  if (n > threshold) {
    int nSubTasks=1 + n / threshold;
    subTasks=new ArrayList<>(nSubTasks);
    int taskSize=n / nSubTasks;
    int soFar=0;
    for (int i=0; i < nSubTasks; i++) {
      int nInTask;
      if (i == nSubTasks - 1) {
        nInTask=n - soFar;
      }
 else {
        nInTask=taskSize;
      }
      int offsetXNew=offsetX + soFar * incrX;
      int offsetYNew=offsetY + soFar * incrY;
      Task<Pair<Double,Integer>> t=new CPUIndexAccumulationTask(op,threshold,nInTask,offsetXNew,offsetYNew,incrX,incrY,elementOffset + soFar,false);
      t.invokeAsync();
      subTasks.add(t);
      soFar+=nInTask;
    }
  }
 else {
    future=TaskExecutorProvider.getTaskExecutor().executeAsync(this);
  }
}
Program: 3295
Project: 3295
Buggy source:
public JCudaExecutioner(){
  try {
    SimpleJCublas.init();
  }
 catch (  Exception e) {
    throw new RuntimeException(e);
  }
  dummyFloatPointer=KernelFunctions.alloc(new float[]{1});
  dummyDoublePointer=KernelFunctions.alloc(new double[]{1});
  parallelExecutioner().setParallelEnabled(false);
}

Fixed version (ground truth):
public JCudaExecutioner(){
  try {
    SimpleJCublas.init();
  }
 catch (  Exception e) {
    throw new RuntimeException(e);
  }
  dummyFloatPointer=KernelFunctions.alloc(new float[]{1});
  dummyDoublePointer=KernelFunctions.alloc(new double[]{1});
}
Program: 3296
Project: 3296
Buggy source:
private void applyVectorOp(INDArray vector,final char operation){
  if (this instanceof IComplexNDArray) {
    IComplexNDArray complexThis=(IComplexNDArray)this;
    IComplexNDArray row=(IComplexNDArray)vector;
    Iterator<int[]> shapes=Shape.isRowVectorShape(vector.shape()) ? new NdIndexIterator('c',shape()) : new NdIndexIterator('f',shape());
    int currVectorPosition=0;
    while (shapes.hasNext()) {
      int[] position=shapes.next();
switch (operation) {
case 'a':
        complexThis.putScalar(position,complexThis.getComplex(position).addi(row.getComplex(currVectorPosition++)));
      break;
case 's':
    complexThis.putScalar(position,complexThis.getComplex(position).subi(row.getComplex(currVectorPosition++)));
  break;
case 'm':
complexThis.putScalar(position,complexThis.getComplex(position).muli(row.getComplex(currVectorPosition++)));
break;
case 'd':
complexThis.putScalar(position,complexThis.getComplex(position).divi(row.getComplex(currVectorPosition++)));
break;
case 'h':
complexThis.putScalar(position,complexThis.getComplex(position).rsubi(row.getComplex(currVectorPosition++)));
break;
case 't':
complexThis.putScalar(position,complexThis.getComplex(position).rdivi(row.getComplex(currVectorPosition++)));
break;
}
if (currVectorPosition >= vector.length()) currVectorPosition=0;
}
}
 else {
int dimension=Shape.isRowVectorShape(vector.shape()) ? 0 : 1;
final INDArray op;
if (vector.data() == data()) op=vector.dup();
 else op=vector;
throw new UnsupportedOperationException("String_Node_Str");
}
}

Fixed version (ground truth):
private void applyVectorOp(INDArray vector,final char operation){
  int alongDimension=Shape.isRowVectorShape(vector.shape()) ? 1 : 0;
  if (this.data() == vector.data())   vector=vector.dup();
switch (operation) {
case 'a':
    Nd4j.getExecutioner().exec(new VectorAddOp(this,vector,this,alongDimension));
  return;
case 's':
Nd4j.getExecutioner().exec(new VectorSubOp(this,vector,this,alongDimension));
return;
case 'm':
Nd4j.getExecutioner().exec(new VectorMulOp(this,vector,this,alongDimension));
return;
case 'd':
Nd4j.getExecutioner().exec(new VectorDivOp(this,vector,this,alongDimension));
return;
case 'h':
Nd4j.getExecutioner().exec(new VectorRSubOp(this,vector,this,alongDimension));
return;
case 't':
Nd4j.getExecutioner().exec(new VectorRDivOp(this,vector,this,alongDimension));
return;
case 'p':
Nd4j.getExecutioner().exec(new VectorCopyOp(this,vector,this,alongDimension));
return;
default :
throw new UnsupportedOperationException("String_Node_Str" + operation);
}
}
Program: 3297
Project: 3297
Buggy source:
public DefaultOpExecutioner(){
  taskFactory=TaskFactoryProvider.getTaskFactory();
}

Fixed version (ground truth):
public DefaultOpExecutioner(){
  taskFactory=Nd4j.getTaskFactory();
}
Program: 3298
Project: 3298
Buggy source:
/** 
 * Can we do the transform op (Z = Op(X,Y)) directly on the arrays without breaking them up into 1d tensors first? 
 */
public static boolean canDoOpDirectly(INDArray x,INDArray y,INDArray z){
  if (x.isVector())   return true;
  int l1=x.length();
  int dl1=x.data().length();
  int l2=y.length();
  int dl2=y.data().length();
  int l3=z.length();
  int dl3=z.data().length();
  int[] strides1=x.stride();
  int[] strides2=y.stride();
  int[] strides3=z.stride();
  boolean equalStrides=Arrays.equals(strides1,strides2) && Arrays.equals(strides1,strides3);
  if (l1 == dl1 && l2 == dl2 && l3 == dl3 && equalStrides)   return true;
  if (equalStrides) {
    int[] shape1=x.shape();
    int[] stridesAsInit=(x.ordering() == 'c' ? ArrayUtil.calcStrides(shape1) : ArrayUtil.calcStridesFortran(shape1));
    boolean stridesSameAsInit=Arrays.equals(strides1,stridesAsInit);
    return stridesSameAsInit;
  }
  return false;
}

Fixed version (ground truth):
/** 
 * Can we do the transform op (Z = Op(X,Y)) directly on the arrays without breaking them up into 1d tensors first? 
 */
public static boolean canDoOpDirectly(INDArray x,INDArray y,INDArray z){
  if (x.isVector())   return true;
  if (x.ordering() != y.ordering() || x.ordering() != z.ordering())   return false;
  int l1=x.length();
  int dl1=x.data().length();
  int l2=y.length();
  int dl2=y.data().length();
  int l3=z.length();
  int dl3=z.data().length();
  int[] strides1=x.stride();
  int[] strides2=y.stride();
  int[] strides3=z.stride();
  boolean equalStrides=Arrays.equals(strides1,strides2) && Arrays.equals(strides1,strides3);
  if (l1 == dl1 && l2 == dl2 && l3 == dl3 && equalStrides)   return true;
  if (equalStrides) {
    int[] shape1=x.shape();
    int[] stridesAsInit=(x.ordering() == 'c' ? ArrayUtil.calcStrides(shape1) : ArrayUtil.calcStridesFortran(shape1));
    boolean stridesSameAsInit=Arrays.equals(strides1,stridesAsInit);
    return stridesSameAsInit;
  }
  return false;
}
Program: 3299
Project: 3299
Buggy source:
/** 
 * Tensor1DStats, used to efficiently iterate through tensors on a matrix (2d NDArray) for element-wise ops For example, the offset of each 1d tensor can be calculated using only a single tensorAlongDimension method call, hence is potentially faster than approaches requiring multiple tensorAlongDimension calls.<br> Note that this can only (generally) be used for 2d NDArrays. For certain 3+d NDArrays, the tensor starts may not be in increasing order
 */
public static Tensor1DStats get1DTensorStats(INDArray array,int dimension){
  int tensorLength=ArrayUtil.prod(ArrayUtil.removeIndex(array.shape(),dimension));
  int numTensors=array.length() / tensorLength;
  int firstTensorOffset=array.offset();
  int tensorStartSeparation;
  int elementWiseStride;
  if (numTensors == 1) {
    tensorStartSeparation=-1;
    elementWiseStride=array.elementWiseStride();
  }
 else {
    INDArray secondTensor=array.tensorAlongDimension(1,dimension);
    tensorStartSeparation=secondTensor.offset() - firstTensorOffset;
    elementWiseStride=secondTensor.elementWiseStride();
  }
  return new Tensor1DStats(firstTensorOffset,tensorStartSeparation,numTensors,tensorLength,elementWiseStride);
}

Fixed version (ground truth):
/** 
 * Tensor1DStats, used to efficiently iterate through tensors on a matrix (2d NDArray) for element-wise ops For example, the offset of each 1d tensor can be calculated using only a single tensorAlongDimension method call, hence is potentially faster than approaches requiring multiple tensorAlongDimension calls.<br> Note that this can only (generally) be used for 2d NDArrays. For certain 3+d NDArrays, the tensor starts may not be in increasing order
 */
public static Tensor1DStats get1DTensorStats(INDArray array,int dimension){
  int tensorLength=array.size(dimension);
  int numTensors=array.length() / tensorLength;
  int firstTensorOffset=array.offset();
  int tensorStartSeparation;
  int elementWiseStride;
  if (numTensors == 1) {
    tensorStartSeparation=-1;
    elementWiseStride=array.elementWiseStride();
  }
 else {
    INDArray secondTensor=array.tensorAlongDimension(1,dimension);
    tensorStartSeparation=secondTensor.offset() - firstTensorOffset;
    elementWiseStride=secondTensor.elementWiseStride();
  }
  return new Tensor1DStats(firstTensorOffset,tensorStartSeparation,numTensors,tensorLength,elementWiseStride);
}
Program: 3300
Project: 3300
Buggy source:
public AddOp(INDArray x,INDArray xDup,INDArray z){
  super(x,xDup,z,x.length());
}

Fixed version (ground truth):
public AddOp(INDArray x,INDArray y,INDArray z){
  super(x,y,z,x.length());
}
Program: 3301
Project: 3301
Buggy source:
public DivOp(INDArray x,INDArray z,int n){
  super(x,z,n);
}

Fixed version (ground truth):
public DivOp(INDArray x,INDArray y,INDArray z){
  super(x,y,z,x.length());
}
Program: 3302
Project: 3302
Buggy source:
public MulOp(INDArray x,INDArray xDup,INDArray x1){
  super(x,xDup,x1,x.length());
}

Fixed version (ground truth):
public MulOp(INDArray x,INDArray y,INDArray z){
  super(x,y,z,x.length());
}
Program: 3303
Project: 3303
Buggy source:
public RDivOp(INDArray x,INDArray z,int n){
  super(x,z,n);
}

Fixed version (ground truth):
public RDivOp(INDArray x,INDArray y,INDArray z){
  super(x,y,z,x.length());
}
Program: 3304
Project: 3304
Buggy source:
public RSubOp(INDArray x,INDArray z,int n){
  super(x,z,n);
}

Fixed version (ground truth):
public RSubOp(INDArray x,INDArray y,INDArray z){
  super(x,y,z,x.length());
}
Program: 3305
Project: 3305
Buggy source:
public SubOp(INDArray x,INDArray z,int n){
  super(x,z,n);
}

Fixed version (ground truth):
public SubOp(INDArray x,INDArray y,INDArray z){
  super(x,y,z,x.length());
}
Program: 3308
Project: 3308
Buggy source:
@Override public double doTask(){
  return Nd4j.getBlasWrapper().level1().dot(n,x,offsetX,incrX,y,offsetY,incrY);
}

Fixed version (ground truth):
@Override public double doTask(){
  if (x.allocationMode() == DataBuffer.AllocationMode.HEAP) {
    double accum=Nd4j.getBlasWrapper().level1().dot(n,x,offsetX,incrX,y,offsetY,incrY);
    if (outerTask)     return op.getAndSetFinalResult(accum);
    return accum;
  }
 else {
    ByteBuf nbbx=x.asNetty();
    ByteBuf nbby=y.asNetty();
    if (x.dataType() == DataBuffer.Type.FLOAT) {
      float accum=op.zeroFloat();
      int byteOffsetX=4 * offsetX;
      int byteOffsetY=4 * offsetY;
      if (incrX == 1 && incrY == 1) {
        for (int i=0; i < 4 * n; i+=4) {
          accum=op.update(accum,nbbx.getFloat(byteOffsetX + i),nbby.getFloat(byteOffsetY + i));
        }
      }
 else {
        for (int i=0; i < 4 * n; i+=4) {
          accum=op.update(accum,nbbx.getFloat(byteOffsetX + i * incrX),nbby.getFloat(byteOffsetY + i * incrY));
        }
      }
      if (outerTask)       return op.getAndSetFinalResult(accum);
      return accum;
    }
 else {
      double accum=op.zeroDouble();
      int byteOffsetX=8 * offsetX;
      int byteOffsetY=8 * offsetY;
      if (incrX == 1 && incrY == 1) {
        for (int i=0; i < 8 * n; i+=8) {
          accum=op.update(accum,nbbx.getDouble(byteOffsetX + i),nbby.getDouble(byteOffsetY + i));
        }
      }
 else {
        for (int i=0; i < 8 * n; i+=8) {
          accum=op.update(accum,nbbx.getDouble(byteOffsetX + i * incrX),nbby.getDouble(byteOffsetY + i * incrY));
        }
      }
      if (outerTask)       return op.getAndSetFinalResult(accum);
      return accum;
    }
  }
}
Program: 3309
Project: 3309
Buggy source:
@Override public double doTask(){
  double sum=op.zeroDouble();
  if (x.allocationMode() == DataBuffer.AllocationMode.HEAP) {
    if (x.dataType() == DataBuffer.Type.FLOAT) {
      float[] xf=(float[])x.array();
      if (incrX == 1) {
        for (int i=0; i < n; i++) {
          sum+=xf[offsetX + i];
        }
      }
 else {
        for (int i=0; i < n; i++) {
          sum+=xf[offsetX + i * incrX];
        }
      }
    }
 else {
      double[] xd=(double[])x.array();
      if (incrX == 1) {
        for (int i=0; i < n; i++) {
          sum+=xd[offsetX + i];
        }
      }
 else {
        for (int i=0; i < n; i++) {
          sum+=xd[offsetX + i * incrX];
        }
      }
    }
  }
 else {
    ByteBuf nbbx=x.asNetty();
    if (x.dataType() == DataBuffer.Type.FLOAT) {
      int byteOffsetX=4 * offsetX;
      if (incrX == 1) {
        for (int i=0; i < n; i+=4) {
          sum+=nbbx.getFloat(byteOffsetX + i);
        }
      }
 else {
        for (int i=0; i < n; i+=4) {
          sum+=nbbx.getFloat(byteOffsetX + i * incrX);
        }
      }
    }
 else {
      int byteOffsetX=8 * offsetX;
      if (incrX == 1) {
        for (int i=0; i < n; i+=8) {
          sum+=nbbx.getDouble(byteOffsetX + i);
        }
      }
 else {
        for (int i=0; i < n; i+=8) {
          sum+=nbbx.getDouble(byteOffsetX + i * incrX);
        }
      }
    }
  }
  return (outerTask ? op.getAndSetFinalResult(sum) : sum);
}

Fixed version (ground truth):
@Override public double doTask(){
  double sum=op.zeroDouble();
  if (x.allocationMode() == DataBuffer.AllocationMode.HEAP) {
    if (x.dataType() == DataBuffer.Type.FLOAT) {
      float[] xf=(float[])x.array();
      if (incrX == 1) {
        for (int i=0; i < n; i++) {
          sum+=xf[offsetX + i];
        }
      }
 else {
        for (int i=0; i < n; i++) {
          sum+=xf[offsetX + i * incrX];
        }
      }
    }
 else {
      double[] xd=(double[])x.array();
      if (incrX == 1) {
        for (int i=0; i < n; i++) {
          sum+=xd[offsetX + i];
        }
      }
 else {
        for (int i=0; i < n; i++) {
          sum+=xd[offsetX + i * incrX];
        }
      }
    }
  }
 else {
    ByteBuf nbbx=x.asNetty();
    if (x.dataType() == DataBuffer.Type.FLOAT) {
      int byteOffsetX=4 * offsetX;
      if (incrX == 1) {
        for (int i=0; i < 4 * n; i+=4) {
          sum+=nbbx.getFloat(byteOffsetX + i);
        }
      }
 else {
        for (int i=0; i < 4 * n; i+=4) {
          sum+=nbbx.getFloat(byteOffsetX + i * incrX);
        }
      }
    }
 else {
      int byteOffsetX=8 * offsetX;
      if (incrX == 1) {
        for (int i=0; i < 8 * n; i+=8) {
          sum+=nbbx.getDouble(byteOffsetX + i);
        }
      }
 else {
        for (int i=0; i < 8 * n; i+=8) {
          sum+=nbbx.getDouble(byteOffsetX + i * incrX);
        }
      }
    }
  }
  return (outerTask ? op.getAndSetFinalResult(sum) : sum);
}
Program: 3311
Project: 3311
Buggy source:
@Override protected INDArray compute(){
  INDArray x=op.x();
  INDArray y=op.y();
  DataBuffer dx=x.data();
  DataBuffer dy=(y != null ? y.data() : null);
  int nTensors=x.tensorssAlongDimension(dimensions);
  List<RecursiveTask<Double>> taskList=new ArrayList<>(nTensors);
  boolean canDoDirectly=false;
  for (int i=0; i < nTensors; i++) {
    Accumulation opOnDimension=(Accumulation)op.opForDimension(i,dimensions);
    INDArray x2=opOnDimension.x();
    INDArray y2=opOnDimension.y();
    if (i == 0) {
      if (y2 == null)       canDoDirectly=OpExecutionerUtil.canDoTransformOpDirectly(x2);
 else       canDoDirectly=OpExecutionerUtil.canDoTransformOpDirectly(x2,y2);
    }
    RecursiveTask<Double> task;
    if (canDoDirectly) {
      if (y != null) {
        task=opOnDimension.getAccumulationOpDataBufferTask(parallelThreshold,opOnDimension.n(),dx,dy,x2.offset(),y2.offset(),x2.elementWiseStride(),y2.elementWiseStride(),true);
      }
 else {
        task=opOnDimension.getAccumulationOpDataBufferTask(parallelThreshold,opOnDimension.n(),dx,null,x2.offset(),0,x2.elementWiseStride(),0,true);
      }
    }
 else {
      task=new AccumulationViaTensorDataBufferTask(opOnDimension,parallelThreshold,x2,y2);
    }
    task.fork();
    taskList.add(task);
  }
  int[] retShape=ArrayUtil.removeIndex(x.shape(),dimensions);
  INDArray out=Nd4j.create(retShape);
  int i=0;
  for (  RecursiveTask<Double> task : taskList) {
    out.putScalar(i++,task.join());
  }
  return out;
}

Fixed version (ground truth):
@Override protected Double compute(){
  Accumulation opOnDimension=(Accumulation)op.opForDimension(tensorNum,dimensions);
  INDArray x2=opOnDimension.x();
  INDArray y2=opOnDimension.y();
  boolean canDoDirectly;
  if (y2 == null)   canDoDirectly=OpExecutionerUtil.canDoTransformOpDirectly(x2);
 else   canDoDirectly=OpExecutionerUtil.canDoTransformOpDirectly(x2,y2);
  RecursiveTask<Double> task;
  if (canDoDirectly) {
    if (y2 != null) {
      task=opOnDimension.getAccumulationOpDataBufferTask(parallelThreshold,opOnDimension.n(),x2.data(),y2.data(),x2.offset(),y2.offset(),x2.elementWiseStride(),y2.elementWiseStride(),true);
    }
 else {
      task=opOnDimension.getAccumulationOpDataBufferTask(parallelThreshold,opOnDimension.n(),x2.data(),null,x2.offset(),0,x2.elementWiseStride(),0,true);
    }
  }
 else {
    task=new AccumulationViaTensorDataBufferTask(opOnDimension,parallelThreshold,x2,y2);
  }
  return task.invoke();
}
Program: 3312
Project: 3312
Buggy source:
@Override protected INDArray compute(){
  INDArray x=op.x();
  INDArray y=op.y();
  DataBuffer dx=x.data();
  DataBuffer dy=(y != null ? y.data() : null);
  int nTensors=x.tensorssAlongDimension(dimensions);
  List<RecursiveTask<Pair<Double,Integer>>> taskList=new ArrayList<>(nTensors);
  boolean canDoDirectly=false;
  for (int i=0; i < nTensors; i++) {
    IndexAccumulation opOnDimension=(IndexAccumulation)op.opForDimension(i,dimensions);
    INDArray x2=opOnDimension.x();
    INDArray y2=opOnDimension.y();
    if (i == 0) {
      if (y2 == null)       canDoDirectly=OpExecutionerUtil.canDoTransformOpDirectly(x2);
 else       canDoDirectly=OpExecutionerUtil.canDoTransformOpDirectly(x2,y2);
    }
    RecursiveTask<Pair<Double,Integer>> task;
    if (canDoDirectly) {
      if (y != null) {
        task=opOnDimension.getIndexAccumulationOpDataBufferTask(0,opOnDimension.n(),dx,dy,x2.offset(),y2.offset(),x2.elementWiseStride(),y2.elementWiseStride(),0,true);
      }
 else {
        task=opOnDimension.getIndexAccumulationOpDataBufferTask(0,opOnDimension.n(),dx,null,x2.offset(),0,x2.elementWiseStride(),0,0,true);
      }
    }
 else {
      task=new IndexAccumulationViaTensorDataBufferTask(opOnDimension,parallelThreshold,x2,y2);
    }
    task.fork();
    taskList.add(task);
  }
  int[] retShape=ArrayUtil.removeIndex(x.shape(),dimensions);
  INDArray out=Nd4j.create(retShape);
  int i=0;
  for (  RecursiveTask<Pair<Double,Integer>> task : taskList) {
    Pair<Double,Integer> pair=task.join();
    out.putScalar(i++,pair.getSecond());
  }
  return out;
}

Fixed version (ground truth):
@Override protected Pair<Double,Integer> compute(){
  IndexAccumulation opOnDimension=(IndexAccumulation)op.opForDimension(tensorNum,dimensions);
  INDArray x2=opOnDimension.x();
  INDArray y2=opOnDimension.y();
  boolean canDoDirectly;
  if (y2 == null)   canDoDirectly=OpExecutionerUtil.canDoTransformOpDirectly(x2);
 else   canDoDirectly=OpExecutionerUtil.canDoTransformOpDirectly(x2,y2);
  RecursiveTask<Pair<Double,Integer>> task;
  if (canDoDirectly) {
    if (y2 != null) {
      task=opOnDimension.getIndexAccumulationOpDataBufferTask(parallelThreshold,opOnDimension.n(),x2.data(),y2.data(),x2.offset(),y2.offset(),x2.elementWiseStride(),y2.elementWiseStride(),0,true);
    }
 else {
      task=opOnDimension.getIndexAccumulationOpDataBufferTask(parallelThreshold,opOnDimension.n(),x2.data(),null,x2.offset(),0,x2.elementWiseStride(),0,0,true);
    }
  }
 else {
    task=new IndexAccumulationViaTensorDataBufferTask(opOnDimension,parallelThreshold,x2,y2);
  }
  return task.invoke();
}
Program: 3317
Project: 3317
Buggy source:
private void doAccumulationOp(Accumulation op){
  if (op.x().data().allocationMode() == DataBuffer.AllocationMode.HEAP) {
    INDArray x=op.x();
    INDArray y=op.y();
    boolean canDoDirectly=OpExecutionerUtil.canDoTransformOpDirectly(op.x());
    if (canDoDirectly) {
      new BufferOps.AccumulationOpDataBufferTask(op,PARALLEL_THRESHOLD,x.length(),x.data(),(y != null ? y.data() : null),x.offset(),y.offset(),x.elementWiseStride(),(y != null ? y.elementWiseStride() : 0),true).invoke();
    }
 else {
      throw new UnsupportedOperationException("String_Node_Str");
    }
  }
 else {
    throw new UnsupportedOperationException("String_Node_Str");
  }
}

Fixed version (ground truth):
private void doAccumulationOp(Accumulation op){
  if (op.x().data().allocationMode() == DataBuffer.AllocationMode.HEAP) {
    INDArray x=op.x();
    INDArray y=op.y();
    boolean canDoDirectly;
    if (y == null)     canDoDirectly=OpExecutionerUtil.canDoTransformOpDirectly(x);
 else     canDoDirectly=OpExecutionerUtil.canDoTransformOpDirectly(x,y);
    if (canDoDirectly) {
      if (y == null) {
        new BufferOps.AccumulationOpDataBufferTask(op,PARALLEL_THRESHOLD,x.length(),x.data(),null,x.offset(),0,x.elementWiseStride(),0,true).invoke();
      }
 else {
        new BufferOps.AccumulationOpDataBufferTask(op,PARALLEL_THRESHOLD,x.length(),x.data(),y.data(),x.offset(),y.offset(),x.elementWiseStride(),y.elementWiseStride(),true).invoke();
      }
      return;
    }
 else {
      new BufferOps.AccumulationViaTensorDataBufferTask(op,PARALLEL_THRESHOLD,x,y).invoke();
    }
  }
 else {
    if (op.y() != null && Shape.opIsWholeBufferWithMatchingStrides(op)) {
      double accum=op.zeroDouble();
      DataBuffer dx=op.x().data();
      DataBuffer dy=op.y().data();
      for (int i=0; i < op.n(); i++) {
        accum=op.update(accum,dx.getDouble(i),dy.getDouble(i));
      }
    }
 else     if (Shape.opIsWholeBufferWithMatchingStrides(op)) {
      double accum=op.zeroDouble();
      DataBuffer dx=op.x().data();
      for (int i=0; i < op.n(); i++) {
        accum=op.update(accum,dx.getDouble(i));
      }
    }
 else     if (!(op.x() instanceof IComplexNDArray)) {
      IComplexNumber accum=op.zeroComplex();
      if (op.y() != null) {
        INDArray xLinear=op.x().reshape(1,op.x().length());
        INDArray yLinear=op.y().reshape(1,op.y().length());
        for (int i=0; i < op.n(); i++) {
          accum=op.update(accum,xLinear.getDouble(0,i),yLinear.getDouble(0,i));
        }
      }
 else {
        INDArray xLinear=op.x().reshape(1,op.x().length());
        for (int i=0; i < op.n(); i++) {
          accum=op.update(accum,xLinear.getDouble(0,i));
        }
      }
    }
 else {
      for (int c=0; c < op.n(); c++) {
        apply(op,c);
      }
    }
  }
}
Program: 3318
Project: 3318
Buggy source:
@Override protected Double compute(){
  if (n > threshold) {
    int nFirst=n / 2;
    BaseAccumulationDataBufferTask t1=getSubTask(threshold,nFirst,x,y,offsetX,offsetY,incrX,incrY,false);
    int nSecond=n - nFirst;
    int offsetX2=offsetX + nFirst * incrX;
    int offsetY2=offsetY + nFirst * incrY;
    BaseAccumulationDataBufferTask t2=getSubTask(threshold,nSecond,x,y,offsetX2,offsetY2,incrX,incrY,false);
    t1.fork();
    t2.fork();
    double first=t1.join();
    double second=t2.join();
    double preFinalResult=op.combineSubResults(first,second);
    if (outerTask)     return op.getFinalResult(preFinalResult);
 else     return preFinalResult;
  }
 else {
    return doTask();
  }
}

Fixed version (ground truth):
@Override protected Double compute(){
  int tensorDim;
  if (y == null)   tensorDim=OpExecutionerUtil.chooseElementWiseTensorDimension(x);
 else   tensorDim=OpExecutionerUtil.chooseElementWiseTensorDimension(x,y);
  int nTensors=x.tensorssAlongDimension(tensorDim);
  if (nTensors == 1) {
    return new AccumulationOpDataBufferTask(op,0,tensorDim,threshold,x,y,true).invoke();
  }
 else {
    List<AccumulationOpDataBufferTask> blockList=new ArrayList<>(nTensors);
    for (int i=0; i < nTensors; i++) {
      AccumulationOpDataBufferTask task=new AccumulationOpDataBufferTask(op,i,tensorDim,threshold,x,y,false);
      task.fork();
    }
    double accum=op.zeroDouble();
    for (    AccumulationOpDataBufferTask task : blockList) {
      double subAccum=task.join();
      op.combineSubResults(accum,subAccum);
    }
    return op.getFinalResult(accum);
  }
}
Program: 3320
Project: 3320
Buggy source:
public AccumulationOpDataBufferTask(Accumulation op,int threshold,int n,DataBuffer x,DataBuffer y,int offsetX,int offsetY,int incrX,int incrY,boolean outerTask){
  super(op,threshold,n,x,y,offsetX,offsetY,incrX,incrY,outerTask);
}

Fixed version (ground truth):
public AccumulationOpDataBufferTask(Accumulation op,int tadIdx,int tadDim,int threshold,INDArray x,INDArray y,boolean outerTask){
  super(op,tadIdx,tadDim,threshold,x,y,outerTask);
}
Program: 3321
Project: 3321
Buggy source:
protected static INDArrayIndex validate(int size,INDArrayIndex index){
  if ((index instanceof IntervalIndex || index instanceof PointIndex) && size <= index.current())   throw new IllegalArgumentException("String_Node_Str" + index.current() + "String_Node_Str"+ size);
  if (index instanceof IntervalIndex && size < index.end()) {
    int begin=((IntervalIndex)index).begin;
    index=NDArrayIndex.interval(begin,index.stride(),size);
  }
  return index;
}

Fixed version (ground truth):
protected static INDArrayIndex validate(int size,INDArrayIndex index){
  if ((index instanceof IntervalIndex || index instanceof PointIndex) && size <= index.current() && size > 1)   throw new IllegalArgumentException("String_Node_Str" + index.current() + "String_Node_Str"+ size);
  if (index instanceof IntervalIndex && size < index.end()) {
    int begin=((IntervalIndex)index).begin;
    index=NDArrayIndex.interval(begin,index.stride(),size);
  }
  return index;
}
Program: 3324
Project: 3324
Buggy source:
public double score(){
  double ret=0.0;
switch (lossFunction) {
case CUSTOM:
    throw new IllegalStateException("String_Node_Str");
case RECONSTRUCTION_CROSSENTROPY:
  INDArray xEntLogZ2=log(z);
INDArray xEntOneMinusLabelsOut2=labels.rsub(1);
INDArray xEntOneMinusLogOneMinusZ2=log(z).rsubi(1);
ret=-labels.mul(xEntLogZ2).add(xEntOneMinusLabelsOut2).muli(xEntOneMinusLogOneMinusZ2).sumNumber().doubleValue();
break;
case MCXENT:
INDArray sums=labels.mul(log(z));
ret=-sums.sumNumber().doubleValue();
break;
case XENT:
INDArray xEntLogZ=log(z);
INDArray xEntOneMinusLabelsOut=labels.rsub(1);
INDArray xEntOneMinusLogOneMinusZ=log(z).rsubi(1);
ret=labels.mul(xEntLogZ).add(xEntOneMinusLabelsOut).muli(xEntOneMinusLogOneMinusZ).sum(1).sumNumber().doubleValue();
break;
case RMSE_XENT:
INDArray rmseXentDiff=delta == null ? labels.sub(z) : delta;
INDArray squaredrmseXentDiff=pow(rmseXentDiff,2.0);
INDArray sqrt=sqrt(squaredrmseXentDiff);
ret=sqrt.sumNumber().doubleValue();
break;
case MSE:
INDArray mseDelta=delta == null ? labels.sub(z) : delta;
ret=0.5 * pow(mseDelta,2).sum(1).sumNumber().doubleValue();
break;
case EXPLL:
INDArray expLLLogZ=log(z);
ret=z.sub(labels.mul(expLLLogZ)).sumNumber().doubleValue();
break;
case SQUARED_LOSS:
ret=pow(delta == null ? labels.sub(z) : delta,2).sumNumber().doubleValue();
break;
case NEGATIVELOGLIKELIHOOD:
INDArray log=log(z);
INDArray sums2=labels.mul(log);
ret=-sums2.sumNumber().doubleValue();
break;
}
if (useRegularization) {
ret+=l1 + l2;
}
if (miniBatch) ret/=(double)miniBatchSize;
return ret;
}

Fixed version (ground truth):
public double score(){
  double ret=0.0;
switch (lossFunction) {
case CUSTOM:
    throw new IllegalStateException("String_Node_Str");
case RECONSTRUCTION_CROSSENTROPY:
  INDArray xEntLogZ2=logZ(z);
INDArray xEntOneMinusLabelsOut2=labels.rsub(1);
INDArray xEntOneMinusLogOneMinusZ2=xEntLogZ2.dup().rsubi(1);
ret=-labels.mul(xEntLogZ2).add(xEntOneMinusLabelsOut2).muli(xEntOneMinusLogOneMinusZ2).sumNumber().doubleValue();
break;
case MCXENT:
INDArray sums=labels.mul(logZ(z));
ret=-sums.sumNumber().doubleValue();
break;
case XENT:
INDArray xEntLogZ=logZ(z);
INDArray xEntOneMinusLabelsOut=labels.rsub(1);
INDArray xEntOneMinusLogOneMinusZ=xEntLogZ.dup().rsubi(1);
ret=labels.mul(xEntLogZ).add(xEntOneMinusLabelsOut).muli(xEntOneMinusLogOneMinusZ).sum(1).sumNumber().doubleValue();
break;
case RMSE_XENT:
INDArray rmseXentDiff=delta == null ? labels.sub(z) : delta;
INDArray squaredrmseXentDiff=pow(rmseXentDiff,2.0);
INDArray sqrt=sqrt(squaredrmseXentDiff);
ret=sqrt.sumNumber().doubleValue();
break;
case MSE:
INDArray mseDelta=delta == null ? labels.sub(z) : delta;
ret=0.5 * pow(mseDelta,2).sum(1).sumNumber().doubleValue();
break;
case EXPLL:
INDArray expLLLogZ=logZ(z);
ret=z.sub(labels.mul(expLLLogZ)).sumNumber().doubleValue();
break;
case SQUARED_LOSS:
ret=pow(delta == null ? labels.sub(z) : delta,2).sumNumber().doubleValue();
break;
case NEGATIVELOGLIKELIHOOD:
INDArray log=logZ(z);
INDArray sums2=labels.mul(log);
ret=-sums2.sumNumber().doubleValue();
break;
}
if (useRegularization) {
ret+=l1 + l2;
}
if (miniBatch) ret/=(double)miniBatchSize;
return ret;
}
Program: 3326
Project: 3326
Buggy source:
@Override public void init(INDArray arr,int begin,int dimension){
  this.begin=0;
  this.end=arr.size(dimension);
}

Fixed version (ground truth):
@Override public void init(INDArray arr,int begin,int dimension){
  this.begin=0;
  this.end=arr.size(dimension);
  this.length=end;
}
Program: 3327
Project: 3327
Buggy source:
/** 
 * Number of slices: aka shape[0]
 * @return the number of slicesfor this nd array
 */
@Override public int slices(){
  if (shape.length < 1)   return 0;
  return shape[0];
}

Fixed version (ground truth):
/** 
 * Number of slices: aka shape[0]
 * @return the number of slicesfor this nd array
 */
@Override public int slices(){
  if (shape.length < 1)   return 0;
  if (isRowVector())   return length();
  return shape[0];
}
Program: 3329
Project: 3329
Buggy source:
@Test public void testSwapAxesFortranOrder(){
  INDArray n=Nd4j.create(Nd4j.linspace(1,30,30).data(),new int[]{3,5,2});
  for (int i=0; i < n.slices(); i++) {
    INDArray nSlice=n.slice(i);
    System.out.println(nSlice);
  }
  INDArray slice=n.swapAxes(2,1);
  INDArray assertion=Nd4j.create(new double[]{1,4,7,10,13});
  INDArray test=slice.slice(0).slice(0);
  assertEquals(assertion,test);
}

Fixed version (ground truth):
@Test public void testSwapAxesFortranOrder(){
  INDArray n=Nd4j.create(Nd4j.linspace(1,30,30).data(),new int[]{3,5,2});
  for (int i=0; i < n.slices(); i++) {
    INDArray nSlice=n.slice(i);
    for (int j=0; j < nSlice.slices(); j++) {
      INDArray sliceJ=nSlice.slice(j);
      System.out.println(sliceJ);
    }
    System.out.println(nSlice);
  }
  INDArray slice=n.swapAxes(2,1);
  INDArray assertion=Nd4j.create(new double[]{1,4,7,10,13});
  INDArray test=slice.slice(0).slice(0);
  assertEquals(assertion,test);
}
Program: 3330
Project: 3330
Buggy source:
@Test public void testShape(){
  INDArray ndarray=Nd4j.create(new float[][]{{1f,2f},{3f,4f}});
  INDArray subarray=ndarray.get(NDArrayIndex.point(0),NDArrayIndex.all());
  assertTrue(subarray.isRowVector());
  int[] shape=subarray.shape();
  assertEquals(shape[0],1);
  assertEquals(shape[0],2);
}

Fixed version (ground truth):
@Test public void testShape(){
  INDArray ndarray=Nd4j.create(new float[][]{{1f,2f},{3f,4f}});
  INDArray subarray=ndarray.get(NDArrayIndex.point(0),NDArrayIndex.all());
  assertTrue(subarray.isRowVector());
  int[] shape=subarray.shape();
  assertEquals(shape[0],1);
  assertEquals(shape[1],2);
}
Program: 3331
Project: 3331
Buggy source:
@Test public void testRowVectorInterval(){
  int len=30;
  INDArray row=Nd4j.zeros(len);
  for (int i=0; i < len; i++) {
    row.putScalar(i,i);
  }
  INDArray idx=Nd4j.zeros(1,2,3).slice(2,2);
  System.out.println(row.get(NDArrayIndex.point(0),NDArrayIndex.interval(0,10)));
  System.out.println(row.get(NDArrayIndex.point(0),NDArrayIndex.interval(20,30)));
  System.out.println(row.get(NDArrayIndex.interval(0,10)));
  System.out.println(row.get(NDArrayIndex.interval(20,30)));
  INDArray first10a=row.get(NDArrayIndex.point(0),NDArrayIndex.interval(0,10));
  assertArrayEquals(first10a.shape(),new int[]{1,10});
  for (int i=0; i < 10; i++)   assertTrue(first10a.getDouble(i) == i);
  INDArray first10b=row.get(NDArrayIndex.interval(0,10));
  assertArrayEquals(first10b.shape(),new int[]{1,10});
  for (int i=0; i < 10; i++)   assertTrue(first10b.getDouble(i) == i);
  INDArray last10a=row.get(NDArrayIndex.point(0),NDArrayIndex.interval(20,30));
  assertArrayEquals(last10a.shape(),new int[]{1,10});
  for (int i=0; i < 10; i++)   assertTrue(last10a.getDouble(i) == 20 + i);
  INDArray last10b=row.get(NDArrayIndex.interval(20,30));
  assertArrayEquals(last10b.shape(),new int[]{1,10});
  for (int i=0; i < 10; i++)   assertTrue(last10b.getDouble(i) == 20 + i);
}

Fixed version (ground truth):
@Test public void testRowVectorInterval(){
  int len=30;
  INDArray row=Nd4j.zeros(len);
  for (int i=0; i < len; i++) {
    row.putScalar(i,i);
  }
  INDArray first10a=row.get(NDArrayIndex.point(0),NDArrayIndex.interval(0,10));
  assertArrayEquals(first10a.shape(),new int[]{1,10});
  for (int i=0; i < 10; i++)   assertTrue(first10a.getDouble(i) == i);
  INDArray first10b=row.get(NDArrayIndex.interval(0,10));
  assertArrayEquals(first10b.shape(),new int[]{1,10});
  for (int i=0; i < 10; i++)   assertTrue(first10b.getDouble(i) == i);
  INDArray last10a=row.get(NDArrayIndex.point(0),NDArrayIndex.interval(20,30));
  assertArrayEquals(last10a.shape(),new int[]{1,10});
  for (int i=0; i < 10; i++)   assertTrue(last10a.getDouble(i) == 20 + i);
  INDArray last10b=row.get(NDArrayIndex.interval(20,30));
  assertArrayEquals(last10b.shape(),new int[]{1,10});
  for (int i=0; i < 10; i++)   assertTrue(last10b.getDouble(i) == 20 + i);
}
Program: 3332
Project: 3332
Buggy source:
@Override public void init(int begin,int end){
  this.begin=begin;
  this.index=begin;
  this.end=inclusive ? end + 1 : end;
  for (int i=begin; i < end; i+=stride) {
    length++;
  }
}

Fixed version (ground truth):
@Override public void init(int begin,int end){
  this.begin=begin;
  this.index=begin;
  this.end=inclusive ? end + 1 : end;
  for (int i=begin; i < this.end; i+=stride) {
    length++;
  }
}
Program: 3333
Project: 3333
Buggy source:
/** 
 * See: http://www.mathworks.com/help/matlab/ref/permute.htsliceml
 * @param rearrange the dimensions to swap to
 * @return the newly permuted array
 */
@Override public INDArray permute(int... rearrange){
  if (rearrange.length != shape.length)   return dup();
  checkArrangeArray(rearrange);
  int[] newShape=doPermuteSwap(shape,rearrange);
  int[] newStride=doPermuteSwap(stride,rearrange);
  INDArray value=create(data(),newShape,newStride,offset(),ordering());
  return value;
}

Fixed version (ground truth):
/** 
 * See: http://www.mathworks.com/help/matlab/ref/permute.htsliceml
 * @param rearrange the dimensions to swap to
 * @return the newly permuted array
 */
@Override public INDArray permute(int... rearrange){
  if (rearrange.length != shape.length)   return dup();
  checkArrangeArray(rearrange);
  int[] newShape=doPermuteSwap(shape,rearrange);
  int[] newStride=doPermuteSwap(stride,rearrange);
  char newOrder=Shape.getOrder(newShape,newStride,elementStride());
  INDArray value=create(data(),newShape,newStride,offset(),newOrder);
  return value;
}
Program: 3336
Project: 3336
Buggy source:
@Test public void testTensorDot(){
  INDArray oneThroughSixty=Nd4j.arange(60).reshape(3,4,5);
  INDArray oneThroughTwentyFour=Nd4j.arange(24).reshape(4,3,2);
  INDArray result=Nd4j.tensorMmul(oneThroughSixty,oneThroughTwentyFour,new int[][]{{1,0},{0,1}});
  assertArrayEquals(new int[]{5,2},result.shape());
  INDArray assertion=Nd4j.create(new double[][]{{4400,4730},{4532,4874},{4664,5018},{4796,5162},{4928,5306}});
  assertEquals(assertion,result);
}

Fixed version (ground truth):
@Test public void testTensorDot(){
  INDArray w=Nd4j.valueArrayOf(new int[]{2,1,2,2},0.5);
  INDArray col=Nd4j.create(new double[]{1,1,1,1,3,3,3,3,1,1,1,1,3,3,3,3,1,1,1,1,3,3,3,3,1,1,1,1,3,3,3,3,2,2,2,2,4,4,4,4,2,2,2,2,4,4,4,4,2,2,2,2,4,4,4,4,2,2,2,2,4,4,4,4},new int[]{1,1,2,2,4,4});
  INDArray test=Nd4j.tensorMmul(col,w,new int[][]{{1,2,3},{1,2,3}});
  INDArray assertion2=Nd4j.create(new double[]{3.,3.,3.,3.,3.,3.,3.,3.,7.,7.,7.,7.,7.,7.,7.,7.,3.,3.,3.,3.,3.,3.,3.,3.,7.,7.,7.,7.,7.,7.,7.,7.},new int[]{1,4,4,2},new int[]{16,8,2,1},0,'f');
  assertion2.setOrder('f');
  assertEquals(assertion2,test);
  INDArray oneThroughSixty=Nd4j.arange(60).reshape(3,4,5);
  INDArray oneThroughTwentyFour=Nd4j.arange(24).reshape(4,3,2);
  INDArray result=Nd4j.tensorMmul(oneThroughSixty,oneThroughTwentyFour,new int[][]{{1,0},{0,1}});
  assertArrayEquals(new int[]{5,2},result.shape());
  INDArray assertion=Nd4j.create(new double[][]{{4400,4730},{4532,4874},{4664,5018},{4796,5162},{4928,5306}},'f');
  assertEquals(assertion,result);
}
Program: 3337
Project: 3337
Buggy source:
@Override protected void sgemm(char Order,char TransA,char TransB,int M,int N,int K,float alpha,INDArray A,int lda,INDArray B,int ldb,float beta,INDArray C,int ldc){
  A=Shape.toOffsetZero(A);
  B=Shape.toOffsetZero(B);
  DataBuffer aData=A.data();
  DataBuffer bData=B.data();
  float[] cData=getFloatData(C);
  BLAS.getInstance().sgemm(String.valueOf(TransA),String.valueOf(TransB),M,N,K,alpha,aData.asFloat(),getBlasOffset(A),lda,bData.asFloat(),getBlasOffset(B),ldb,beta,cData,getBlasOffset(C),ldc);
  setData(cData,C);
}

Fixed version (ground truth):
@Override protected void sgemm(char Order,char TransA,char TransB,int M,int N,int K,float alpha,INDArray A,int lda,INDArray B,int ldb,float beta,INDArray C,int ldc){
  DataBuffer aData=A.data();
  DataBuffer bData=B.data();
  float[] cData=getFloatData(C);
  BLAS.getInstance().sgemm(String.valueOf(TransA),String.valueOf(TransB),M,N,K,alpha,aData.asFloat(),getBlasOffset(A),lda,bData.asFloat(),getBlasOffset(B),ldb,beta,cData,getBlasOffset(C),ldc);
  setData(cData,C);
}
Program: 3338
Project: 3338
Buggy source:
protected void collectRows(INDArray slice){
  if (slice.isRowVector()) {
    vectors.add(slice);
  }
 else   if (isMatrix()) {
    for (int i=0; i < slice.rows(); i++)     vectors.add(slice.getRow(i));
  }
 else   for (int i=0; i < slice.slices(); i++)   collectRows(slice.slice(i));
}

Fixed version (ground truth):
protected void collectRows(INDArray slice){
  if (slice.isRowVector()) {
    vectors.add(slice);
  }
 else   if (slice.isMatrix()) {
    for (int i=0; i < slice.rows(); i++)     vectors.add(slice.getRow(i));
  }
 else   for (int i=0; i < slice.slices(); i++)   collectRows(slice.slice(i));
}
Program: 3341
Project: 3341
Buggy source:
/** 
 * Start the server
 */
public void start(){
  try {
    InputStream is=new ClassPathResource(resourcePath).getInputStream();
    File tmpConfig=new File(resourcePath);
    if (!tmpConfig.getParentFile().exists())     tmpConfig.getParentFile().mkdirs();
    BufferedOutputStream bos=new BufferedOutputStream(new FileOutputStream(tmpConfig));
    IOUtils.copy(is,bos);
    bos.flush();
    run(new String[]{"String_Node_Str",tmpConfig.getAbsolutePath()});
    tmpConfig.deleteOnExit();
  }
 catch (  Exception e) {
    throw new RuntimeException(e);
  }
}

Fixed version (ground truth):
/** 
 * Start the server
 */
public void start(){
  try {
    InputStream is=new ClassPathResource(resourcePath,InstrumentationApplication.class.getClassLoader()).getInputStream();
    File tmpConfig=new File(resourcePath);
    if (!tmpConfig.getParentFile().exists())     tmpConfig.getParentFile().mkdirs();
    BufferedOutputStream bos=new BufferedOutputStream(new FileOutputStream(tmpConfig));
    IOUtils.copy(is,bos);
    bos.flush();
    run(new String[]{"String_Node_Str",tmpConfig.getAbsolutePath()});
    tmpConfig.deleteOnExit();
  }
 catch (  Exception e) {
    throw new RuntimeException(e);
  }
}
Program: 3342
Project: 3342
Buggy source:
@Override public Resource getConfigurationResource(){
  return new ClassPathResource(LINALG_PROPS);
}

Fixed version (ground truth):
@Override public Resource getConfigurationResource(){
  return new ClassPathResource(LINALG_PROPS,JavaBackend.class.getClassLoader());
}
Program: 3343
Project: 3343
Buggy source:
@Override public Resource getConfigurationResource(){
  return new ClassPathResource(LINALG_PROPS);
}

Fixed version (ground truth):
@Override public Resource getConfigurationResource(){
  return new ClassPathResource(LINALG_PROPS,JblasBackend.class.getClassLoader());
}
Program: 3344
Project: 3344
Buggy source:
@Test public void testLoader() throws Exception {
  Nd4j.dtype=DataBuffer.Type.DOUBLE;
  KernelFunctionLoader loader=KernelFunctionLoader.getInstance();
  loader.load();
  ClassPathResource res=new ClassPathResource("String_Node_Str");
  if (!res.exists())   throw new IllegalStateException("String_Node_Str");
  Properties props=new Properties();
  props.load(res.getInputStream());
  loader.unload();
}

Fixed version (ground truth):
@Test public void testLoader() throws Exception {
  Nd4j.dtype=DataBuffer.Type.DOUBLE;
  KernelFunctionLoader loader=KernelFunctionLoader.getInstance();
  loader.load();
  ClassPathResource res=new ClassPathResource("String_Node_Str",KernelFunctionLoader.class.getClassLoader());
  if (!res.exists())   throw new IllegalStateException("String_Node_Str");
  Properties props=new Properties();
  props.load(res.getInputStream());
  loader.unload();
}
Program: 3345
Project: 3345
Buggy source:
@Override public Resource getConfigurationResource(){
  return new ClassPathResource(LINALG_PROPS);
}

Fixed version (ground truth):
@Override public Resource getConfigurationResource(){
  return new ClassPathResource(LINALG_PROPS,JCublasBackend.class.getClassLoader());
}
Program: 3346
Project: 3346
Buggy source:
/** 
 * Configure the given information based on the device
 */
public void configure(){
  if (confCalled)   return;
  syncThreads=Boolean.parseBoolean(System.getProperty(SYNC_THREADS,"String_Node_Str"));
  if (numDevices == 0) {
    getNumDevices();
  }
  for (int i=0; i < numDevices; i++) {
    ClassPathResource confFile=new ClassPathResource("String_Node_Str" + i);
    if (confFile.exists()) {
      Properties props=new Properties();
      try {
        props.load(confFile.getInputStream());
        confs.put(i,new DeviceConfiguration(i,props));
      }
 catch (      IOException e) {
        throw new RuntimeException(e);
      }
    }
 else     confs.put(i,new DeviceConfiguration(i));
  }
  confCalled=true;
}

Fixed version (ground truth):
/** 
 * Configure the given information based on the device
 */
public void configure(){
  if (confCalled)   return;
  syncThreads=Boolean.parseBoolean(System.getProperty(SYNC_THREADS,"String_Node_Str"));
  if (numDevices == 0) {
    getNumDevices();
  }
  for (int i=0; i < numDevices; i++) {
    ClassPathResource confFile=new ClassPathResource("String_Node_Str" + i,ContextHolder.class.getClassLoader());
    if (confFile.exists()) {
      Properties props=new Properties();
      try {
        props.load(confFile.getInputStream());
        confs.put(i,new DeviceConfiguration(i,props));
      }
 catch (      IOException e) {
        throw new RuntimeException(e);
      }
    }
 else     confs.put(i,new DeviceConfiguration(i));
  }
  confCalled=true;
}
Program: 3347
Project: 3347
Buggy source:
/** 
 * Singleton pattern
 * @return the instance for the context holder.
 */
public static synchronized ContextHolder getInstance(){
  if (INSTANCE == null) {
    Properties props=new Properties();
    try {
      props.load(new ClassPathResource("String_Node_Str").getInputStream());
    }
 catch (    IOException e) {
      throw new RuntimeException(e);
    }
    INSTANCE=new ContextHolder();
    INSTANCE.configure();
    for (    String pair : props.stringPropertyNames())     System.getProperties().put(pair,props.getProperty(pair));
    Runtime.getRuntime().addShutdownHook(new Thread(new Runnable(){
      @Override public void run(){
        INSTANCE.destroy();
      }
    }
));
  }
  return INSTANCE;
}

Fixed version (ground truth):
/** 
 * Singleton pattern
 * @return the instance for the context holder.
 */
public static synchronized ContextHolder getInstance(){
  if (INSTANCE == null) {
    Properties props=new Properties();
    try {
      props.load(new ClassPathResource("String_Node_Str",ContextHolder.class.getClassLoader()).getInputStream());
    }
 catch (    IOException e) {
      throw new RuntimeException(e);
    }
    INSTANCE=new ContextHolder();
    INSTANCE.configure();
    for (    String pair : props.stringPropertyNames())     System.getProperties().put(pair,props.getProperty(pair));
    Runtime.getRuntime().addShutdownHook(new Thread(new Runnable(){
      @Override public void run(){
        INSTANCE.destroy();
      }
    }
));
  }
  return INSTANCE;
}
Program: 3348
Project: 3348
Buggy source:
/** 
 * Load the appropriate functions from the class path in to one module
 * @return the module associated with this
 * @throws Exception
 */
public void load() throws Exception {
  if (init)   return;
  StringBuffer sb=new StringBuffer();
  sb.append("String_Node_Str");
  ClassPathResource res=new ClassPathResource("String_Node_Str");
  if (!res.exists())   throw new IllegalStateException("String_Node_Str");
  Properties props=new Properties();
  props.load(res.getInputStream());
  log.info("String_Node_Str");
  ensureImports(props,"String_Node_Str");
  ensureImports(props,"String_Node_Str");
  compileAndLoad(props,FLOAT,"String_Node_Str");
  compileAndLoad(props,DOUBLE,"String_Node_Str");
  init=true;
}

Fixed version (ground truth):
/** 
 * Load the appropriate functions from the class path in to one module
 * @return the module associated with this
 * @throws Exception
 */
public void load() throws Exception {
  if (init)   return;
  StringBuffer sb=new StringBuffer();
  sb.append("String_Node_Str");
  ClassPathResource res=new ClassPathResource("String_Node_Str",KernelFunctionLoader.class.getClassLoader());
  if (!res.exists())   throw new IllegalStateException("String_Node_Str");
  Properties props=new Properties();
  props.load(res.getInputStream());
  log.info("String_Node_Str");
  ensureImports(props,"String_Node_Str");
  ensureImports(props,"String_Node_Str");
  compileAndLoad(props,FLOAT,"String_Node_Str");
  compileAndLoad(props,DOUBLE,"String_Node_Str");
  init=true;
}
Program: 3349
Project: 3349
Buggy source:
private String loadFile(String file) throws IOException {
  ClassPathResource resource=new ClassPathResource(file);
  String tmpDir=System.getProperty("String_Node_Str");
  if (!resource.exists())   throw new IllegalStateException("String_Node_Str" + resource);
  File out=new File(tmpDir,file);
  if (!out.getParentFile().exists())   out.getParentFile().mkdirs();
  if (out.exists())   out.delete();
  out.createNewFile();
  BufferedOutputStream bos=new BufferedOutputStream(new FileOutputStream(out));
  IOUtils.copy(resource.getInputStream(),bos);
  bos.flush();
  bos.close();
  out.deleteOnExit();
  return out.getAbsolutePath();
}

Fixed version (ground truth):
private String loadFile(String file) throws IOException {
  ClassPathResource resource=new ClassPathResource(file,KernelFunctionLoader.class.getClassLoader());
  String tmpDir=System.getProperty("String_Node_Str");
  if (!resource.exists())   throw new IllegalStateException("String_Node_Str" + resource);
  File out=new File(tmpDir,file);
  if (!out.getParentFile().exists())   out.getParentFile().mkdirs();
  if (out.exists())   out.delete();
  out.createNewFile();
  BufferedOutputStream bos=new BufferedOutputStream(new FileOutputStream(out));
  IOUtils.copy(resource.getInputStream(),bos);
  bos.flush();
  bos.close();
  out.deleteOnExit();
  return out.getAbsolutePath();
}