Program: 3458
Project: 3458
Buggy source:
/** 
 * ND Convolution
 * @param input  the input to op
 * @param kernel the kernel to op with
 * @param type   the type of convolution
 * @param axes   the axes to do the convolution along
 * @return the convolution of the given input and kernel
 */
@Override public INDArray convn(INDArray input,INDArray kernel,Convolution.Type type,int[] axes){
  if (kernel.isScalar() && input.isScalar())   return kernel.mul(input);
  INDArray shape=ArrayUtil.toNDArray(input.shape()).add(ArrayUtil.toNDArray(kernel.shape())).subi(1);
  int[] intShape=ArrayUtil.toInts(shape);
  IComplexNDArray fftedInput=FFT.rawfftn(Nd4j.createComplex(input),intShape,axes);
  IComplexNDArray fftedKernel=FFT.rawfftn(Nd4j.createComplex(kernel),intShape,axes);
  if (!Arrays.equals(fftedInput.shape(),fftedKernel.shape())) {
    if (fftedInput.length() < fftedKernel.length())     fftedInput=ComplexNDArrayUtil.padWithZeros(fftedInput,fftedKernel.shape());
 else     fftedKernel=ComplexNDArrayUtil.padWithZeros(fftedKernel,fftedInput.shape());
  }
  IComplexNDArray inputTimesKernel=fftedInput.muli(fftedKernel);
  IComplexNDArray convolution=FFT.ifftn(inputTimesKernel);
switch (type) {
case FULL:
    return convolution.getReal();
case SAME:
  return ComplexNDArrayUtil.center(convolution,input.shape()).getReal();
case VALID:
int[] shape2=ArrayUtil.toInts(Transforms.abs(ArrayUtil.toNDArray(input.shape()).sub(ArrayUtil.toNDArray(kernel.shape())).addi(1)));
for (int i=0; i < shape2.length; i++) shape2[i]=Math.max(1,shape2[i]);
return ComplexNDArrayUtil.center(convolution,shape2).getReal();
}
return convolution.getReal();
}

Fixed version (ground truth):
/** 
 * ND Convolution
 * @param input  the input to op
 * @param kernel the kernel to op with
 * @param type   the type of convolution
 * @param axes   the axes to do the convolution along
 * @return the convolution of the given input and kernel
 */
@Override public INDArray convn(INDArray input,INDArray kernel,Convolution.Type type,int[] axes){
  if (input.shape().length != kernel.shape().length) {
    int[] newShape=new int[Math.max(input.shape().length,kernel.shape().length)];
    Arrays.fill(newShape,1);
    int lengthDelta=Math.abs(input.shape().length - kernel.shape().length);
    if (input.shape().length < kernel.shape().length) {
      System.arraycopy(input.shape(),0,newShape,kernel.shape().length - lengthDelta,Math.min(kernel.shape().length,input.shape().length) - lengthDelta);
      input=input.reshape(newShape);
    }
 else {
      System.arraycopy(kernel.shape(),0,newShape,input.shape().length - lengthDelta,Math.min(kernel.shape().length,input.shape().length) - lengthDelta);
      kernel=kernel.reshape(newShape);
    }
  }
  if (kernel.isScalar() && input.isScalar())   return kernel.mul(input);
  INDArray shape=ArrayUtil.toNDArray(input.shape()).add(ArrayUtil.toNDArray(kernel.shape())).subi(1);
  int[] intShape=ArrayUtil.toInts(shape);
  IComplexNDArray fftedInput=FFT.rawfftn(Nd4j.createComplex(input),intShape,axes);
  IComplexNDArray fftedKernel=FFT.rawfftn(Nd4j.createComplex(kernel),intShape,axes);
  if (!Arrays.equals(fftedInput.shape(),fftedKernel.shape())) {
    if (fftedInput.length() < fftedKernel.length())     fftedInput=ComplexNDArrayUtil.padWithZeros(fftedInput,fftedKernel.shape());
 else     fftedKernel=ComplexNDArrayUtil.padWithZeros(fftedKernel,fftedInput.shape());
  }
  IComplexNDArray inputTimesKernel=fftedInput.muli(fftedKernel);
  IComplexNDArray convolution=FFT.ifftn(inputTimesKernel);
switch (type) {
case FULL:
    return convolution.getReal();
case SAME:
  return ComplexNDArrayUtil.center(convolution,input.shape()).getReal();
case VALID:
int[] shape2=ArrayUtil.toInts(Transforms.abs(ArrayUtil.toNDArray(input.shape()).sub(ArrayUtil.toNDArray(kernel.shape())).addi(1)));
return ComplexNDArrayUtil.center(convolution,shape2).getReal();
}
return convolution.getReal();
}