tools/autograd/templates/Functions.cpp
// This implements steps (2)~(4) of the algorithm in
// NOTE [ Detecting Memory Overlap Within A Strided Tensor ]
// Helper for as_strided_backward
This implements steps (2)~(4) of the algorithm in
NOTE [ Detecting Memory Overlap Within A Strided Tensor ]
Helper for as_strided_backward
This implements steps ( 2 ) ~ ( 4 ) of the algorithm in NOTE [ Detecting Memory Overlap Within A Strided Tensor ] Helper for as_strided_backward
static inline bool _maybe_overlapping_memory(IntList sizes, IntList strides) {
  if (sizes.size() > 0) {
    std::vector<std::size_t> argsort(sizes.size());
    std::iota(argsort.begin(), argsort.end(), 0);
    std::sort(argsort.begin(), argsort.end(),
        [&](std::size_t i, std::size_t j){ return strides[i] < strides[j]; });
    int64_t max_index_in_slice = 0;
    for (auto i : argsort) {
      auto stride_ = strides[i];
      if (stride_ <= max_index_in_slice) {
        return true;
      }
      max_index_in_slice += stride_ * (sizes[i] - 1);
    }
  }
  return false;
}
static inline bool _maybe_overlapping_memory ( IntList sizes , IntList strides ) { if ( sizes . size ( ) > 0 ) { std :: vector < std :: size_t > argsort ( sizes . size ( ) ) ; std :: iota ( argsort . begin ( ) , argsort . end ( ) , 0 ) ; std :: sort ( argsort . begin ( ) , argsort . end ( ) , [ & ] ( std :: size_t i , std :: size_t j ) { return strides [ i ] < strides [ j ] ; } ) ; int64_t max_index_in_slice = 0 ; for ( auto i : argsort ) { auto stride_ = strides [ i ] ; if ( stride_ <= max_index_in_slice ) { return true ; } max_index_in_slice += stride_ * ( sizes [ i ] - 1 ) ; } } return false ; }
This implements steps (2)~(4) of the algorithm in
NOTE [ Detecting Memory Overlap Within A Strided Tensor ]
Helper for as_strided_backward
This implements steps ( 2 ) ~ ( 4 ) of the algorithm in NOTE [ Detecting Memory Overlap Within A Strided Tensor ] Helper for as_strided_backward