nus-yam/ex-repair huggingface dataset:
Program: 3242
Project: 3242
Buggy source:
private String[] writeData(DataSet write) throws IOException {
  String[] ret=new String[2];
  String dataSetId=UUID.randomUUID().toString();
  BufferedOutputStream dataOut=new BufferedOutputStream(new FileOutputStream(new File(rootDir,dataSetId + "String_Node_Str")));
  DataOutputStream dos=new DataOutputStream(dataOut);
  Nd4j.write(write.getFeatureMatrix(),dos);
  dos.flush();
  dos.close();
  BufferedOutputStream dataOutLabels=new BufferedOutputStream(new FileOutputStream(new File(rootDir,dataSetId + "String_Node_Str")));
  DataOutputStream dosLabels=new DataOutputStream(dataOutLabels);
  Nd4j.write(write.getLabels(),dosLabels);
  dosLabels.flush();
  dos.close();
  ret[0]=new File(rootDir,dataSetId + "String_Node_Str").getAbsolutePath();
  ret[1]=new File(rootDir,dataSetId + "String_Node_Str").getAbsolutePath();
  return ret;
}

Fixed version (ground truth):
private String[] writeData(DataSet write) throws IOException {
  String[] ret=new String[2];
  String dataSetId=UUID.randomUUID().toString();
  BufferedOutputStream dataOut=new BufferedOutputStream(new FileOutputStream(new File(rootDir,dataSetId + "String_Node_Str")));
  DataOutputStream dos=new DataOutputStream(dataOut);
  Nd4j.write(write.getFeatureMatrix(),dos);
  dos.flush();
  dos.close();
  BufferedOutputStream dataOutLabels=new BufferedOutputStream(new FileOutputStream(new File(rootDir,dataSetId + "String_Node_Str")));
  DataOutputStream dosLabels=new DataOutputStream(dataOutLabels);
  Nd4j.write(write.getLabels(),dosLabels);
  dosLabels.flush();
  dosLabels.close();
  ret[0]=new File(rootDir,dataSetId + "String_Node_Str").getAbsolutePath();
  ret[1]=new File(rootDir,dataSetId + "String_Node_Str").getAbsolutePath();
  return ret;
}
Program: 3243
Project: 3243
Buggy source:
@Override public DataSet get(String key){
  DataSet dataSet=null;
  if (memoryCache.contains(key)) {
    dataSet=memoryCache.get(key);
    if (!fileCache.contains(key)) {
      fileCache.put(key,dataSet);
    }
  }
 else   if (fileCache.contains(key)) {
    dataSet=fileCache.get(key);
    if (!memoryCache.contains(key)) {
      memoryCache.put(key,dataSet);
    }
  }
  return dataSet;
}

Fixed version (ground truth):
@Override public DataSet get(String key){
  DataSet dataSet=null;
  if (memoryCache.contains(key)) {
    dataSet=memoryCache.get(key);
    if (!fileCache.contains(key)) {
      fileCache.put(key,dataSet);
    }
  }
 else   if (fileCache.contains(key)) {
    dataSet=fileCache.get(key);
    if (dataSet != null && !memoryCache.contains(key)) {
      memoryCache.put(key,dataSet);
    }
  }
  return dataSet;
}
Program: 3244
Project: 3244
Buggy source:
@Test public void testResponse() throws Exception {
  int streamId=10;
  int responderStreamId=11;
  String host="String_Node_Str";
  AeronNDArrayResponder responder=AeronNDArrayResponder.startSubscriber(getContext2(),host,40124,null,responderStreamId);
  AtomicInteger count=new AtomicInteger(0);
  AtomicBoolean running=new AtomicBoolean(true);
  AeronNDArraySubscriber subscriber=AeronNDArraySubscriber.startSubscriber(getContext(),host,40123,arr -> count.incrementAndGet(),streamId,running);
  int expectedResponses=10;
  HostPortPublisher publisher=HostPortPublisher.builder().ctx(getContext2()).uriToSend(host + "String_Node_Str" + streamId).channel(AeronUtil.aeronChannel(host,40124)).streamId(responderStreamId).build();
  Thread.sleep(10000);
  for (int i=0; i < expectedResponses; i++) {
    publisher.send();
  }
  Thread.sleep(60000);
  publisher.close();
  assertEquals(expectedResponses,count.get());
  System.out.println("String_Node_Str");
}

Fixed version (ground truth):
@Test public void testResponse() throws Exception {
  int streamId=10;
  int responderStreamId=11;
  String host="String_Node_Str";
  AeronNDArrayResponder responder=AeronNDArrayResponder.startSubscriber(getContext2(),host,40124,new NDArrayHolder(){
    /** 
 * The number of updates that have been sent to this older.
 * @return
 */
    @Override public int totalUpdates(){
      return 1;
    }
    /** 
 * Retrieve an ndarray
 * @return
 */
    @Override public INDArray get(){
      return Nd4j.scalar(1.0);
    }
  }
,responderStreamId);
  AtomicInteger count=new AtomicInteger(0);
  AtomicBoolean running=new AtomicBoolean(true);
  AeronNDArraySubscriber subscriber=AeronNDArraySubscriber.startSubscriber(getContext(),host,40123,arr -> count.incrementAndGet(),streamId,running);
  int expectedResponses=10;
  HostPortPublisher publisher=HostPortPublisher.builder().ctx(getContext2()).uriToSend(host + "String_Node_Str" + streamId).channel(AeronUtil.aeronChannel(host,40124)).streamId(responderStreamId).build();
  Thread.sleep(10000);
  for (int i=0; i < expectedResponses; i++) {
    publisher.send();
  }
  Thread.sleep(60000);
  publisher.close();
  assertEquals(expectedResponses,count.get());
  System.out.println("String_Node_Str");
}
Program: 3245
Project: 3245
Buggy source:
public LossFunctionGradientChecks(Nd4jBackend backend){
  super(backend);
}

Fixed version (ground truth):
public LossFunctionGradientChecks(Nd4jBackend backend){
  super(backend);
  this.initialType=Nd4j.dataType();
}
Program: 3246
Project: 3246
Buggy source:
@Override public INDArray computeGradient(INDArray labels,INDArray preOutput,String activationFn,INDArray mask){
  INDArray gradients=super.computeGradient(labels,preOutput,activationFn,mask);
  gradients.muli(1.0 / labels.size(1));
  return gradients;
}

Fixed version (ground truth):
@Override public INDArray computeGradient(INDArray labels,INDArray preOutput,String activationFn,INDArray mask){
  INDArray gradients=super.computeGradient(labels,preOutput,activationFn,mask);
  gradients.divi(labels.size(1));
  return gradients;
}
Program: 3247
Project: 3247
Buggy source:
@Override public INDArray computeScoreArray(INDArray labels,INDArray preOutput,String activationFn,INDArray mask){
  INDArray scoreArr=super.computeScoreArray(labels,preOutput,activationFn,mask);
  scoreArr.muli(1 / scoreArr.size(1));
  return scoreArr;
}

Fixed version (ground truth):
@Override public INDArray computeScoreArray(INDArray labels,INDArray preOutput,String activationFn,INDArray mask){
  INDArray scoreArr=super.computeScoreArray(labels,preOutput,activationFn,mask);
  scoreArr.divi(scoreArr.size(1));
  return scoreArr;
}
Program: 3248
Project: 3248
Buggy source:
/** 
 * This method frees native system memory referenced by specified tracking id/AllocationPoint
 * @param bucketId
 * @param objectId
 * @param point
 * @param copyback
 */
protected void purgeZeroObject(Long bucketId,Long objectId,AllocationPoint point,boolean copyback){
  allocationsMap.remove(objectId);
  memoryHandler.purgeZeroObject(bucketId,objectId,point,copyback);
}

Fixed version (ground truth):
/** 
 * This method frees native system memory referenced by specified tracking id/AllocationPoint
 * @param bucketId
 * @param objectId
 * @param point
 * @param copyback
 */
protected void purgeZeroObject(Long bucketId,Long objectId,AllocationPoint point,boolean copyback){
  allocationsMap.remove(objectId);
  memoryHandler.purgeZeroObject(bucketId,objectId,point,copyback);
  EventsProvider.getInstance().storeEvent(point.getLastWriteEvent());
  EventsProvider.getInstance().storeEvent(point.getLastReadEvent());
}
Program: 3249
Project: 3249
Buggy source:
public synchronized void destroy(){
  if (!isDestroyed()) {
    NativeOpsHolder.getInstance().getDeviceNativeOps().destroyEvent(this);
    markDestoryed();
  }
}

Fixed version (ground truth):
public void destroy(){
  if (!isDestroyed()) {
    NativeOpsHolder.getInstance().getDeviceNativeOps().destroyEvent(this);
    markDestoryed();
  }
}
Program: 3250
Project: 3250
Buggy source:
public synchronized void synchronize(){
  if (!isDestroyed()) {
    NativeOpsHolder.getInstance().getDeviceNativeOps().eventSynchronize(this);
  }
}

Fixed version (ground truth):
public void synchronize(){
  if (!isDestroyed()) {
    NativeOpsHolder.getInstance().getDeviceNativeOps().eventSynchronize(this);
  }
}
Program: 3251
Project: 3251
Buggy source:
@Override public void waitTillFinished(AllocationPoint point){
  CudaContext context=point.getCurrentContext();
  if (context == null)   context=(CudaContext)allocator.getDeviceContext().getContext();
  context.syncOldStream();
}

Fixed version (ground truth):
@Override public void waitTillFinished(AllocationPoint point){
  if (point.getLastWriteEvent() != null) {
    point.getLastWriteEvent().synchronize();
  }
}
Program: 3252
Project: 3252
Buggy source:
@Override public void registerAction(CudaContext context,AllocationPoint result,AllocationPoint... operands){
  context.syncOldStream();
}

Fixed version (ground truth):
public void registerAction(CudaContext context,INDArray result,INDArray... operands){
  if (result == null)   return;
  AllocationPoint point=allocator.getAllocationPoint(result);
  point.tickDeviceWrite();
  EventsProvider.getInstance().storeEvent(point.getLastWriteEvent());
  point.setLastWriteEvent(EventsProvider.getInstance().getEvent());
  point.getLastWriteEvent().register(context.getOldStream());
  for (  INDArray operand : operands) {
    if (operand == null)     continue;
    AllocationPoint pointOperand=allocator.getAllocationPoint(operand);
    EventsProvider.getInstance().storeEvent(pointOperand.getLastReadEvent());
    pointOperand.setLastReadEvent(EventsProvider.getInstance().getEvent());
    pointOperand.getLastReadEvent().register(context.getOldStream());
  }
}
Program: 3253
Project: 3253
Buggy source:
@Override public void waitTillReleased(AllocationPoint point){
  waitTillFinished(point);
}

Fixed version (ground truth):
@Override public void waitTillReleased(AllocationPoint point){
  waitTillFinished(point);
  if (point.getLastReadEvent() != null)   point.getLastReadEvent().synchronize();
}
Program: 3254
Project: 3254
Buggy source:
@Override public boolean equals(Object o){
  if (o != null)   AtomicAllocator.getInstance().synchronizeHostData((INDArray)o);
  AtomicAllocator.getInstance().synchronizeHostData(this);
  return super.equals(o);
}

Fixed version (ground truth):
@Override public boolean equals(Object o){
  return super.equals(o);
}
Program: 3255
Project: 3255
Buggy source:
@Override public DataSet next(){
  String key=makeKey(currentIndex);
  DataSet ds=null;
  if (cache.contains(key)) {
    ds=cache.get(key);
  }
 else {
    ds=sourceIterator.next();
    if (preProcessor != null) {
      preProcessor.preProcess(ds);
    }
    cache.put(key,ds);
  }
  currentIndex+=1;
  return ds;
}

Fixed version (ground truth):
@Override public DataSet next(){
  String key=makeKey(currentIndex);
  DataSet ds;
  if (usingCache) {
    ds=cache.get(key);
  }
 else {
    ds=sourceIterator.next();
    if (preProcessor != null) {
      preProcessor.preProcess(ds);
    }
    cache.put(key,ds);
  }
  currentIndex+=1;
  return ds;
}
Program: 3256
Project: 3256
Buggy source:
@Override public boolean hasNext(){
  return sourceIterator.hasNext() || cache.contains(makeKey(currentIndex));
}

Fixed version (ground truth):
@Override public boolean hasNext(){
  if (usingCache) {
    return cache.contains(makeKey(currentIndex));
  }
 else {
    if (sourceIterator.hasNext()) {
      return true;
    }
 else {
      usingCache=true;
      cache.setComplete(namespace,true);
      return false;
    }
  }
}
Program: 3257
Project: 3257
Buggy source:
@Override public void put(String key,DataSet dataSet){
  File file=resolveKey(key);
  if (file.exists()) {
    throw new IllegalStateException("String_Node_Str" + file + "String_Node_Str");
  }
 else {
    File parentDir=file.getParentFile();
    if (!parentDir.exists()) {
      if (!parentDir.mkdirs()) {
        throw new IllegalStateException("String_Node_Str" + parentDir);
      }
    }
    dataSet.save(file);
  }
}

Fixed version (ground truth):
@Override public void put(String key,DataSet dataSet){
  File file=resolveKey(key);
  File parentDir=file.getParentFile();
  if (!parentDir.exists()) {
    if (!parentDir.mkdirs()) {
      throw new IllegalStateException("String_Node_Str" + parentDir);
    }
  }
  if (file.exists()) {
    file.delete();
  }
  dataSet.save(file);
}
Program: 3258
Project: 3258
Buggy source:
private void runDataSetTest(DataSetCache cache){
  DataSet dataSet=new DataSet(Nd4j.ones(500,100),Nd4j.zeros(500,2));
  DataSetIterator it=new SamplingDataSetIterator(dataSet,10,50);
  DataSetIterator cachedIt=new CachingDataSetIterator(it,cache);
  while (cachedIt.hasNext()) {
    cachedIt.next();
  }
  cachedIt.reset();
  it.reset();
  dataSet.setFeatures(Nd4j.zeros(500,100));
  dataSet.setLabels(Nd4j.ones(500,2));
  while (it.hasNext()) {
    assertTrue(cachedIt.hasNext());
    DataSet cachedDs=cachedIt.next();
    assertEquals(1000.0,cachedDs.getFeatureMatrix().sumNumber());
    assertEquals(0.0,cachedDs.getLabels().sumNumber());
    DataSet ds=it.next();
    assertEquals(0.0,ds.getFeatureMatrix().sumNumber());
    assertEquals(20.0,ds.getLabels().sumNumber());
  }
}

Fixed version (ground truth):
private void runDataSetTest(DataSetCache cache){
  DataSet dataSet=new DataSet(Nd4j.ones(500,100),Nd4j.zeros(500,2));
  DataSetIterator it=new SamplingDataSetIterator(dataSet,10,50);
  String namespace="String_Node_Str";
  DataSetIterator cachedIt=new CachingDataSetIterator(it,cache,namespace);
  while (cachedIt.hasNext()) {
    assertFalse(cache.isComplete(namespace));
    cachedIt.next();
  }
  assertTrue(cache.isComplete(namespace));
  cachedIt.reset();
  it.reset();
  dataSet.setFeatures(Nd4j.zeros(500,100));
  dataSet.setLabels(Nd4j.ones(500,2));
  while (it.hasNext()) {
    assertTrue(cachedIt.hasNext());
    DataSet cachedDs=cachedIt.next();
    assertEquals(1000.0,cachedDs.getFeatureMatrix().sumNumber());
    assertEquals(0.0,cachedDs.getLabels().sumNumber());
    DataSet ds=it.next();
    assertEquals(0.0,ds.getFeatureMatrix().sumNumber());
    assertEquals(20.0,ds.getLabels().sumNumber());
  }
  assertFalse(cachedIt.hasNext());
  assertFalse(it.hasNext());
}
Program: 3259
Project: 3259
Buggy source:
@Test public void testEpsOps(){
  INDArray ones=Nd4j.ones(6);
  double tiny=1.000000000000000000000000000001;
  assertTrue(ones.eps(tiny).sumNumber().doubleValue() == 6);
  INDArray consec=Nd4j.linspace(1,6,6);
  assertTrue(consec.eps(5).sumNumber().doubleValue() == 1);
  assertTrue(consec.sub(1).eps(5).sumNumber().doubleValue() == 1);
  assertTrue(consec.sub(1).eps(5).getDouble(0,5) == 1);
}

Fixed version (ground truth):
@Test public void testEpsOps(){
  INDArray ones=Nd4j.ones(6);
  double tiny=1.000000000000001;
  assertTrue(ones.eps(tiny).sumNumber().doubleValue() == 6);
  INDArray consec=Nd4j.linspace(1,6,6);
  assertTrue(consec.eps(5).sumNumber().doubleValue() == 1);
  assertTrue(consec.sub(1).eps(5).sumNumber().doubleValue() == 1);
  assertTrue(consec.sub(1).eps(5).getDouble(0,5) == 1);
}
Program: 3260
Project: 3260
Buggy source:
protected BaseDataBuffer(long length,boolean initialize){
  if (length < 1)   throw new IllegalArgumentException("String_Node_Str");
  this.length=length;
  this.underlyingLength=length;
  allocationMode=AllocUtil.getAllocationModeFromContext();
  if (length < 0)   throw new IllegalArgumentException("String_Node_Str");
  if (allocationMode == AllocationMode.HEAP) {
    if (length >= Integer.MAX_VALUE)     throw new IllegalArgumentException("String_Node_Str");
    if (dataType() == Type.DOUBLE)     doubleData=new double[(int)length];
 else     if (dataType() == Type.FLOAT)     floatData=new float[(int)length];
  }
 else   if (allocationMode == AllocationMode.JAVACPP) {
    if (dataType() == Type.DOUBLE) {
      pointer=new DoublePointer(length());
      indexer=DoubleIndexer.create((DoublePointer)pointer);
      if (initialize)       fillPointerWithZero();
    }
 else     if (dataType() == Type.FLOAT) {
      pointer=new FloatPointer(length());
      indexer=FloatIndexer.create((FloatPointer)pointer);
      if (initialize)       fillPointerWithZero();
    }
 else     if (dataType() == Type.INT) {
      pointer=new IntPointer(length());
      indexer=IntIndexer.create((IntPointer)pointer);
      if (initialize)       fillPointerWithZero();
    }
  }
 else {
    if (length * getElementSize() < 0)     throw new IllegalArgumentException("String_Node_Str" + length + "String_Node_Str");
    wrappedBuffer=ByteBuffer.allocateDirect((int)(getElementSize() * length)).order(ByteOrder.nativeOrder());
  }
}

Fixed version (ground truth):
protected BaseDataBuffer(long length,boolean initialize){
  if (length < 1)   throw new IllegalArgumentException("String_Node_Str");
  initTypeAndSize();
  this.length=length;
  this.underlyingLength=length;
  allocationMode=AllocUtil.getAllocationModeFromContext();
  if (length < 0)   throw new IllegalArgumentException("String_Node_Str");
  if (allocationMode == AllocationMode.HEAP) {
    if (length >= Integer.MAX_VALUE)     throw new IllegalArgumentException("String_Node_Str");
    if (dataType() == Type.DOUBLE)     doubleData=new double[(int)length];
 else     if (dataType() == Type.FLOAT)     floatData=new float[(int)length];
  }
 else   if (allocationMode == AllocationMode.JAVACPP) {
    if (dataType() == Type.DOUBLE) {
      pointer=new DoublePointer(length());
      indexer=DoubleIndexer.create((DoublePointer)pointer);
      if (initialize)       fillPointerWithZero();
    }
 else     if (dataType() == Type.FLOAT) {
      pointer=new FloatPointer(length());
      indexer=FloatIndexer.create((FloatPointer)pointer);
      if (initialize)       fillPointerWithZero();
    }
 else     if (dataType() == Type.INT) {
      pointer=new IntPointer(length());
      indexer=IntIndexer.create((IntPointer)pointer);
      if (initialize)       fillPointerWithZero();
    }
  }
 else {
    if (length * getElementSize() < 0)     throw new IllegalArgumentException("String_Node_Str" + length + "String_Node_Str");
    wrappedBuffer=ByteBuffer.allocateDirect((int)(getElementSize() * length)).order(ByteOrder.nativeOrder());
  }
}
Program: 3261
Project: 3261
Buggy source:
/** 
 * Get the nesterov update
 * @param gradient the gradient to get the update for
 * @param iteration
 * @return
 */
@Override public INDArray getGradient(INDArray gradient,int iteration){
  if (v == null)   v=Nd4j.zeros(gradient.shape());
  INDArray vPrev=v;
  v=vPrev.mul(momentum).subi(gradient.mul(learningRate));
  Nd4j.getExecutioner().execAndReturn(new AddOp(vPrev.muli(momentum),v.mul(-momentum - 1),gradient));
  return gradient;
}

Fixed version (ground truth):
/** 
 * Get the nesterov update
 * @param gradient the gradient to get the update for
 * @param iteration
 * @return
 */
@Override public INDArray getGradient(INDArray gradient,int iteration){
  if (v == null)   v=Nd4j.zeros(gradient.shape());
  INDArray vPrev=v;
  v=vPrev.mul(momentum).subi(gradient.mul(learningRate));
  INDArray ret=vPrev.muli(momentum).addi(v.mul(-momentum - 1));
  gradient.assign(ret);
  return gradient;
}
Program: 3262
Project: 3262
Buggy source:
/** 
 * Fit the given model
 * @param iterator the data to iterate oer
 */
public void fit(DataSetIterator iterator){
  while (iterator.hasNext()) {
    DataSet next=iterator.next();
    if (mean == null) {
      mean=next.getFeatureMatrix().mean(0);
      std=Nd4j.zeros(mean.shape());
    }
 else {
      INDArray xMinusMean=next.getFeatureMatrix().subRowVector(mean);
      INDArray newMean=mean.add(xMinusMean.sum(0).divi(runningTotal));
      std.addi(xMinusMean.muli(next.getFeatureMatrix().subRowVector(newMean)).sum(0).divi(runningTotal));
      mean=newMean;
    }
    runningTotal+=next.numExamples();
  }
  iterator.reset();
}

Fixed version (ground truth):
/** 
 * Fit the given model
 * @param iterator the data to iterate oer
 */
public void fit(DataSetIterator iterator){
  while (iterator.hasNext()) {
    DataSet next=iterator.next();
    runningTotal+=next.numExamples();
    if (mean == null) {
      mean=next.getFeatureMatrix().mean(0);
      std=(iterator.batch() == 1) ? Nd4j.zeros(mean.shape()) : Transforms.pow(next.getFeatureMatrix().std(0),2);
      std.muli(iterator.batch());
    }
 else {
      INDArray xMinusMean=next.getFeatureMatrix().subRowVector(mean);
      INDArray newMean=mean.add(xMinusMean.sum(0).divi(runningTotal));
      INDArray meanB=next.getFeatureMatrix().mean(0);
      INDArray deltaSq=Transforms.pow(meanB.subRowVector(mean),2);
      INDArray deltaSqScaled=deltaSq.mul(((float)runningTotal - iterator.batch()) * iterator.batch() / iterator.totalExamples());
      INDArray mtwoB=Transforms.pow(next.getFeatureMatrix().std(0),2);
      mtwoB.muli(iterator.batch());
      std=std.add(mtwoB);
      std=std.add(deltaSqScaled);
      mean=newMean;
    }
  }
  std.divi(runningTotal);
  std=Transforms.sqrt(std);
  iterator.reset();
}
Program: 3263
Project: 3263
Buggy source:
/** 
 * Returns the stride(indices along the linear index for which each slice is accessed) of this array
 * @return the stride of this array
 */
@Override public int[] stride(){
  int[] ret=new int[Shape.rank(shapeInformation.asNioInt())];
  IntBuffer buffer=Shape.stride(shapeInformation.asNioInt());
  for (int i=0; i < ret.length; i++)   ret[i]=buffer.get(i);
  return ret;
}

Fixed version (ground truth):
/** 
 * Returns the stride(indices along the linear index for which each slice is accessed) of this array
 * @return the stride of this array
 */
@Override public int[] stride(){
  int[] ret=new int[Shape.rank(shapeInformation)];
  DataBuffer buffer=Shape.stride(shapeInformation);
  for (int i=0; i < ret.length; i++)   ret[i]=buffer.getInt(i);
  return ret;
}
Program: 3265
Project: 3265
Buggy source:
/** 
 * Returns the slice of this from the specified dimension
 * @param slice     the dimension to return from
 * @param dimension the dimension of the slice to return
 * @return the slice of this matrix from the specified dimensionand dimension
 */
@Override public INDArray slice(int slice,int dimension){
  int slices=size(dimension);
  if (slice >= slices)   throw new IllegalArgumentException("String_Node_Str" + slice);
  if (Shape.rank(shapeInformation.asNioInt()) == 0) {
    if (slice == 0)     return createScalarForIndex(slice,true);
 else     throw new IllegalArgumentException("String_Node_Str");
  }
  if (slice < 0)   slice+=rank();
  INDArrayIndex[] indexes=new INDArrayIndex[rank()];
  indexes[dimension]=NDArrayIndex.point(slice);
  for (int i=0; i < rank(); i++) {
    if (i != dimension)     indexes[i]=NDArrayIndex.all();
  }
  return get(indexes);
}

Fixed version (ground truth):
/** 
 * Returns the slice of this from the specified dimension
 * @param slice     the dimension to return from
 * @param dimension the dimension of the slice to return
 * @return the slice of this matrix from the specified dimensionand dimension
 */
@Override public INDArray slice(int slice,int dimension){
  int slices=size(dimension);
  if (slice >= slices)   throw new IllegalArgumentException("String_Node_Str" + slice);
  if (Shape.rank(shapeInformation) == 0) {
    if (slice == 0)     return createScalarForIndex(slice,true);
 else     throw new IllegalArgumentException("String_Node_Str");
  }
  if (slice < 0)   slice+=rank();
  INDArrayIndex[] indexes=new INDArrayIndex[rank()];
  indexes[dimension]=NDArrayIndex.point(slice);
  for (int i=0; i < rank(); i++) {
    if (i != dimension)     indexes[i]=NDArrayIndex.all();
  }
  return get(indexes);
}
Program: 3266
Project: 3266
Buggy source:
/** 
 * Returns the number of possible vectors for a given dimension
 * @param dimension the dimension to calculate the number of vectors for
 * @return the number of possible vectors along a dimension
 */
@Override public int vectorsAlongDimension(int dimension){
  if (dimension == 0 && isVector() || isRowVector())   return 1;
  if (size(dimension) == 1 && !isVector()) {
    for (int i=dimension; i < rank(); i++) {
      if (size(i) != 1)       return vectorsAlongDimension(i);
    }
    return length();
  }
 else   if (size(0) == 1 && !isVector()) {
    int realDimension=rank() - getLeadingOnes();
    if (length / size(realDimension) >= Integer.MAX_VALUE)     throw new IllegalArgumentException("String_Node_Str");
    return (int)(length / size(realDimension));
  }
  if (dimension >= Shape.rank(shapeInformation.asNioInt())) {
    if (length / size(Shape.rank(shapeInformation.asNioInt()) - 1) >= Integer.MAX_VALUE)     throw new IllegalArgumentException("String_Node_Str");
    return (int)(length / size(Shape.rank(shapeInformation.asNioInt()) - 1));
  }
  if (length / size(dimension) >= Integer.MAX_VALUE)   throw new IllegalArgumentException("String_Node_Str");
  return (int)(length / size(dimension));
}

Fixed version (ground truth):
/** 
 * Returns the number of possible vectors for a given dimension
 * @param dimension the dimension to calculate the number of vectors for
 * @return the number of possible vectors along a dimension
 */
@Override public int vectorsAlongDimension(int dimension){
  if (dimension == 0 && isVector() || isRowVector())   return 1;
  if (size(dimension) == 1 && !isVector()) {
    for (int i=dimension; i < rank(); i++) {
      if (size(i) != 1)       return vectorsAlongDimension(i);
    }
    return length();
  }
 else   if (size(0) == 1 && !isVector()) {
    int realDimension=rank() - getLeadingOnes();
    if (length / size(realDimension) >= Integer.MAX_VALUE)     throw new IllegalArgumentException("String_Node_Str");
    return (int)(length / size(realDimension));
  }
  if (dimension >= Shape.rank(shapeInformation)) {
    if (length / size(Shape.rank(shapeInformation) - 1) >= Integer.MAX_VALUE)     throw new IllegalArgumentException("String_Node_Str");
    return (int)(length / size(Shape.rank(shapeInformation) - 1));
  }
  if (length / size(dimension) >= Integer.MAX_VALUE)   throw new IllegalArgumentException("String_Node_Str");
  return (int)(length / size(dimension));
}
Program: 3267
Project: 3267
Buggy source:
/** 
 * Returns the shape(dimensions) of this array
 * @return the shape of this matrix
 */
public int[] shape(){
  int[] ret=new int[rank()];
  IntBuffer buffer=Shape.shapeOf(shapeInformation.asNioInt());
  for (int i=0; i < ret.length; i++)   ret[i]=buffer.get(i);
  return ret;
}

Fixed version (ground truth):
/** 
 * Returns the shape(dimensions) of this array
 * @return the shape of this matrix
 */
public int[] shape(){
  int[] ret=new int[rank()];
  DataBuffer buffer=Shape.shapeOf(shapeInformation);
  for (int i=0; i < ret.length; i++)   ret[i]=buffer.getInt(i);
  return ret;
}
Program: 3268
Project: 3268
Buggy source:
/** 
 * Returns the size of this array along a particular dimension
 * @param dimension the dimension to return from
 * @return the shape of the specified dimension
 */
@Override public int size(int dimension){
  if (isScalar()) {
    if (dimension == 0 || dimension == 1 || dimension < 0)     return (int)length;
 else     throw new IllegalArgumentException("String_Node_Str" + dimension);
  }
  if (dimension < 0) {
    return Shape.shapeOf(shapeInformation.asNioInt()).get(dimension + Shape.rank(shapeInformation.asNioInt()));
  }
  return Shape.shapeOf(shapeInformation.asNioInt()).get(dimension);
}

Fixed version (ground truth):
/** 
 * Returns the size of this array along a particular dimension
 * @param dimension the dimension to return from
 * @return the shape of the specified dimension
 */
@Override public int size(int dimension){
  if (isScalar()) {
    if (dimension == 0 || dimension == 1 || dimension < 0)     return (int)length;
 else     throw new IllegalArgumentException("String_Node_Str" + dimension);
  }
  if (dimension < 0) {
    return Shape.shapeOf(shapeInformation).getInt(dimension + Shape.rank(shapeInformation));
  }
  return Shape.shapeOf(shapeInformation).getInt(dimension);
}
Program: 3269
Project: 3269
Buggy source:
/** 
 * See: http://www.mathworks.com/help/matlab/ref/permute.html
 * @param rearrange the dimensions to swap to
 * @return the newly permuted array
 */
@Override public INDArray permute(int... rearrange){
  if (rearrange.length != rank())   return dup();
  boolean alreadyInOrder=true;
  for (int i=0; i < Shape.rank(shapeInfo()); i++) {
    if (rearrange[i] != i) {
      alreadyInOrder=false;
      break;
    }
  }
  if (alreadyInOrder)   return this;
  checkArrangeArray(rearrange);
  int[] newShape=doPermuteSwap(Shape.shapeOf(shapeInformation.asNioInt()),rearrange);
  int[] newStride=doPermuteSwap(Shape.stride(shapeInformation.asNioInt()),rearrange);
  char newOrder=Shape.getOrder(newShape,newStride,elementStride());
  INDArray value=create(data(),newShape,newStride,offset(),newOrder);
  return value;
}

Fixed version (ground truth):
/** 
 * See: http://www.mathworks.com/help/matlab/ref/permute.html
 * @param rearrange the dimensions to swap to
 * @return the newly permuted array
 */
@Override public INDArray permute(int... rearrange){
  if (rearrange.length != rank())   return dup();
  boolean alreadyInOrder=true;
  for (int i=0; i < Shape.rank(shapeInfo()); i++) {
    if (rearrange[i] != i) {
      alreadyInOrder=false;
      break;
    }
  }
  if (alreadyInOrder)   return this;
  checkArrangeArray(rearrange);
  int[] newShape=doPermuteSwap(Shape.shapeOf(shapeInformation),rearrange);
  int[] newStride=doPermuteSwap(Shape.stride(shapeInformation),rearrange);
  char newOrder=Shape.getOrder(newShape,newStride,elementStride());
  INDArray value=create(data(),newShape,newStride,offset(),newOrder);
  return value;
}
Program: 3270
Project: 3270
Buggy source:
protected int[] doPermuteSwap(IntBuffer shape,int[] rearrange){
  int[] ret=new int[rearrange.length];
  for (int i=0; i < rearrange.length; i++) {
    ret[i]=shape.get(rearrange[i]);
  }
  return ret;
}

Fixed version (ground truth):
protected int[] doPermuteSwap(DataBuffer shape,int[] rearrange){
  int[] ret=new int[rearrange.length];
  for (int i=0; i < rearrange.length; i++) {
    ret[i]=shape.getInt(rearrange[i]);
  }
  return ret;
}
Program: 3272
Project: 3272
Buggy source:
/** 
 * Number of columns (shape[1]), throws an exception when called when not 2d
 * @return the number of columns in the array (only 2d)
 */
@Override public int columns(){
  if (isMatrix()) {
    if (shape().length == 2)     return size(1);
  }
  if (isVector()) {
    if (isColumnVector())     return 1;
 else     if (isRowVector() && Shape.rank(shapeInformation.asNioInt()) > 1)     return size(1);
 else     return size(0);
  }
  throw new IllegalStateException("String_Node_Str");
}

Fixed version (ground truth):
/** 
 * Number of columns (shape[1]), throws an exception when called when not 2d
 * @return the number of columns in the array (only 2d)
 */
@Override public int columns(){
  if (isMatrix()) {
    if (shape().length == 2)     return size(1);
  }
  if (isVector()) {
    if (isColumnVector())     return 1;
 else     if (isRowVector() && Shape.rank(shapeInformation) > 1)     return size(1);
 else     return size(0);
  }
  throw new IllegalStateException("String_Node_Str");
}
Program: 3273
Project: 3273
Buggy source:
/** 
 * Get the vector along a particular dimension
 * @param index     the index of the vector to get
 * @param dimension the dimension to get the vector from
 * @return the vector along a particular dimension
 */
@Override public INDArray vectorAlongDimension(int index,int dimension){
  if (dimension < 0)   dimension=Shape.rank(shapeInformation.asNioInt()) + dimension;
  if (dimension == Shape.rank(shapeInformation.asNioInt()) - 1 && size(dimension) == 1 && rank() > 2 || rank() > 2 && dimension == 0 && size(dimension) == 1) {
    return this;
  }
  INDArray ret=tensorAlongDimension(index,dimension);
  if (isMatrix() && ret.isVector() && dimension == 1 && !ret.isRowVector())   return ret.reshape(ArrayUtil.reverseCopy(ret.shape()));
 else   if (isMatrix() && ret.isVector() && dimension == 0 && !ret.isColumnVector())   return ret.reshape(ArrayUtil.reverseCopy(ret.shape()));
  return ret;
}

Fixed version (ground truth):
/** 
 * Get the vector along a particular dimension
 * @param index     the index of the vector to get
 * @param dimension the dimension to get the vector from
 * @return the vector along a particular dimension
 */
@Override public INDArray vectorAlongDimension(int index,int dimension){
  if (dimension < 0)   dimension=Shape.rank(shapeInformation) + dimension;
  if (dimension == Shape.rank(shapeInformation) - 1 && size(dimension) == 1 && rank() > 2 || rank() > 2 && dimension == 0 && size(dimension) == 1) {
    return this;
  }
  INDArray ret=tensorAlongDimension(index,dimension);
  if (isMatrix() && ret.isVector() && dimension == 1 && !ret.isRowVector())   return ret.reshape(ArrayUtil.reverseCopy(ret.shape()));
 else   if (isMatrix() && ret.isVector() && dimension == 0 && !ret.isColumnVector())   return ret.reshape(ArrayUtil.reverseCopy(ret.shape()));
  return ret;
}
Program: 3274
Project: 3274
Buggy source:
@Override public int linearIndex(int i){
  setLinearStride();
  int idx=i;
  for (int j=0; j < Shape.rank(shapeInformation.asNioInt()) - 1; j++) {
    if (size(i) == 1)     continue;
    idx+=i * stride(j);
  }
  return Shape.offset(shapeInfo()) + (idx);
}

Fixed version (ground truth):
@Override public int linearIndex(int i){
  setLinearStride();
  int idx=i;
  for (int j=0; j < Shape.rank(shapeInformation) - 1; j++) {
    if (size(i) == 1)     continue;
    idx+=i * stride(j);
  }
  return Shape.offset(shapeInfo()) + (idx);
}
Program: 3275
Project: 3275
Buggy source:
@Override public INDArray subArray(int[] offsets,int[] shape,int[] stride){
  int n=shape.length;
  if (shape.length < 1)   return create(Nd4j.createBuffer(shape));
  if (offsets.length != n)   throw new IllegalArgumentException("String_Node_Str" + Arrays.toString(offsets));
  if (stride.length != n)   throw new IllegalArgumentException("String_Node_Str" + Arrays.toString(stride));
  if (Shape.contentEquals(shape,Shape.shapeOf(shapeInformation.asNioInt()))) {
    if (ArrayUtil.isZero(offsets)) {
      return this;
    }
 else {
      throw new IllegalArgumentException("String_Node_Str");
    }
  }
  int[] dotProductOffsets=offsets;
  int[] dotProductStride=stride;
  int offset=Shape.offset(shapeInfo()) + NDArrayIndex.offset(dotProductStride,dotProductOffsets);
  if (offset >= data().length())   offset=ArrayUtil.sum(offsets);
  return create(data,Arrays.copyOf(shape,shape.length),stride,offset,ordering());
}

Fixed version (ground truth):
@Override public INDArray subArray(int[] offsets,int[] shape,int[] stride){
  int n=shape.length;
  if (shape.length < 1)   return create(Nd4j.createBuffer(shape));
  if (offsets.length != n)   throw new IllegalArgumentException("String_Node_Str" + Arrays.toString(offsets));
  if (stride.length != n)   throw new IllegalArgumentException("String_Node_Str" + Arrays.toString(stride));
  if (Shape.contentEquals(shape,Shape.shapeOf(shapeInformation))) {
    if (ArrayUtil.isZero(offsets)) {
      return this;
    }
 else {
      throw new IllegalArgumentException("String_Node_Str");
    }
  }
  int[] dotProductOffsets=offsets;
  int[] dotProductStride=stride;
  int offset=Shape.offset(shapeInfo()) + NDArrayIndex.offset(dotProductStride,dotProductOffsets);
  if (offset >= data().length())   offset=ArrayUtil.sum(offsets);
  return create(data,Arrays.copyOf(shape,shape.length),stride,offset,ordering());
}
Program: 3276
Project: 3276
Buggy source:
/** 
 * Test whether a matrix is scalar.
 */
@Override public boolean isScalar(){
  if (isScalar != null)   return isScalar;
  if (Shape.rank(shapeInfo()) > 2) {
    isScalar=false;
  }
 else   if (Shape.rank(shapeInformation.asNioInt()) == 1) {
    isScalar=Shape.shapeOf(shapeInformation.asNioInt()).get(0) == 1;
  }
 else   if (Shape.rank(shapeInformation.asNioInt()) == 2) {
    isScalar=Shape.shapeOf(shapeInformation.asNioInt()).get(0) == 1 && Shape.shapeOf(shapeInformation.asNioInt()).get(1) == 1;
  }
 else   isScalar=false;
  return isScalar;
}

Fixed version (ground truth):
/** 
 * Test whether a matrix is scalar.
 */
@Override public boolean isScalar(){
  if (isScalar != null)   return isScalar;
  if (Shape.rank(shapeInfo()) > 2) {
    isScalar=false;
  }
 else   if (Shape.rank(shapeInformation) == 1) {
    isScalar=Shape.shapeOf(shapeInformation).getInt(0) == 1;
  }
 else   if (Shape.rank(shapeInformation) == 2) {
    isScalar=Shape.shapeOf(shapeInformation).getInt(0) == 1 && Shape.shapeOf(shapeInformation).getInt(1) == 1;
  }
 else   isScalar=false;
  return isScalar;
}
Program: 3277
Project: 3277
Buggy source:
@Override public void setShape(int... shape){
  IntBuffer shapeView=Shape.shapeOf(shapeInformation.asNioInt());
  for (int i=0; i < shape.length; i++) {
    shapeView.put(i,shape[i]);
  }
}

Fixed version (ground truth):
@Override public void setShape(int... shape){
  DataBuffer shapeView=Shape.shapeOf(shapeInformation);
  for (int i=0; i < shape.length; i++) {
    shapeView.put(i,shape[i]);
  }
}
Program: 3278
Project: 3278
Buggy source:
@Override public void setStride(int[] stride){
  IntBuffer strideView=Shape.stride(shapeInformation.asNioInt());
  for (int i=0; i < stride.length; i++)   strideView.put(i,stride[i]);
}

Fixed version (ground truth):
@Override public void setStride(int[] stride){
  DataBuffer strideView=Shape.stride(shapeInformation);
  for (int i=0; i < stride.length; i++)   strideView.put(i,stride[i]);
}
Program: 3279
Project: 3279
Buggy source:
protected void write(DataOutputStream out) throws IOException {
  out.writeUTF(allocationMode.name());
  out.writeInt(length());
  out.writeUTF(dataType().name());
  if (dataType() == Type.DOUBLE) {
    for (int i=0; i < length(); i++)     out.writeDouble(getDouble(i));
  }
 else {
    for (int i=0; i < length(); i++)     out.writeFloat(getFloat(i));
  }
}

Fixed version (ground truth):
@Override public void write(DataOutputStream out) throws IOException {
  out.writeUTF(allocationMode.name());
  out.writeInt(length());
  out.writeUTF(dataType().name());
  if (dataType() == Type.DOUBLE) {
    for (int i=0; i < length(); i++)     out.writeDouble(getDouble(i));
  }
 else   if (dataType() == Type.INT) {
    for (int i=0; i < length(); i++)     out.writeInt(getInt(i));
  }
 else {
    for (int i=0; i < length(); i++)     out.writeFloat(getFloat(i));
  }
}
Program: 3281
Project: 3281
Buggy source:
@Test public void testSerialization2() throws Exception {
  INDArray[] arr=new INDArray[]{Nd4j.ones(1,10),Nd4j.ones(5,10).getRow(2)};
  for (  INDArray a : arr) {
    ByteArrayOutputStream baos=new ByteArrayOutputStream();
    try (ObjectOutputStream oos=new ObjectOutputStream(baos)){
      oos.writeObject(a);
    }
     byte[] bytes=baos.toByteArray();
    ByteArrayInputStream bais=new ByteArrayInputStream(bytes);
    ObjectInputStream ois=new ObjectInputStream(bais);
    INDArray aDeserialized=(INDArray)ois.readObject();
    System.out.println(aDeserialized);
    assertEquals(Nd4j.ones(1,10),aDeserialized);
  }
}

Fixed version (ground truth):
@Test public void testSerialization2() throws Exception {
  INDArray[] arr=new INDArray[]{Nd4j.ones(1,10),Nd4j.ones(5,10).getRow(2)};
  for (  INDArray a : arr) {
    ByteArrayOutputStream baos=new ByteArrayOutputStream();
    try (ObjectOutputStream oos=new ObjectOutputStream(baos)){
      oos.writeObject(a);
      oos.flush();
    }
     byte[] bytes=baos.toByteArray();
    ByteArrayInputStream bais=new ByteArrayInputStream(bytes);
    ObjectInputStream ois=new ObjectInputStream(bais);
    INDArray aDeserialized=(INDArray)ois.readObject();
    System.out.println(aDeserialized);
    assertEquals(Nd4j.ones(1,10),aDeserialized);
  }
}
Program: 3282
Project: 3282
Buggy source:
@Test public void testNettyCopy(){
  DataBuffer db=Nd4j.createBuffer(new double[]{1,2,3,4});
  if (db.allocationMode() == DataBuffer.AllocationMode.HEAP)   return;
  ByteBuf buf=db.asNetty();
  ByteBuf copy=buf.copy(0,buf.capacity());
  for (int i=0; i < db.length(); i++) {
    assertEquals(db.getDouble(i),copy.getDouble(i * 8));
  }
}

Fixed version (ground truth):
@Test public void testNettyCopy(){
  DataBuffer db=Nd4j.createBuffer(new double[]{1,2,3,4});
  if (db.allocationMode() == DataBuffer.AllocationMode.HEAP)   return;
  ByteBuf buf=db.asNetty();
  ByteBuf copy=buf.copy(0,buf.capacity());
  for (int i=0; i < db.length(); i++) {
    assertEquals(db.getDouble(i),copy.getDouble(i * 8),1e-1);
  }
}
Program: 3283
Project: 3283
Buggy source:
@Test public void testReadWrite(){
  DataBuffer assertion=Nd4j.createBuffer(new double[]{1,2,3});
  ByteArrayOutputStream bos=new ByteArrayOutputStream();
  DataOutputStream dos=new DataOutputStream(bos);
  assertion.write(dos);
  DataBuffer clone=assertion.dup();
  assertion.read(new DataInputStream(new ByteArrayInputStream(bos.toByteArray())));
  assertEquals(assertion,clone);
}

Fixed version (ground truth):
@Test public void testReadWrite() throws Exception {
  DataBuffer assertion=Nd4j.createBuffer(new double[]{1,2,3});
  ByteArrayOutputStream bos=new ByteArrayOutputStream();
  DataOutputStream dos=new DataOutputStream(bos);
  assertion.write(dos);
  DataBuffer clone=assertion.dup();
  assertion.read(new DataInputStream(new ByteArrayInputStream(bos.toByteArray())));
  assertEquals(assertion,clone);
}
Program: 3284
Project: 3284
Buggy source:
/** 
 * Create an n x (shape) ndarray where the ndarray is repeated num times
 * @param n   the ndarray to replicate
 * @param num the number of copies to repeat
 * @return the repeated ndarray
 */
public static INDArray repeat(INDArray n,int num){
  List<INDArray> list=new ArrayList<>();
  for (int i=0; i < num; i++)   list.add(n.dup());
  int[] shape=n.isColumnVector() ? new int[]{n.shape()[0]} : n.shape();
  int[] retShape=Ints.concat(new int[]{num},shape);
  return Nd4j.create(list,retShape);
}

Fixed version (ground truth):
/** 
 * Create an n x (shape) ndarray where the ndarray is repeated num times
 * @param n   the ndarray to replicate
 * @param num the number of copies to repeat
 * @return the repeated ndarray
 */
public static INDArray repeat(INDArray n,int num){
  List<INDArray> list=new ArrayList<>();
  for (int i=0; i < num; i++)   list.add(n.dup());
  int[] nShape=n.shape();
  int[] shape=n.isColumnVector() ? new int[]{n.shape()[0]} : nShape;
  int[] retShape=Ints.concat(new int[]{num},shape);
  return Nd4j.create(list,retShape);
}
Program: 3285
Project: 3285
Buggy source:
/** 
 * Returns true if this ndarray is 2d or 3d with a singleton element
 * @return true if the element is a matrix, false otherwise
 */
public boolean isMatrix(){
  return (shape().length == 2 && (size(0) != 1 && size(1) != 1));
}

Fixed version (ground truth):
/** 
 * Returns true if this ndarray is 2d or 3d with a singleton element
 * @return true if the element is a matrix, false otherwise
 */
public boolean isMatrix(){
  if (isMatrix != null)   return isMatrix;
  isMatrix=(Shape.rank(shapeInfo()) == 2 && (size(0) != 1 && size(1) != 1));
  return isMatrix;
}
Program: 3286
Project: 3286
Buggy source:
/** 
 * Test whether a matrix is scalar.
 */
@Override public boolean isScalar(){
  if (isScalar != null)   return isScalar;
  if (Shape.rank(shapeInformation) > 2)   return false;
  if (Shape.rank(shapeInformation) == 1)   return Shape.shapeOf(shapeInformation).get(0) == 1;
 else   if (Shape.rank(shapeInformation) == 2) {
    return Shape.shapeOf(shapeInformation).get(0) == 1 && Shape.shapeOf(shapeInformation).get(1) == 1;
  }
  isScalar=true;
  return isScalar;
}

Fixed version (ground truth):
/** 
 * Test whether a matrix is scalar.
 */
@Override public boolean isScalar(){
  if (isScalar != null)   return isScalar;
  if (Shape.rank(shapeInfo()) > 2) {
    isScalar=false;
  }
 else   if (Shape.rank(shapeInformation) == 1) {
    isScalar=Shape.shapeOf(shapeInformation).get(0) == 1;
  }
 else   if (Shape.rank(shapeInformation) == 2) {
    isScalar=Shape.shapeOf(shapeInformation).get(0) == 1 && Shape.shapeOf(shapeInformation).get(1) == 1;
  }
  isScalar=false;
  return isScalar;
}
Program: 3287
Project: 3287
Buggy source:
private String format(INDArray arr,int rank){
  StringBuffer sb=new StringBuffer();
  if (arr.isScalar()) {
    if (arr instanceof IComplexNDArray)     return ((IComplexNDArray)arr).getComplex(0).toString();
    return decimalFormat.format(arr.getDouble(0));
  }
 else   if (arr.isVector()) {
    sb.append("String_Node_Str");
    for (int i=0; i < arr.length(); i++) {
      sb.append(StringUtils.repeat("String_Node_Str",rank - 1));
      if (arr instanceof IComplexNDArray)       sb.append(((IComplexNDArray)arr).getComplex(i).toString());
 else       sb.append(decimalFormat.format(arr.getDouble(i)));
      if (i < arr.length() - 1)       sb.append(sep);
    }
    sb.append("String_Node_Str");
    return sb.toString();
  }
 else {
    sb.append("String_Node_Str");
    for (int i=0; i < arr.slices(); i++) {
      sb.append(format(arr.slice(i),rank - 1));
      if (i < arr.slices() - 1) {
        sb.append("String_Node_Str");
        sb.append(StringUtils.repeat("String_Node_Str",rank - 1));
      }
    }
    sb.append("String_Node_Str");
    return sb.toString();
  }
}

Fixed version (ground truth):
private String format(INDArray arr,int rank){
  if (rank < 1)   return "String_Node_Str";
  StringBuffer sb=new StringBuffer();
  if (arr.isScalar()) {
    if (arr instanceof IComplexNDArray)     return ((IComplexNDArray)arr).getComplex(0).toString();
    return decimalFormat.format(arr.getDouble(0));
  }
 else   if (arr.isVector()) {
    sb.append("String_Node_Str");
    for (int i=0; i < arr.length(); i++) {
      sb.append(StringUtils.repeat("String_Node_Str",rank - 1));
      if (arr instanceof IComplexNDArray)       sb.append(((IComplexNDArray)arr).getComplex(i).toString());
 else       sb.append(decimalFormat.format(arr.getDouble(i)));
      if (i < arr.length() - 1)       sb.append(sep);
    }
    sb.append("String_Node_Str");
    return sb.toString();
  }
 else {
    sb.append("String_Node_Str");
    for (int i=0; i < arr.slices(); i++) {
      sb.append(format(arr.slice(i),rank - 1));
      if (i < arr.slices() - 1) {
        sb.append("String_Node_Str");
        sb.append(StringUtils.repeat("String_Node_Str",rank - 1));
      }
    }
    sb.append("String_Node_Str");
    return sb.toString();
  }
}
Program: 3288
Project: 3288
Buggy source:
/** 
 * Set the value of the ndarray to the specified value
 * @param value the value to assign
 * @return the ndarray with the values
 */
@Override public INDArray assign(Number value){
  data().assign(value,offset());
  return this;
}

Fixed version (ground truth):
/** 
 * Set the value of the ndarray to the specified value
 * @param value the value to assign
 * @return the ndarray with the values
 */
@Override public INDArray assign(Number value){
  Nd4j.getExecutioner().exec(new ScalarSet(this,value));
  return this;
}
Program: 3290
Project: 3290
Buggy source:
@Override public IComplexNumber op(IComplexNumber origin){
  return origin;
}

Fixed version (ground truth):
@Override public IComplexNumber op(IComplexNumber origin){
  return Nd4j.createComplexNumber(origin.absoluteValue(),0);
}
Program: 3291
Project: 3291
Buggy source:
@Override public INDArray blockUntilComplete(){
  if (subTasks == null) {
    invokeAsync();
  }
  int[] retShape=ArrayUtil.removeIndex(op.x().shape(),dimensions);
  INDArray out=Nd4j.create(retShape);
  int i=0;
  for (  Task<Double> task : subTasks) {
    out.putScalar(i++,task.blockUntilComplete());
  }
  return out;
}

Fixed version (ground truth):
@Override public INDArray blockUntilComplete(){
  if (subTasks == null) {
    invokeAsync();
  }
  int[] retShape=ArrayUtil.removeIndex(op.x().shape(),dimensions);
  INDArray out=Nd4j.create(retShape);
  int i=0;
  for (  Task<Double> task : subTasks) {
    out.putScalar(i++,task.blockUntilComplete());
  }
  op.setZ(out);
  return out;
}
Program: 3292
Project: 3292
Buggy source:
@Override public INDArray blockUntilComplete(){
  if (subTasks == null) {
    invokeAsync();
  }
  int[] retShape=ArrayUtil.removeIndex(op.x().shape(),dimensions);
  INDArray out=Nd4j.create(retShape);
  int i=0;
  for (  Task<Pair<Double,Integer>> task : subTasks) {
    Pair<Double,Integer> result=task.blockUntilComplete();
    out.putScalar(i++,result.getSecond());
  }
  return out;
}

Fixed version (ground truth):
@Override public INDArray blockUntilComplete(){
  if (subTasks == null) {
    invokeAsync();
  }
  int[] retShape=ArrayUtil.removeIndex(op.x().shape(),dimensions);
  INDArray out=Nd4j.create(retShape);
  int i=0;
  for (  Task<Pair<Double,Integer>> task : subTasks) {
    Pair<Double,Integer> result=task.blockUntilComplete();
    out.putScalar(i++,result.getSecond());
  }
  op.setZ(out);
  return out;
}