aten/src/THC/THCTensor.cpp
/* Returns false if there is no possibility that the tensor    */
/* has "overlapping" indices and true otherwise.               */
/* "Overlapping" indices are two+ valid indices that specify   */
/* the same offset within the tensor.                          */
/* The function does this by checking for a sufficient but not */
/* necessary condition of no overlap. In particular, that      */
/* that there exists an ordering of the tensor's dimensions    */
/* that is nicely "nested," with each dimension contained      */
/* within the next one.                                        */
Returns false if there is no possibility that the tensor
has "overlapping" indices and true otherwise.
"Overlapping" indices are two+ valid indices that specify
the same offset within the tensor.
The function does this by checking for a sufficient but not
necessary condition of no overlap. In particular, that
that there exists an ordering of the tensor's dimensions
that is nicely "nested," with each dimension contained
within the next one.
Returns false if there is no possibility that the tensor has " overlapping " indices and true otherwise . " Overlapping " indices are two + valid indices that specify the same offset within the tensor . The function does this by checking for a sufficient but not necessary condition of no overlap . In particular that that there exists an ordering of the tensor ' s dimensions that is nicely " nested " with each dimension contained within the next one .
bool THCTensor_maybeOverlappingIndices(THCState* state, const THCTensor* t) {
  SizeAndStride info[MAX_CUTORCH_DIMS];
  int dims = THCTensor_nDimensionLegacyAll(state, t);
  int nonSize1Dims = 0;
  for (int i = 0; i < dims; ++i) {
    int64_t size = THCTensor_sizeLegacyNoScalars(state, t, i);
    if (size > 1) {
      info[nonSize1Dims].size = size;
      info[nonSize1Dims].stride =
        THCTensor_stride(state, t, i);
      if (info[nonSize1Dims].stride < 1) {
        return true;
      }
      ++nonSize1Dims;
    }
  }
  if (nonSize1Dims == 0) {
    return false;
  }
  qsort(info, nonSize1Dims, sizeof(SizeAndStride), compareSizeAndStride);
  for (int i = 0; i < (nonSize1Dims - 1); ++i) {
    if (((info[i].size - 1) * info[i].stride) >= info[i + 1].stride) {
      return true;
    }
  }
  return false;
}
bool THCTensor_maybeOverlappingIndices ( THCState * state , const THCTensor * t ) { SizeAndStride info [ MAX_CUTORCH_DIMS ] ; int dims = THCTensor_nDimensionLegacyAll ( state , t ) ; int nonSize1Dims = 0 ; for ( int i = 0 ; i < dims ; ++ i ) { int64_t size = THCTensor_sizeLegacyNoScalars ( state , t , i ) ; if ( size > 1 ) { info [ nonSize1Dims ] . size = size ; info [ nonSize1Dims ] . stride = THCTensor_stride ( state , t , i ) ; if ( info [ nonSize1Dims ] . stride < 1 ) { return true ; } ++ nonSize1Dims ; } } if ( nonSize1Dims == 0 ) { return false ; } qsort ( info , nonSize1Dims , sizeof ( SizeAndStride ) , compareSizeAndStride ) ; for ( int i = 0 ; i < ( nonSize1Dims - 1 ) ; ++ i ) { if ( ( ( info [ i ] . size - 1 ) * info [ i ] . stride ) >= info [ i + 1 ] . stride ) { return true ; } } return false ; }
Returns false if there is no possibility that the tensor
has "overlapping" indices and true otherwise.
Returns false if there is no possibility that the tensor has " overlapping " indices and true otherwise .
/* Extract size/stride arrays; only consider size >1 dims. */ /* Short-circuits if tensor is a single element.             */ /* Ascending order (innermost dimension in sorted view is at [0]) */