   THCudaTensor *gradOutputWindow;
   THCudaTensor *gradInputWindow;
   long k, i;
-  
+
   int dimS = 0; // sequence dimension
-  
-  if (gradOutput->nDimension == 3) 
+
+  if (gradOutput->nDimension == 3)
   {
     dimS = 1;
   }
-  
+
   nInputFrame = input->size[dimS];
   nOutputFrame = gradOutput->size[dimS];
 

    THCudaTensor *gradOutputSample = THCudaTensor_new();
    THCudaTensor *inputSample = THCudaTensor_new();
    long nBatchFrame = input->size[0];
    
    for(i = 0; i < nBatchFrame; i++)
    {
      THCudaTensor_select(gradOutputSample, gradOutput, 0, i);
      THCudaTensor_select(inputSample, input, 0, i);
      long nOutputSampleFrame = nOutputFrame;
      
      /* bias first */
      for(k = 0; k < nOutputFrame; k++)
      {

        long nFrame = (nInputFrame-k*dW-kW)/inputFrameStride + 1;
        nOutputSampleFrame -= nFrame;

        THCudaTensor_setStorage2d(gradOutputWindow, gradOutputSample->storage,
                                gradOutputSample->storageOffset + k*gradOutputSample->size[1],
                                nFrame, outputFrameStride*gradOutputSample->size[1],
                                gradOutputSample->size[1], 1);
