   }
   long inputWidth   = input->size[dimw];
   long inputHeight  = input->size[dimh];
-  long outputWidth  = (inputWidth - kW) / dW + 1;
-  long outputHeight = (inputHeight - kH) / dH + 1;
+  long outputWidth  = (inputWidth + 2*padding - kW) / dW + 1;
+  long outputHeight = (inputHeight + 2*padding - kH) / dH + 1;
 
   luaL_argcheck(L, kW == kH, 1, "filters must be square (kW == kH)");
   luaL_argcheck(L, dW == dH, 1, "stride must be square (dW == dH)");

  }
  long inputWidth   = input->size[dimw];
  long inputHeight  = input->size[dimh];
  long outputWidth  = (inputWidth - kW) / dW + 1;
  long outputHeight = (inputHeight - kH) / dH + 1;

  luaL_argcheck(L, kW == kH, 1, "filters must be square (kW == kH)");
  luaL_argcheck(L, dW == dH, 1, "stride must be square (dW == dH)");

  }
  long inputWidth   = input->size[dimw];
  long inputHeight  = input->size[dimh];
  long outputWidth  = (inputWidth + 2*padding - kW) / dW + 1;
  long outputHeight = (inputHeight + 2*padding - kH) / dH + 1;

  if (input->nDimension == 3) {
    // implementation in progress...
