SliceOperation

Description

Extracts a slice with a specified size from a start location of the input tensor.

Operator Context

Figure 1 Context of the SliceOperation operator

Definition

struct SliceParam {
    SVector<int64_t> offsets;
    SVector<int64_t> size;
    uint8_t rsv[8] = {0};
};

Parameters

Member

Type

Default Value

Description

offsets

SVector<int64_t>

-

Start location of each dimension slice.

  • If offsets[i] is less than 0 (-dimNum <= i < dimNum), for example, offsets[i]= -1, the dimension size of the ith dimension of input x is dimNum, in this case, a start location of the ith-dimensional slice input to x is dimNum - 1 (that is, the start location is the last dimension).
  • If offsets[i] is less than 0 and the dimension size of the ith dimension is dimNum, the sum of dimNum and x must be greater than or equal to 0.

size

SVector<int64_t>

-

Size of each dimension slice.

  • When size[i] = -1, it indicates that the end location of the slice is the last location of the ith dimension. If the dimension size of the ith dimension is dimNum, the end location is dimNum - 1.
  • The element of size must be greater than or equal to -1. offsets[i] + size[i] must be within the range of the ith dimension of x.

rsv[8]

uint8_t

{0}

Reserved

Input

Parameter

Dimension

Data Type

Format

Description

x

[-1,...,-1]

The value -1 indicates that the size of the current dimension is not restricted.

float16/float/int8/bool/int32/uint32/bf16

ND

Input tensor.

Output

Parameter

Dimension

Data Type

Format

Description

output

[-1,...,-1]

The value -1 indicates that the size of the current dimension is not restricted.

float16/float/int8/bool/int32/uint32/bf16

Same as the data type of x

ND

Output tensor. The dimension size is the value specified by size.

Restrictions

  • If offsets[i] is less than 0, the access starts from the ith highest dimension. For example, if offsets is –1 and the dimension of input x is dimNum, the start position of the ith dimension slice is dimNum – 1.
  • If offsets[i] is less than 0 and the dimension size of the ith dimension is dimNum, the sum of dimNum and offsets[i] must be greater than or equal to 0.
  • When size[i] = -1, it indicates that the end of the slice is the last location of the ith dimension. If the dimension size of the ith dimension is dimNum, the end location is dimNum - 1.
  • The element of size must be greater than or equal to -1. offsets[i] + size[i] must be within the range of the ith dimension of x.

Example API Call

  • Input
    x = [[ -78.9,   78.8,  32.22,   49.7,  82.8, 24.77],
         [  72.2,  20.89,  55.16,   85.5,  72.8,  94.8],
        [ 11.36, -83.56,  65.94, -46.94, 72.44,  68.7]]
    offsets = [1, 2]
        
    size = [2, 4]

    In dimension 0, the slice length is 2 from index 1.

    In the first dimension, the slice length is 4 (2 + 4 < = 6) from index 2.

  • Output
    y.dim = [2, 4]
    y = [[ 55.1562,  85.5000,  72.8125,  94.8125],
         [ 65.9375, -46.9375,  72.4375,  68.6875]]

    If the dimension of size is -1, the output shape is automatically derived.