   long inputHeight  = input->size[1];
   long inputWidth   = input->size[2];
   long batchSize    = input->size[3];
-  long outputHeight = (inputHeight - kH) / dH + 1;
-  long outputWidth  = (inputWidth - kW) / dW + 1;
+  long outputHeight = (padding + inputHeight - kH) / dH + 1;
+  long outputWidth  = (padding + inputWidth - kW) / dW + 1;
   
   // asserts
   luaL_argcheck(L, inputWidth == inputHeight, 1, "input must be square");

  long inputHeight  = input->size[1];
  long inputWidth   = input->size[2];
  long batchSize    = input->size[3];
  long outputHeight = (inputHeight - kH) / dH + 1;
  long outputWidth  = (inputWidth - kW) / dW + 1;

  // resize output
  THCudaTensor_resize4d(output, nOutputPlane, outputHeight, outputWidth, batchSize);

  THCudaTensor *gradOutput = (THCudaTensor *)luaT_checkudata(L, 3, "torch.CudaTensor");
  int dW = luaT_getfieldcheckint(L, 1, "dW");
  int dH = luaT_getfieldcheckint(L, 1, "dH");
  int padding = luaT_getfieldcheckint(L, 1, "padding");

  THCudaTensor *weight = (THCudaTensor *)luaT_getfieldcheckudata(L, 1, "weight", "torch.CudaTensor");
  THCudaTensor *gradInput = (THCudaTensor *)luaT_getfieldcheckudata(L, 1, "gradInput", "torch.CudaTensor");
