Backends/SiaNet.Backend.TensorSharp/NDArray.cs
/// <summary>
/// Returns a tensor which contains all slices of size size in the given dimension. The step between two slices is given by step.
/// The result tensor has an additional dimension of size size.
/// </summary>
/// <param name="dimension">The dimension.</param>
/// <param name="size">The size.</param>
/// <param name="step">The step.</param>
/// <returns>Tensor.</returns>
/// <exception cref="InvalidOperationException">Cannot unfold an empty tensor</exception>
/// <exception cref="ArgumentOutOfRangeException">
/// dimension is out of range - dimension
/// or
/// size cannot be larger than the size of dimension - size
/// or
/// step must be at least 1 - step
/// </exception>
Returns a tensor which contains all slices of size size in the given dimension. The step between two slices is given by step.
The result tensor has an additional dimension of size size.
Returns a tensor which contains all slices of size size in the given dimension . The step between two slices is given by step . The result tensor has an additional dimension of size size .
public NDArray Unfold(int dimension, long size, long step)
        {
            if (DimensionCount == 0) throw new InvalidOperationException("Cannot unfold an empty tensor");
            if (dimension < 0 || dimension >= DimensionCount) throw new ArgumentOutOfRangeException("dimension is out of range", "dimension");
            if (size > shape[dimension]) throw new ArgumentOutOfRangeException("size cannot be larger than the size of dimension", "size");
            if (step <= 0) throw new ArgumentOutOfRangeException("step must be at least 1", "step");
            var newSize = new long[DimensionCount + 1];
            var newStrides = new long[DimensionCount + 1];
            Array.Copy(shape, newSize, DimensionCount);
            Array.Copy(strides, newStrides, DimensionCount);
            newSize[DimensionCount] = size;
            newStrides[DimensionCount] = this.strides[dimension];
            newSize[dimension] = (this.shape[dimension] - size) / step + 1;
            newStrides[dimension] = step * this.strides[dimension];
            return new NDArray(newSize, newStrides, this.Storage, this.StorageOffset);
        }
public NDArray Unfold ( int dimension , long size , long step ) { if ( DimensionCount == 0 ) throw new InvalidOperationException ( " " ) ; if ( dimension < 0 || dimension >= DimensionCount ) throw new ArgumentOutOfRangeException ( " " , " " ) ; if ( size > shape [ dimension ] ) throw new ArgumentOutOfRangeException ( " " , " " ) ; if ( step <= 0 ) throw new ArgumentOutOfRangeException ( " " , " " ) ; var newSize = new long [ DimensionCount + 1 ] ; var newStrides = new long [ DimensionCount + 1 ] ; Array . Copy ( shape , newSize , DimensionCount ) ; Array . Copy ( strides , newStrides , DimensionCount ) ; newSize [ DimensionCount ] = size ; newStrides [ DimensionCount ] = this . strides [ dimension ] ; newSize [ dimension ] = ( this . shape [ dimension ] - size ) / step + 1 ; newStrides [ dimension ] = step * this . strides [ dimension ] ; return new NDArray ( newSize , newStrides , this . Storage , this . StorageOffset ) ; }
Returns a tensor which contains all slices of size size in the given dimension.
Returns a tensor which contains all slices of size size in the given dimension .
None
Cannot unfold an empty tensor
Cannot unfold an empty tensor
dimension is out of range - dimension
or
size cannot be larger than the size of dimension - size
or
step must be at least 1 - step
dimension is out of range - dimension or size cannot be larger than the size of dimension - size or step must be at least 1 - step
dimension
int
None
size
long
None
step
long
None