        if (!between(y, 0, height-1)) continue;
        for (int x = xi_l; x <= xi_r; ++x) {
          if (!between(x, 0, width-1)) continue;
-         float weight = expf(-(x - xf_s) * (x - xf_s) - (y - yf_s) * (y - yf_s));
+         float weight = expf(-(x - xf_s) * (x - xf_s) / 4 - (y - yf_s) * (y - yf_s) / 4);
          weight_sum += weight;
          weights[id_point] = weight;
          int address = masks_strideBatch * b + masks_strideHeight * y + masks_strideWidth * x;

           if (!between(x, 0, width-1)) continue;
           bias_x[id_point] = (x - xf_s); // remember multiply 2 below since it is derivative of square
           bias_y[id_point] = (y - yf_s); // remember multiply 2 below since it is derivative of square
           float weight = expf(-bias_x[id_point] * bias_x[id_point] - bias_y[id_point] * bias_y[id_point]);
           bias_x_weighted += weight * bias_x[id_point];
           bias_y_weighted += weight * bias_y[id_point];
           weight_sum += weight;

static int cunn_SubSamplerBHWD_updateOutput(lua_State *L)
{
  THCState *state = getCutorchState(L);

  THCudaTensor *inputImages = (THCudaTensor *)luaT_checkudata(L, 2, "torch.CudaTensor");
  THCudaTensor *grids = (THCudaTensor *)luaT_checkudata(L, 3, "torch.CudaTensor");
  THCudaTensor *masks = (THCudaTensor *)luaT_checkudata(L, 4, "torch.CudaTensor");
