Program: 3316
Project: 3316
Buggy source:
@Test public void testOpExecutionerTransformOps() throws Exception {
  final DataBuffer.AllocationMode origAlloc=Nd4j.alloc;
  DefaultOpExecutioner opExec=(DefaultOpExecutioner)Nd4j.getExecutioner();
  List<Class<? extends TransformOp>> testClasses=new ArrayList<>();
  testClasses.add(AddOp.class);
  testClasses.add(CopyOp.class);
  testClasses.add(MulOp.class);
  testClasses.add(DivOp.class);
  testClasses.add(RDivOp.class);
  testClasses.add(RSubOp.class);
  testClasses.add(SubOp.class);
  testClasses.add(Tanh.class);
  testClasses.add(Sigmoid.class);
  testClasses.add(RectifedLinear.class);
  testClasses.add(SoftMax.class);
  int[] shape={30,50};
  for (  DataBuffer.Type dtype : DataBuffer.Type.values()) {
    Nd4j.dtype=dtype;
    Nd4j.factory().setDType(dtype);
    Nd4j.getRandom().setSeed(12345);
    INDArray origFirst=Nd4j.rand(shape);
    INDArray origSecond=Nd4j.rand(shape);
    for (    Class<? extends TransformOp> opClass : testClasses) {
      String msg="String_Node_Str" + opClass.getName() + "String_Node_Str"+ dtype;
      Constructor<? extends TransformOp> xyzConstructor=opClass.getConstructor(INDArray.class,INDArray.class,INDArray.class);
      DefaultOpExecutioner.setParallelThreshold(Integer.MAX_VALUE);
      Nd4j.alloc=DataBuffer.AllocationMode.HEAP;
      INDArray x1=getCopyOf(origFirst,DataBuffer.AllocationMode.HEAP,dtype);
      INDArray y1=getCopyOf(origSecond,DataBuffer.AllocationMode.HEAP,dtype);
      INDArray z1=getCopyOf(origFirst,DataBuffer.AllocationMode.HEAP,dtype);
      TransformOp op=xyzConstructor.newInstance(x1,y1,z1);
      opExec.exec(op);
      assertEquals(x1,origFirst);
      assertEquals(y1,origSecond);
      INDArray x2=getCopyOf(origFirst,DataBuffer.AllocationMode.HEAP,dtype);
      INDArray y2=getCopyOf(origSecond,DataBuffer.AllocationMode.HEAP,dtype);
      op=xyzConstructor.newInstance(x2,y2,x2);
      opExec.exec(op);
      assertEquals(y2,origSecond);
      assertEquals(x2,z1);
      if (!op.isPassThrough()) {
        INDArray x1a=getCopyOf(origFirst,DataBuffer.AllocationMode.HEAP,dtype);
        INDArray y1a=getCopyOf(origSecond,DataBuffer.AllocationMode.HEAP,dtype);
        INDArray z1a=getCopyOf(origFirst,DataBuffer.AllocationMode.HEAP,dtype);
        op=xyzConstructor.newInstance(x1a,y1a,z1a);
        new TransformViaTensorDataBufferTask(op,Integer.MAX_VALUE,x1a,y1a,z1a).invoke();
        assertEquals(msg,x1a,origFirst);
        assertEquals(msg,y1a,origSecond);
        assertEquals(msg,z1a,z1);
        INDArray x2a=getCopyOf(origFirst,DataBuffer.AllocationMode.HEAP,dtype);
        INDArray y2a=getCopyOf(origSecond,DataBuffer.AllocationMode.HEAP,dtype);
        op=xyzConstructor.newInstance(x2a,y2a,x2a);
        new TransformViaTensorDataBufferTask(op,Integer.MAX_VALUE,x2a,y2a,x2a).invoke();
        assertEquals(msg,y2a,origSecond);
        assertEquals(msg,x2a,z1);
      }
      DefaultOpExecutioner.setParallelThreshold(5);
      Nd4j.alloc=DataBuffer.AllocationMode.HEAP;
      INDArray x3=getCopyOf(origFirst,DataBuffer.AllocationMode.HEAP,dtype);
      INDArray y3=getCopyOf(origSecond,DataBuffer.AllocationMode.HEAP,dtype);
      INDArray z3=getCopyOf(origFirst,DataBuffer.AllocationMode.HEAP,dtype);
      op=xyzConstructor.newInstance(x3,y3,z3);
      opExec.exec(op);
      assertEquals(msg,x3,origFirst);
      assertEquals(msg,y3,origSecond);
      assertEquals(msg,z3,z1);
      INDArray x4=getCopyOf(origFirst,DataBuffer.AllocationMode.HEAP,dtype);
      INDArray y4=getCopyOf(origSecond,DataBuffer.AllocationMode.HEAP,dtype);
      op=xyzConstructor.newInstance(x4,y4,x4);
      opExec.exec(op);
      assertEquals(msg,y4,origSecond);
      assertEquals(msg,x4,z1);
      if (!op.isPassThrough()) {
        INDArray x3a=getCopyOf(origFirst,DataBuffer.AllocationMode.HEAP,dtype);
        INDArray y3a=getCopyOf(origSecond,DataBuffer.AllocationMode.HEAP,dtype);
        INDArray z3a=getCopyOf(origFirst,DataBuffer.AllocationMode.HEAP,dtype);
        op=xyzConstructor.newInstance(x3a,y3a,z3a);
        new TransformViaTensorDataBufferTask(op,5,x3a,y3a,z3a).invoke();
        assertEquals(msg,x3a,origFirst);
        assertEquals(msg,y3a,origSecond);
        assertEquals(msg,z3a,z1);
        INDArray x4a=getCopyOf(origFirst,DataBuffer.AllocationMode.HEAP,dtype);
        INDArray y4a=getCopyOf(origSecond,DataBuffer.AllocationMode.HEAP,dtype);
        op=xyzConstructor.newInstance(x4a,y4a,x4a);
        new TransformViaTensorDataBufferTask(op,5,x4a,y4a,x4a).invoke();
        assertEquals(msg,y4a,origSecond);
        assertEquals(msg,x4a,z1);
      }
      DefaultOpExecutioner.setParallelThreshold(Integer.MAX_VALUE);
      Nd4j.alloc=DataBuffer.AllocationMode.DIRECT;
      INDArray x5=getCopyOf(origFirst,DataBuffer.AllocationMode.DIRECT,dtype);
      INDArray y5=getCopyOf(origSecond,DataBuffer.AllocationMode.DIRECT,dtype);
      INDArray z5=getCopyOf(origFirst,DataBuffer.AllocationMode.DIRECT,dtype);
      op=xyzConstructor.newInstance(x5,y5,z5);
      opExec.exec(op);
      assertEquals(msg,x5,origFirst);
      assertEquals(msg,y5,origSecond);
      assertEquals(msg,z5,z1);
      INDArray x6=getCopyOf(origFirst,DataBuffer.AllocationMode.DIRECT,dtype);
      INDArray y6=getCopyOf(origSecond,DataBuffer.AllocationMode.DIRECT,dtype);
      op=xyzConstructor.newInstance(x6,y6,x6);
      opExec.exec(op);
      assertEquals(msg,y6,origSecond);
      assertEquals(msg,x6,z1);
      if (!op.isPassThrough()) {
        INDArray x5a=getCopyOf(origFirst,DataBuffer.AllocationMode.DIRECT,dtype);
        INDArray y5a=getCopyOf(origSecond,DataBuffer.AllocationMode.DIRECT,dtype);
        INDArray z5a=getCopyOf(origFirst,DataBuffer.AllocationMode.DIRECT,dtype);
        op=xyzConstructor.newInstance(x5a,y5a,z5a);
        new TransformViaTensorDataBufferTask(op,Integer.MAX_VALUE,x5a,y5a,z5a).invoke();
        assertEquals(msg,x5a,origFirst);
        assertEquals(msg,y5a,origSecond);
        assertEquals(msg,z5a,z5);
        INDArray x6a=getCopyOf(origFirst,DataBuffer.AllocationMode.DIRECT,dtype);
        INDArray y6a=getCopyOf(origSecond,DataBuffer.AllocationMode.DIRECT,dtype);
        op=xyzConstructor.newInstance(x6a,y6a,x6a);
        new TransformViaTensorDataBufferTask(op,Integer.MAX_VALUE,x6a,y6a,x6a).invoke();
        assertEquals(msg,y6a,origSecond);
        assertEquals(msg,x6a,z1);
      }
      DefaultOpExecutioner.setParallelThreshold(5);
      Nd4j.alloc=DataBuffer.AllocationMode.DIRECT;
      INDArray x7=getCopyOf(origFirst,DataBuffer.AllocationMode.DIRECT,dtype);
      INDArray y7=getCopyOf(origSecond,DataBuffer.AllocationMode.DIRECT,dtype);
      INDArray z7=getCopyOf(origFirst,DataBuffer.AllocationMode.DIRECT,dtype);
      op=xyzConstructor.newInstance(x7,y7,z7);
      opExec.exec(op);
      assertEquals(msg,x7,origFirst);
      assertEquals(msg,y7,origSecond);
      assertEquals(msg,z7,z1);
      INDArray x8=getCopyOf(origFirst,DataBuffer.AllocationMode.DIRECT,dtype);
      INDArray y8=getCopyOf(origSecond,DataBuffer.AllocationMode.DIRECT,dtype);
      op=xyzConstructor.newInstance(x8,y8,x8);
      opExec.exec(op);
      assertEquals(msg,y8,origSecond);
      assertEquals(msg,x8,z1);
      if (!op.isPassThrough()) {
        INDArray x7a=getCopyOf(origFirst,DataBuffer.AllocationMode.DIRECT,dtype);
        INDArray y7a=getCopyOf(origSecond,DataBuffer.AllocationMode.DIRECT,dtype);
        INDArray z7a=getCopyOf(origFirst,DataBuffer.AllocationMode.DIRECT,dtype);
        op=xyzConstructor.newInstance(x7a,y7a,z7a);
        new TransformViaTensorDataBufferTask(op,5,x7a,y7a,z7a).invoke();
        assertEquals(msg,x7a,origFirst);
        assertEquals(msg,y7a,origSecond);
        assertEquals(msg,z7a,z1);
        INDArray x8a=getCopyOf(origFirst,DataBuffer.AllocationMode.DIRECT,dtype);
        INDArray y8a=getCopyOf(origSecond,DataBuffer.AllocationMode.DIRECT,dtype);
        op=xyzConstructor.newInstance(x8a,y8a,x8a);
        new TransformViaTensorDataBufferTask(op,5,x8a,y8a,x8a).invoke();
        assertEquals(msg,y8a,origSecond);
        assertEquals(msg,x8a,z1);
      }
    }
  }
  Nd4j.alloc=origAlloc;
}

Fixed version (ground truth):
@Test public void testOpExecutionerTransformOps() throws Exception {
  final DataBuffer.AllocationMode origAlloc=Nd4j.alloc;
  DefaultOpExecutioner opExec=(DefaultOpExecutioner)Nd4j.getExecutioner();
  List<Class<? extends TransformOp>> testClasses=new ArrayList<>();
  testClasses.add(AddOp.class);
  testClasses.add(CopyOp.class);
  testClasses.add(MulOp.class);
  testClasses.add(DivOp.class);
  testClasses.add(RDivOp.class);
  testClasses.add(RSubOp.class);
  testClasses.add(SubOp.class);
  testClasses.add(Tanh.class);
  testClasses.add(Sigmoid.class);
  testClasses.add(RectifedLinear.class);
  testClasses.add(SoftMax.class);
  int[] shape={30,50};
  for (  DataBuffer.Type dtype : DataBuffer.Type.values()) {
    Nd4j.dtype=dtype;
    Nd4j.factory().setDType(dtype);
    Nd4j.getRandom().setSeed(12345);
    INDArray origFirst=Nd4j.rand(shape);
    INDArray origSecond=Nd4j.rand(shape);
    for (    Class<? extends TransformOp> opClass : testClasses) {
      String msg="String_Node_Str" + opClass.getName() + "String_Node_Str"+ dtype;
      Constructor<? extends TransformOp> xyzConstructor=opClass.getConstructor(INDArray.class,INDArray.class,INDArray.class);
      DefaultOpExecutioner.setParallelThreshold(Integer.MAX_VALUE);
      Nd4j.alloc=DataBuffer.AllocationMode.HEAP;
      INDArray x1=getCopyOf(origFirst,DataBuffer.AllocationMode.HEAP,dtype);
      INDArray y1=getCopyOf(origSecond,DataBuffer.AllocationMode.HEAP,dtype);
      INDArray z1=getCopyOf(origFirst,DataBuffer.AllocationMode.HEAP,dtype);
      TransformOp op=xyzConstructor.newInstance(x1,y1,z1);
      opExec.exec(op);
      assertEquals(x1,origFirst);
      assertEquals(y1,origSecond);
      INDArray x2=getCopyOf(origFirst,DataBuffer.AllocationMode.HEAP,dtype);
      INDArray y2=getCopyOf(origSecond,DataBuffer.AllocationMode.HEAP,dtype);
      op=xyzConstructor.newInstance(x2,y2,x2);
      opExec.exec(op);
      assertEquals(y2,origSecond);
      assertEquals(x2,z1);
      if (!op.isPassThrough()) {
        INDArray x1a=getCopyOf(origFirst,DataBuffer.AllocationMode.HEAP,dtype);
        INDArray y1a=getCopyOf(origSecond,DataBuffer.AllocationMode.HEAP,dtype);
        INDArray z1a=getCopyOf(origFirst,DataBuffer.AllocationMode.HEAP,dtype);
        op=xyzConstructor.newInstance(x1a,y1a,z1a);
        new TransformViaTensorDataBufferAction(op,Integer.MAX_VALUE,x1a,y1a,z1a).invoke();
        assertEquals(msg,x1a,origFirst);
        assertEquals(msg,y1a,origSecond);
        assertEquals(msg,z1a,z1);
        INDArray x2a=getCopyOf(origFirst,DataBuffer.AllocationMode.HEAP,dtype);
        INDArray y2a=getCopyOf(origSecond,DataBuffer.AllocationMode.HEAP,dtype);
        op=xyzConstructor.newInstance(x2a,y2a,x2a);
        new TransformViaTensorDataBufferAction(op,Integer.MAX_VALUE,x2a,y2a,x2a).invoke();
        assertEquals(msg,y2a,origSecond);
        assertEquals(msg,x2a,z1);
      }
      DefaultOpExecutioner.setParallelThreshold(5);
      Nd4j.alloc=DataBuffer.AllocationMode.HEAP;
      INDArray x3=getCopyOf(origFirst,DataBuffer.AllocationMode.HEAP,dtype);
      INDArray y3=getCopyOf(origSecond,DataBuffer.AllocationMode.HEAP,dtype);
      INDArray z3=getCopyOf(origFirst,DataBuffer.AllocationMode.HEAP,dtype);
      op=xyzConstructor.newInstance(x3,y3,z3);
      opExec.exec(op);
      assertEquals(msg,x3,origFirst);
      assertEquals(msg,y3,origSecond);
      assertEquals(msg,z3,z1);
      INDArray x4=getCopyOf(origFirst,DataBuffer.AllocationMode.HEAP,dtype);
      INDArray y4=getCopyOf(origSecond,DataBuffer.AllocationMode.HEAP,dtype);
      op=xyzConstructor.newInstance(x4,y4,x4);
      opExec.exec(op);
      assertEquals(msg,y4,origSecond);
      assertEquals(msg,x4,z1);
      if (!op.isPassThrough()) {
        INDArray x3a=getCopyOf(origFirst,DataBuffer.AllocationMode.HEAP,dtype);
        INDArray y3a=getCopyOf(origSecond,DataBuffer.AllocationMode.HEAP,dtype);
        INDArray z3a=getCopyOf(origFirst,DataBuffer.AllocationMode.HEAP,dtype);
        op=xyzConstructor.newInstance(x3a,y3a,z3a);
        new TransformViaTensorDataBufferAction(op,5,x3a,y3a,z3a).invoke();
        assertEquals(msg,x3a,origFirst);
        assertEquals(msg,y3a,origSecond);
        assertEquals(msg,z3a,z1);
        INDArray x4a=getCopyOf(origFirst,DataBuffer.AllocationMode.HEAP,dtype);
        INDArray y4a=getCopyOf(origSecond,DataBuffer.AllocationMode.HEAP,dtype);
        op=xyzConstructor.newInstance(x4a,y4a,x4a);
        new TransformViaTensorDataBufferAction(op,5,x4a,y4a,x4a).invoke();
        assertEquals(msg,y4a,origSecond);
        assertEquals(msg,x4a,z1);
      }
      DefaultOpExecutioner.setParallelThreshold(Integer.MAX_VALUE);
      Nd4j.alloc=DataBuffer.AllocationMode.DIRECT;
      INDArray x5=getCopyOf(origFirst,DataBuffer.AllocationMode.DIRECT,dtype);
      INDArray y5=getCopyOf(origSecond,DataBuffer.AllocationMode.DIRECT,dtype);
      INDArray z5=getCopyOf(origFirst,DataBuffer.AllocationMode.DIRECT,dtype);
      op=xyzConstructor.newInstance(x5,y5,z5);
      opExec.exec(op);
      assertEquals(msg,x5,origFirst);
      assertEquals(msg,y5,origSecond);
      assertEquals(msg,z5,z1);
      INDArray x6=getCopyOf(origFirst,DataBuffer.AllocationMode.DIRECT,dtype);
      INDArray y6=getCopyOf(origSecond,DataBuffer.AllocationMode.DIRECT,dtype);
      op=xyzConstructor.newInstance(x6,y6,x6);
      opExec.exec(op);
      assertEquals(msg,y6,origSecond);
      assertEquals(msg,x6,z1);
      if (!op.isPassThrough()) {
        INDArray x5a=getCopyOf(origFirst,DataBuffer.AllocationMode.DIRECT,dtype);
        INDArray y5a=getCopyOf(origSecond,DataBuffer.AllocationMode.DIRECT,dtype);
        INDArray z5a=getCopyOf(origFirst,DataBuffer.AllocationMode.DIRECT,dtype);
        op=xyzConstructor.newInstance(x5a,y5a,z5a);
        new TransformViaTensorDataBufferAction(op,Integer.MAX_VALUE,x5a,y5a,z5a).invoke();
        assertEquals(msg,x5a,origFirst);
        assertEquals(msg,y5a,origSecond);
        assertEquals(msg,z5a,z5);
        INDArray x6a=getCopyOf(origFirst,DataBuffer.AllocationMode.DIRECT,dtype);
        INDArray y6a=getCopyOf(origSecond,DataBuffer.AllocationMode.DIRECT,dtype);
        op=xyzConstructor.newInstance(x6a,y6a,x6a);
        new TransformViaTensorDataBufferAction(op,Integer.MAX_VALUE,x6a,y6a,x6a).invoke();
        assertEquals(msg,y6a,origSecond);
        assertEquals(msg,x6a,z1);
      }
      DefaultOpExecutioner.setParallelThreshold(5);
      Nd4j.alloc=DataBuffer.AllocationMode.DIRECT;
      INDArray x7=getCopyOf(origFirst,DataBuffer.AllocationMode.DIRECT,dtype);
      INDArray y7=getCopyOf(origSecond,DataBuffer.AllocationMode.DIRECT,dtype);
      INDArray z7=getCopyOf(origFirst,DataBuffer.AllocationMode.DIRECT,dtype);
      op=xyzConstructor.newInstance(x7,y7,z7);
      opExec.exec(op);
      assertEquals(msg,x7,origFirst);
      assertEquals(msg,y7,origSecond);
      assertEquals(msg,z7,z1);
      INDArray x8=getCopyOf(origFirst,DataBuffer.AllocationMode.DIRECT,dtype);
      INDArray y8=getCopyOf(origSecond,DataBuffer.AllocationMode.DIRECT,dtype);
      op=xyzConstructor.newInstance(x8,y8,x8);
      opExec.exec(op);
      assertEquals(msg,y8,origSecond);
      assertEquals(msg,x8,z1);
      if (!op.isPassThrough()) {
        INDArray x7a=getCopyOf(origFirst,DataBuffer.AllocationMode.DIRECT,dtype);
        INDArray y7a=getCopyOf(origSecond,DataBuffer.AllocationMode.DIRECT,dtype);
        INDArray z7a=getCopyOf(origFirst,DataBuffer.AllocationMode.DIRECT,dtype);
        op=xyzConstructor.newInstance(x7a,y7a,z7a);
        new TransformViaTensorDataBufferAction(op,5,x7a,y7a,z7a).invoke();
        assertEquals(msg,x7a,origFirst);
        assertEquals(msg,y7a,origSecond);
        assertEquals(msg,z7a,z1);
        INDArray x8a=getCopyOf(origFirst,DataBuffer.AllocationMode.DIRECT,dtype);
        INDArray y8a=getCopyOf(origSecond,DataBuffer.AllocationMode.DIRECT,dtype);
        op=xyzConstructor.newInstance(x8a,y8a,x8a);
        new TransformViaTensorDataBufferAction(op,5,x8a,y8a,x8a).invoke();
        assertEquals(msg,y8a,origSecond);
        assertEquals(msg,x8a,z1);
      }
    }
  }
  Nd4j.alloc=origAlloc;
}