Backends/SiaNet.Backend.TensorSharp/Cuda/ApplyUtils.cs
/// <summary>
/// Determines whether [has overlapping indices] [the specified tensor].
/// </summary>
/// <param name="tensor">The tensor.</param>
/// <returns><c>true</c> if [has overlapping indices] [the specified tensor]; otherwise, <c>false</c>.</returns>
Determines whether [has overlapping indices] [the specified tensor].
Determines whether [ has overlapping indices ] [ the specified tensor ] .
public static bool HasOverlappingIndices(NDArray tensor)
        {
            var info = Enumerable.Range(0, tensor.DimensionCount)
                .Select(x => new SizeAndStride() { size = tensor.Shape[x], stride = tensor.Strides[x] })
                .Where(x => x.size > 1)
                .ToArray();
            if (info.Length == 0)
            {
                return false; 
            }
            Array.Sort(info);
            if (info[info.Length - 1].stride < 1)
            {
                return true;
            }
            for (int i = info.Length - 2; i >= 0; --i)
            {
                if (info[i].stride < info[i + 1].size * info[i + 1].stride)
                {
                    return true;
                }
            }
            return false;
        }
public static bool HasOverlappingIndices ( NDArray tensor ) { var info = Enumerable . Range ( 0 , tensor . DimensionCount ) . Select ( x => new SizeAndStride ( ) { size = tensor . Shape [ x ] , stride = tensor . Strides [ x ] } ) . Where ( x => x . size > 1 ) . ToArray ( ) ; if ( info . Length == 0 ) { return false ; } Array . Sort ( info ) ; if ( info [ info . Length - 1 ] . stride < 1 ) { return true ; } for ( int i = info . Length - 2 ; i >= 0 ; -- i ) { if ( info [ i ] . stride < info [ i + 1 ] . size * info [ i + 1 ] . stride ) { return true ; } } return false ; }
Determines whether [has overlapping indices] [the specified tensor].
Determines whether [ has overlapping indices ] [ the specified tensor ] .
// In this function, we don't care about permutations of the // size/stride arrays (transpositions). // We order the size/stride arrays by stride, skipping dimensions of // size 1. Strides of dimensions of size 1 don't matter, since there // is only one addressing point in them. // In this reordered view, the tensor is contiguous if // stride[dim] == size[dim + 1] * stride[dim + 1] for all `dim`. // The tensor has holes if // stride[dim] > size[dim + 1] * stride[dim + 1] for one or more // `dim`. // The tensor has overlaps if // stride[dim] < size[dim + 1] * stride[dim + 1] for one or more // `dim`, or the innermost stride is 0. // Extract size/stride arrays; only consider size >1 dims. // no overlap // Descending order (innermost dimension in sorted view is at last index) // Base case: innermost dimension must have stride >= 1 // Subsequent dimensions, if any // There are overlaps // Tensor has holes or is contiguous
None
tensor
NDArray
None