       long stride_d = 0;
       for (int d=0; d<src_nDim; d++)
       {
+        long src_stride_d = src_stride[d];
         if (d < dim)
         {
-          stride_d = src_stride[d] / size_dim;
+          stride_d = src_stride_d / size_dim;
           coeff = leftover / stride_d;
           leftover -= coeff * stride_d;
           targetIdx += coeff * stride_d * idx_size;

}

__global__ void THCudaTensor_kernel_indexSelect(
   float *tensor, float *src, float* src_stride, float *index, 
   long src_nDim, int dim, long idx_size, long tensor_size, long size_dim
)
{

        }
        else if (d > dim)
        {
          coeff = leftover / src_stride_d;
          leftover -= coeff * src_stride_d;
          targetIdx += coeff * src_stride_d;
          srcIdx += coeff * src_stride_d;
        } 
      }
      long src_stride_dim = src_stride[dim];
      tensor[targetIdx + i*src_stride_dim] = src[srcIdx + ((int)(index[i])-1)*src_stride_dim];
    }
  }
}	
