       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;

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

        }
        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];
    }
  }
}	
