       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
)
{

{
  THLongStorage *newSize;
  THCudaTensor *indices_;
  long *stride_;
  long nIndex = THLongTensor_nElement(indices);
  long nRes;
  
  THArgCheck(indices->nDimension == 1, 3, "expecting vector of indices");
  THArgCheck(dim < src->nDimension, 4, "Indexing dim is out of bounds");
