# Slice#

## Slice - 13#

Version

• name: Slice (GitHub)

• domain: main

• since_version: 13

• function: False

• support_level: SupportType.COMMON

• shape inference: True

This version of the operator has been available since version 13.

Summary

Produces a slice of the input tensor along multiple axes. Similar to numpy: https://numpy.org/doc/stable/user/basics.indexing.html?highlight=slice#slicing-and-striding

Slice uses the starts, ends, axes and steps inputs to select a sub-tensor of its input data tensor.

An effective start[i], end[i], and step[i] must be computed for each i in [0, … r-1] where r = rank(input) as follows:

If axes are omitted, they are set to [0, …, r-1]. If steps are omitted, they are set to [1, …, 1] of length len(starts)

The effective values are initialized as start[i] = 0, end[i] = dims[i] where dims are the dimensions of input and `step[i] = `1.

All negative elements of axes are made non-negatve by adding r to them, where r =rank(input).

All negative values in starts[i] and ends[i] have dims[axes[i]] added to them, where dims are the dimensions of input. Then start[axes[i]] is the adjusted starts[i] is clamped into the range [0, dims[axes[i]]] for positive stepping and [0, dims[axes[i]]-1] for negative stepping.

The clamping for the adjusted ends[i] depends on the sign of steps[i] and must accommodate copying 0 through dims[axes[i]] elements, so for positive stepping end[axes[i]] is clamped to [0, dims[axes[i]]], while for negative stepping it is clamped to [-1, dims[axes[i]]-1].

Finally, step[axes[i]] = steps[i].

For slicing to the end of a dimension with unknown size, it is recommended to pass in INT_MAX when slicing forward and ‘INT_MIN’ when slicing backward.

Example 1:
data = [

[1, 2, 3, 4], [5, 6, 7, 8],

] axes = [0, 1] starts = [1, 0] ends = [2, 3] steps = [1, 2] result = [

[5, 7],

]

Example 2:
data = [

[1, 2, 3, 4], [5, 6, 7, 8],

] starts = [0, 1] ends = [-1, 1000] result = [

[2, 3, 4],

]

Inputs

Between 3 and 5 inputs.

• data (heterogeneous) - T: Tensor of data to extract slices from.

• starts (heterogeneous) - Tind: 1-D tensor of starting indices of corresponding axis in axes

• ends (heterogeneous) - Tind: 1-D tensor of ending indices (exclusive) of corresponding axis in axes

• axes (optional, heterogeneous) - Tind: 1-D tensor of axes that starts and ends apply to. Negative value means counting dimensions from the back. Accepted range is [-r, r-1] where r = rank(data). Behavior is undefined if an axis is repeated.

• steps (optional, heterogeneous) - Tind: 1-D tensor of slice step of corresponding axis in axes. Negative value means slicing backward. ‘steps’ cannot be 0. Defaults to 1s.

Outputs

• output (heterogeneous) - T: Sliced data tensor.

Type Constraints

• T in ( tensor(bfloat16), tensor(bool), tensor(complex128), tensor(complex64), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(string), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8) ): Constrain input and output types to all tensor types.

• Tind in ( tensor(int32), tensor(int64) ): Constrain indices to integer types

Examples

_slice

```node = onnx.helper.make_node(
"Slice",
inputs=["x", "starts", "ends", "axes", "steps"],
outputs=["y"],
)

x = np.random.randn(20, 10, 5).astype(np.float32)
y = x[0:3, 0:10]
starts = np.array([0, 0], dtype=np.int64)
ends = np.array([3, 10], dtype=np.int64)
axes = np.array([0, 1], dtype=np.int64)
steps = np.array([1, 1], dtype=np.int64)

expect(
node, inputs=[x, starts, ends, axes, steps], outputs=[y], name="test_slice"
)
```

_slice_neg

```node = onnx.helper.make_node(
"Slice",
inputs=["x", "starts", "ends", "axes", "steps"],
outputs=["y"],
)

x = np.random.randn(20, 10, 5).astype(np.float32)
starts = np.array([0], dtype=np.int64)
ends = np.array([-1], dtype=np.int64)
axes = np.array([1], dtype=np.int64)
steps = np.array([1], dtype=np.int64)
y = x[:, 0:-1]

expect(
node,
inputs=[x, starts, ends, axes, steps],
outputs=[y],
name="test_slice_neg",
)
```

_slice_start_out_of_bounds

```node = onnx.helper.make_node(
"Slice",
inputs=["x", "starts", "ends", "axes", "steps"],
outputs=["y"],
)

x = np.random.randn(20, 10, 5).astype(np.float32)
starts = np.array([1000], dtype=np.int64)
ends = np.array([1000], dtype=np.int64)
axes = np.array([1], dtype=np.int64)
steps = np.array([1], dtype=np.int64)
y = x[:, 1000:1000]

expect(
node,
inputs=[x, starts, ends, axes, steps],
outputs=[y],
name="test_slice_start_out_of_bounds",
)
```

_slice_end_out_of_bounds

```node = onnx.helper.make_node(
"Slice",
inputs=["x", "starts", "ends", "axes", "steps"],
outputs=["y"],
)

x = np.random.randn(20, 10, 5).astype(np.float32)
starts = np.array([1], dtype=np.int64)
ends = np.array([1000], dtype=np.int64)
axes = np.array([1], dtype=np.int64)
steps = np.array([1], dtype=np.int64)
y = x[:, 1:1000]

expect(
node,
inputs=[x, starts, ends, axes, steps],
outputs=[y],
name="test_slice_end_out_of_bounds",
)
```

_slice_default_axes

```node = onnx.helper.make_node(
"Slice",
inputs=["x", "starts", "ends"],
outputs=["y"],
)

x = np.random.randn(20, 10, 5).astype(np.float32)
starts = np.array([0, 0, 3], dtype=np.int64)
ends = np.array([20, 10, 4], dtype=np.int64)
y = x[:, :, 3:4]

expect(
node, inputs=[x, starts, ends], outputs=[y], name="test_slice_default_axes"
)
```

_slice_default_steps

```node = onnx.helper.make_node(
"Slice",
inputs=["x", "starts", "ends", "axes"],
outputs=["y"],
)

x = np.random.randn(20, 10, 5).astype(np.float32)
starts = np.array([0, 0, 3], dtype=np.int64)
ends = np.array([20, 10, 4], dtype=np.int64)
axes = np.array([0, 1, 2], dtype=np.int64)
y = x[:, :, 3:4]

expect(
node,
inputs=[x, starts, ends, axes],
outputs=[y],
name="test_slice_default_steps",
)
```

_slice_neg_steps

```node = onnx.helper.make_node(
"Slice",
inputs=["x", "starts", "ends", "axes", "steps"],
outputs=["y"],
)

x = np.random.randn(20, 10, 5).astype(np.float32)
starts = np.array([20, 10, 4], dtype=np.int64)
ends = np.array([0, 0, 1], dtype=np.int64)
axes = np.array([0, 1, 2], dtype=np.int64)
steps = np.array([-1, -3, -2]).astype(np.int64)
y = x[20:0:-1, 10:0:-3, 4:1:-2]

expect(
node,
inputs=[x, starts, ends, axes, steps],
outputs=[y],
name="test_slice_neg_steps",
)
```

_slice_negative_axes

```node = onnx.helper.make_node(
"Slice",
inputs=["x", "starts", "ends", "axes"],
outputs=["y"],
)

x = np.random.randn(20, 10, 5).astype(np.float32)
starts = np.array([0, 0, 3], dtype=np.int64)
ends = np.array([20, 10, 4], dtype=np.int64)
axes = np.array([0, -2, -1], dtype=np.int64)
y = x[:, :, 3:4]

expect(
node,
inputs=[x, starts, ends, axes],
outputs=[y],
name="test_slice_negative_axes",
)
```

Differences

 `0` `0` `Produces a slice of the input tensor along multiple axes. Similar to numpy:` `Produces a slice of the input tensor along multiple axes. Similar to numpy:` `1` `1` `https://docs.scipy.org/doc/numpy/reference/arrays.indexing.html` `https://numpy.org/doc/stable/user/basics.indexing.html?highlight=slice#slicing-and-striding` `2` `2` `3` `Slices uses starts, ends, axes and steps inputs to specify the start and end` `Slice uses the starts, ends, axes and steps inputs to select a sub-tensor` `3` `4` `dimension and step for each axis in the list of axes, it uses this information to` `of its input data tensor.` `5` `6` `An effective start[i], end[i], and step[i] must be computed for each i` `7` `in [0, ... r-1] where r = rank(input) as follows:` `8` `9` `If axes are omitted, they are set to [0, ..., r-1].` `10` `If steps are omitted, they are set to [1, ..., 1] of length len(starts)` `11` `12` `The effective values are initialized as start[i] = 0, end[i] = dims[i] where` `13` `dims are the dimensions of input and step[i] = 1.` `14` `15` `All negative elements of axes are made non-negatve by adding r to them, where` `4` `16` `slice the input data tensor. If a negative value is passed for any of the` `r =rank(input).` `17` `18` `All negative values in starts[i] and ends[i] have dims[axes[i]] added to them,` `19` `where dims are the dimensions of input. Then start[axes[i]] is the adjusted` `20` `starts[i] is clamped into the range [0, dims[axes[i]]] for positive stepping` `21` `and [0, dims[axes[i]]-1] for negative stepping.` `22` `23` `The clamping for the adjusted ends[i] depends on the sign of steps[i] and must` `24` `accommodate copying 0 through dims[axes[i]] elements, so for positive stepping` `25` `end[axes[i]] is clamped to [0, dims[axes[i]]], while for negative stepping it` `5` `26` `start or end indices, it represents number of elements before the end of that` `is clamped to [-1, dims[axes[i]]-1].` `27` `6` `28` `dimension. If the value passed to start or end is larger than the n (the` `Finally, step[axes[i]] = steps[i].` `7` `number of elements in this dimension), it represents n. For slicing to the` `29` `8` `30` `end of a dimension with unknown size, it is recommended to pass in INT_MAX` `For slicing to the end of a dimension with unknown size, it is recommended to pass` `9` `31` `when slicing forward and 'INT_MIN' when slicing backward.` `in INT_MAX when slicing forward and 'INT_MIN' when slicing backward.` `10` `If a negative value is passed for step, it represents slicing backward.` `11` `However step value cannot be 0.` `12` `If axes are omitted, they are set to [0, ..., ndim-1].` `13` `If steps are omitted, they are set to [1, ..., 1] of length len(starts)` `32` `14` `33` `Example 1:` `Example 1:` `15` `34` ` data = [` ` data = [` `16` `35` ` [1, 2, 3, 4],` ` [1, 2, 3, 4],` `17` `36` ` [5, 6, 7, 8],` ` [5, 6, 7, 8],` `18` `37` ` ]` ` ]` `19` `38` ` axes = [0, 1]` ` axes = [0, 1]` `20` `39` ` starts = [1, 0]` ` starts = [1, 0]` `21` `40` ` ends = [2, 3]` ` ends = [2, 3]` `22` `41` ` steps = [1, 2]` ` steps = [1, 2]` `23` `42` ` result = [` ` result = [` `24` `43` ` [5, 7],` ` [5, 7],` `25` `44` ` ]` ` ]` `26` `45` `Example 2:` `Example 2:` `27` `46` ` data = [` ` data = [` `28` `47` ` [1, 2, 3, 4],` ` [1, 2, 3, 4],` `29` `48` ` [5, 6, 7, 8],` ` [5, 6, 7, 8],` `30` `49` ` ]` ` ]` `31` `50` ` starts = [0, 1]` ` starts = [0, 1]` `32` `51` ` ends = [-1, 1000]` ` ends = [-1, 1000]` `33` `52` ` result = [` ` result = [` `34` `53` ` [2, 3, 4],` ` [2, 3, 4],` `35` `54` ` ]` ` ]` `36` `55` `37` `56` `**Inputs**` `**Inputs**` `38` `57` `39` `58` `Between 3 and 5 inputs.` `Between 3 and 5 inputs.` `40` `59` `41` `60` `* **data** (heterogeneous) - **T**:` `* **data** (heterogeneous) - **T**:` `42` `61` ` Tensor of data to extract slices from.` ` Tensor of data to extract slices from.` `43` `62` `* **starts** (heterogeneous) - **Tind**:` `* **starts** (heterogeneous) - **Tind**:` `44` `63` ` 1-D tensor of starting indices of corresponding axis in axes` ` 1-D tensor of starting indices of corresponding axis in axes` `45` `64` `* **ends** (heterogeneous) - **Tind**:` `* **ends** (heterogeneous) - **Tind**:` `46` `65` ` 1-D tensor of ending indices (exclusive) of corresponding axis in` ` 1-D tensor of ending indices (exclusive) of corresponding axis in` `47` `66` ` axes` ` axes` `48` `67` `* **axes** (optional, heterogeneous) - **Tind**:` `* **axes** (optional, heterogeneous) - **Tind**:` `49` `68` ` 1-D tensor of axes that starts and ends apply to. Negative value` ` 1-D tensor of axes that starts and ends apply to. Negative value` `50` `69` ` means counting dimensions from the back. Accepted range is [-r, r-1]` ` means counting dimensions from the back. Accepted range is [-r, r-1]` `51` `70` ` where r = rank(data).` ` where r = rank(data). Behavior is undefined if an axis is repeated.` `52` `71` `* **steps** (optional, heterogeneous) - **Tind**:` `* **steps** (optional, heterogeneous) - **Tind**:` `53` `72` ` 1-D tensor of slice step of corresponding axis in axes. Negative` ` 1-D tensor of slice step of corresponding axis in axes. Negative` `54` `73` ` value means slicing backward. 'steps' cannot be 0. Defaults to 1.` ` value means slicing backward. 'steps' cannot be 0. Defaults to 1s.` `55` `74` `56` `75` `**Outputs**` `**Outputs**` `57` `76` `58` `77` `* **output** (heterogeneous) - **T**:` `* **output** (heterogeneous) - **T**:` `59` `78` ` Sliced data tensor.` ` Sliced data tensor.` `60` `79` `61` `80` `**Type Constraints**` `**Type Constraints**` `62` `81` `63` `82` `* **T** in (` `* **T** in (` `83` ` tensor(bfloat16),` `64` `84` ` tensor(bool),` ` tensor(bool),` `65` `85` ` tensor(complex128),` ` tensor(complex128),` `66` `86` ` tensor(complex64),` ` tensor(complex64),` `67` `87` ` tensor(double),` ` tensor(double),` `68` `88` ` tensor(float),` ` tensor(float),` `69` `89` ` tensor(float16),` ` tensor(float16),` `70` `90` ` tensor(int16),` ` tensor(int16),` `71` `91` ` tensor(int32),` ` tensor(int32),` `72` `92` ` tensor(int64),` ` tensor(int64),` `73` `93` ` tensor(int8),` ` tensor(int8),` `74` `94` ` tensor(string),` ` tensor(string),` `75` `95` ` tensor(uint16),` ` tensor(uint16),` `76` `96` ` tensor(uint32),` ` tensor(uint32),` `77` `97` ` tensor(uint64),` ` tensor(uint64),` `78` `98` ` tensor(uint8)` ` tensor(uint8)` `79` `99` ` ):` ` ):` `80` `100` ` Constrain input and output types to all tensor types.` ` Constrain input and output types to all tensor types.` `81` `101` `* **Tind** in (` `* **Tind** in (` `82` `102` ` tensor(int32),` ` tensor(int32),` `83` `103` ` tensor(int64)` ` tensor(int64)` `84` `104` ` ):` ` ):` `85` `105` ` Constrain indices to integer types` ` Constrain indices to integer types`

## Slice - 11#

Version

• name: Slice (GitHub)

• domain: main

• since_version: 11

• function: False

• support_level: SupportType.COMMON

• shape inference: True

This version of the operator has been available since version 11.

Summary

Produces a slice of the input tensor along multiple axes. Similar to numpy: https://docs.scipy.org/doc/numpy/reference/arrays.indexing.html Slices uses starts, ends, axes and steps inputs to specify the start and end dimension and step for each axis in the list of axes, it uses this information to slice the input data tensor. If a negative value is passed for any of the start or end indices, it represents number of elements before the end of that dimension. If the value passed to start or end is larger than the n (the number of elements in this dimension), it represents n. For slicing to the end of a dimension with unknown size, it is recommended to pass in INT_MAX when slicing forward and ‘INT_MIN’ when slicing backward. If a negative value is passed for step, it represents slicing backward. However step value cannot be 0. If axes are omitted, they are set to [0, …, ndim-1]. If steps are omitted, they are set to [1, …, 1] of length len(starts) Example 1:

data = [

[1, 2, 3, 4], [5, 6, 7, 8],

] axes = [0, 1] starts = [1, 0] ends = [2, 3] steps = [1, 2] result = [

[5, 7],

]

Example 2:
data = [

[1, 2, 3, 4], [5, 6, 7, 8],

] starts = [0, 1] ends = [-1, 1000] result = [

[2, 3, 4],

]

Inputs

Between 3 and 5 inputs.

• data (heterogeneous) - T: Tensor of data to extract slices from.

• starts (heterogeneous) - Tind: 1-D tensor of starting indices of corresponding axis in axes

• ends (heterogeneous) - Tind: 1-D tensor of ending indices (exclusive) of corresponding axis in axes

• axes (optional, heterogeneous) - Tind: 1-D tensor of axes that starts and ends apply to. Negative value means counting dimensions from the back. Accepted range is [-r, r-1] where r = rank(data).

• steps (optional, heterogeneous) - Tind: 1-D tensor of slice step of corresponding axis in axes. Negative value means slicing backward. ‘steps’ cannot be 0. Defaults to 1.

Outputs

• output (heterogeneous) - T: Sliced data tensor.

Type Constraints

• T in ( tensor(bool), tensor(complex128), tensor(complex64), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(string), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8) ): Constrain input and output types to all tensor types.

• Tind in ( tensor(int32), tensor(int64) ): Constrain indices to integer types

Differences

 `0` `0` `Produces a slice of the input tensor along multiple axes. Similar to numpy:` `Produces a slice of the input tensor along multiple axes. Similar to numpy:` `1` `1` `https://docs.scipy.org/doc/numpy/reference/arrays.indexing.html` `https://docs.scipy.org/doc/numpy/reference/arrays.indexing.html` `2` `2` `Slices uses starts, ends, axes and steps inputs to specify the start and end` `Slices uses starts, ends, axes and steps inputs to specify the start and end` `3` `3` `dimension and step for each axis in the list of axes, it uses this information to` `dimension and step for each axis in the list of axes, it uses this information to` `4` `4` `slice the input data tensor. If a negative value is passed for any of the` `slice the input data tensor. If a negative value is passed for any of the` `5` `5` `start or end indices, it represent number of elements before the end of that` `start or end indices, it represents number of elements before the end of that` `6` `6` `dimension. If the value passed to start or end is larger than the n (the` `dimension. If the value passed to start or end is larger than the n (the` `7` `7` `number of elements in this dimension), it represents n. For slicing to the` `number of elements in this dimension), it represents n. For slicing to the` `8` `8` `end of a dimension with unknown size, it is recommended to pass in INT_MAX.` `end of a dimension with unknown size, it is recommended to pass in INT_MAX` `9` `when slicing forward and 'INT_MIN' when slicing backward.` `9` `10` `If a negative value is passed for step, it represents slicing backward.` `If a negative value is passed for step, it represents slicing backward.` `11` `However step value cannot be 0.` `10` `12` `If axes are omitted, they are set to [0, ..., ndim-1].` `If axes are omitted, they are set to [0, ..., ndim-1].` `11` `13` `If steps are omitted, they are set to [1, ..., 1] of length len(starts)` `If steps are omitted, they are set to [1, ..., 1] of length len(starts)` `12` `14` `Example 1:` `Example 1:` `13` `15` ` data = [` ` data = [` `14` `16` ` [1, 2, 3, 4],` ` [1, 2, 3, 4],` `15` `17` ` [5, 6, 7, 8],` ` [5, 6, 7, 8],` `16` `18` ` ]` ` ]` `17` `19` ` axes = [0, 1]` ` axes = [0, 1]` `18` `20` ` starts = [1, 0]` ` starts = [1, 0]` `19` `21` ` ends = [2, 3]` ` ends = [2, 3]` `20` `22` ` steps = [1, 2]` ` steps = [1, 2]` `21` `23` ` result = [` ` result = [` `22` `24` ` [5, 7],` ` [5, 7],` `23` `25` ` ]` ` ]` `24` `26` `Example 2:` `Example 2:` `25` `27` ` data = [` ` data = [` `26` `28` ` [1, 2, 3, 4],` ` [1, 2, 3, 4],` `27` `29` ` [5, 6, 7, 8],` ` [5, 6, 7, 8],` `28` `30` ` ]` ` ]` `29` `31` ` starts = [0, 1]` ` starts = [0, 1]` `30` `32` ` ends = [-1, 1000]` ` ends = [-1, 1000]` `31` `33` ` result = [` ` result = [` `32` `34` ` [2, 3, 4],` ` [2, 3, 4],` `33` `35` ` ]` ` ]` `34` `36` `35` `37` `**Inputs**` `**Inputs**` `36` `38` `37` `39` `Between 3 and 5 inputs.` `Between 3 and 5 inputs.` `38` `40` `39` `41` `* **data** (heterogeneous) - **T**:` `* **data** (heterogeneous) - **T**:` `40` `42` ` Tensor of data to extract slices from.` ` Tensor of data to extract slices from.` `41` `43` `* **starts** (heterogeneous) - **Tind**:` `* **starts** (heterogeneous) - **Tind**:` `42` `44` ` 1-D tensor of starting indices of corresponding axis in axes` ` 1-D tensor of starting indices of corresponding axis in axes` `43` `45` `* **ends** (heterogeneous) - **Tind**:` `* **ends** (heterogeneous) - **Tind**:` `44` `46` ` 1-D tensor of ending indices (exclusive) of corresponding axis in` ` 1-D tensor of ending indices (exclusive) of corresponding axis in` `45` `47` ` axes` ` axes` `46` `48` `* **axes** (optional, heterogeneous) - **Tind**:` `* **axes** (optional, heterogeneous) - **Tind**:` `47` `49` ` 1-D tensor of axes that starts and ends apply to.` ` 1-D tensor of axes that starts and ends apply to. Negative value` `50` ` means counting dimensions from the back. Accepted range is [-r, r-1]` `51` ` where r = rank(data).` `48` `52` `* **steps** (optional, heterogeneous) - **Tind**:` `* **steps** (optional, heterogeneous) - **Tind**:` `49` `53` ` 1-D tensor of slice step of corresponding axis in axes. Default to` ` 1-D tensor of slice step of corresponding axis in axes. Negative` `50` ` 1.` `54` ` value means slicing backward. 'steps' cannot be 0. Defaults to 1.` `51` `55` `52` `56` `**Outputs**` `**Outputs**` `53` `57` `54` `58` `* **output** (heterogeneous) - **T**:` `* **output** (heterogeneous) - **T**:` `55` `59` ` Sliced data tensor.` ` Sliced data tensor.` `56` `60` `57` `61` `**Type Constraints**` `**Type Constraints**` `58` `62` `59` `63` `* **T** in (` `* **T** in (` `60` `64` ` tensor(bool),` ` tensor(bool),` `61` `65` ` tensor(complex128),` ` tensor(complex128),` `62` `66` ` tensor(complex64),` ` tensor(complex64),` `63` `67` ` tensor(double),` ` tensor(double),` `64` `68` ` tensor(float),` ` tensor(float),` `65` `69` ` tensor(float16),` ` tensor(float16),` `66` `70` ` tensor(int16),` ` tensor(int16),` `67` `71` ` tensor(int32),` ` tensor(int32),` `68` `72` ` tensor(int64),` ` tensor(int64),` `69` `73` ` tensor(int8),` ` tensor(int8),` `70` `74` ` tensor(string),` ` tensor(string),` `71` `75` ` tensor(uint16),` ` tensor(uint16),` `72` `76` ` tensor(uint32),` ` tensor(uint32),` `73` `77` ` tensor(uint64),` ` tensor(uint64),` `74` `78` ` tensor(uint8)` ` tensor(uint8)` `75` `79` ` ):` ` ):` `76` `80` ` Constrain input and output types to all tensor types.` ` Constrain input and output types to all tensor types.` `77` `81` `* **Tind** in (` `* **Tind** in (` `78` `82` ` tensor(int32),` ` tensor(int32),` `79` `83` ` tensor(int64)` ` tensor(int64)` `80` `84` ` ):` ` ):` `81` `85` ` Constrain indices to integer types` ` Constrain indices to integer types`

## Slice - 10#

Version

• name: Slice (GitHub)

• domain: main

• since_version: 10

• function: False

• support_level: SupportType.COMMON

• shape inference: True

This version of the operator has been available since version 10.

Summary

Produces a slice of the input tensor along multiple axes. Similar to numpy: https://docs.scipy.org/doc/numpy/reference/arrays.indexing.html Slices uses starts, ends, axes and steps inputs to specify the start and end dimension and step for each axis in the list of axes, it uses this information to slice the input data tensor. If a negative value is passed for any of the start or end indices, it represent number of elements before the end of that dimension. If the value passed to start or end is larger than the n (the number of elements in this dimension), it represents n. For slicing to the end of a dimension with unknown size, it is recommended to pass in INT_MAX. If a negative value is passed for step, it represents slicing backward. If axes are omitted, they are set to [0, …, ndim-1]. If steps are omitted, they are set to [1, …, 1] of length len(starts) Example 1:

data = [

[1, 2, 3, 4], [5, 6, 7, 8],

] axes = [0, 1] starts = [1, 0] ends = [2, 3] steps = [1, 2] result = [

[5, 7],

]

Example 2:
data = [

[1, 2, 3, 4], [5, 6, 7, 8],

] starts = [0, 1] ends = [-1, 1000] result = [

[2, 3, 4],

]

Inputs

Between 3 and 5 inputs.

• data (heterogeneous) - T: Tensor of data to extract slices from.

• starts (heterogeneous) - Tind: 1-D tensor of starting indices of corresponding axis in axes

• ends (heterogeneous) - Tind: 1-D tensor of ending indices (exclusive) of corresponding axis in axes

• axes (optional, heterogeneous) - Tind: 1-D tensor of axes that starts and ends apply to.

• steps (optional, heterogeneous) - Tind: 1-D tensor of slice step of corresponding axis in axes. Default to 1.

Outputs

• output (heterogeneous) - T: Sliced data tensor.

Type Constraints

• T in ( tensor(bool), tensor(complex128), tensor(complex64), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(string), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8) ): Constrain input and output types to all tensor types.

• Tind in ( tensor(int32), tensor(int64) ): Constrain indices to integer types

Differences

 `0` `0` `Produces a slice of the input tensor along multiple axes. Similar to numpy:` `Produces a slice of the input tensor along multiple axes. Similar to numpy:` `1` `1` `https://docs.scipy.org/doc/numpy/reference/arrays.indexing.html` `https://docs.scipy.org/doc/numpy/reference/arrays.indexing.html` `2` `2` `Slices uses axes, starts and ends attributes to specify the start and end` `Slices uses starts, ends, axes and steps inputs to specify the start and end` `3` `3` `dimension for each axis in the list of axes, it uses this information to` `dimension and step for each axis in the list of axes, it uses this information to` `4` `4` `slice the input data tensor. If a negative value is passed for any of the` `slice the input data tensor. If a negative value is passed for any of the` `5` `5` `start or end indices, it represent number of elements before the end of that` `start or end indices, it represent number of elements before the end of that` `6` `6` `dimension. If the value passed to start or end is larger than the n (the` `dimension. If the value passed to start or end is larger than the n (the` `7` `7` `number of elements in this dimension), it represents n. For slicing to the` `number of elements in this dimension), it represents n. For slicing to the` `8` `8` `end of a dimension with unknown size, it is recommended to pass in INT_MAX.` `end of a dimension with unknown size, it is recommended to pass in INT_MAX.` `9` `If a negative value is passed for step, it represents slicing backward.` `9` `10` `If axes are omitted, they are set to [0, ..., ndim-1].` `If axes are omitted, they are set to [0, ..., ndim-1].` `11` `If steps are omitted, they are set to [1, ..., 1] of length len(starts)` `10` `12` `Example 1:` `Example 1:` `11` `13` ` data = [` ` data = [` `12` `14` ` [1, 2, 3, 4],` ` [1, 2, 3, 4],` `13` `15` ` [5, 6, 7, 8],` ` [5, 6, 7, 8],` `14` `16` ` ]` ` ]` `15` `17` ` axes = [0, 1]` ` axes = [0, 1]` `16` `18` ` starts = [1, 0]` ` starts = [1, 0]` `17` `19` ` ends = [2, 3]` ` ends = [2, 3]` `20` ` steps = [1, 2]` `18` `21` ` result = [` ` result = [` `19` `22` ` [5, 6, 7],` ` [5, 7],` `20` `23` ` ]` ` ]` `21` `24` `Example 2:` `Example 2:` `22` `25` ` data = [` ` data = [` `23` `26` ` [1, 2, 3, 4],` ` [1, 2, 3, 4],` `24` `27` ` [5, 6, 7, 8],` ` [5, 6, 7, 8],` `25` `28` ` ]` ` ]` `26` `29` ` starts = [0, 1]` ` starts = [0, 1]` `27` `30` ` ends = [-1, 1000]` ` ends = [-1, 1000]` `28` `31` ` result = [` ` result = [` `29` `32` ` [2, 3, 4],` ` [2, 3, 4],` `30` `33` ` ]` ` ]` `31` `34` `32` `**Attributes**` `33` `34` `* **axes**:` `35` `35` ` Axes that starts and ends apply to. It's optional. If not` `**Inputs**` `36` `36` `37` ` present, will be treated as [0, 1, ..., len(starts) - 1].` `Between 3 and 5 inputs.` `38` `39` `* **data** (heterogeneous) - **T**:` `40` ` Tensor of data to extract slices from.` `41` `* **starts** (heterogeneous) - **Tind**:` `37` `42` `* **ends** (required):` ` 1-D tensor of starting indices of corresponding axis in axes` `43` `* **ends** (heterogeneous) - **Tind**:` `38` `44` ` Ending indices (exclusive) of corresponding axis in axes` ` 1-D tensor of ending indices (exclusive) of corresponding axis in` `39` `* **starts** (required):` `40` ` Starting indices of corresponding axis in axes` `41` `45` ` axes` `42` `46` `**Inputs**` `* **axes** (optional, heterogeneous) - **Tind**:` `43` `47` ` 1-D tensor of axes that starts and ends apply to.` `44` `48` `* **data** (heterogeneous) - **T**:` `* **steps** (optional, heterogeneous) - **Tind**:` `45` ` Tensor of data to extract slices from.` `49` ` 1-D tensor of slice step of corresponding axis in axes. Default to` `50` ` 1.` `46` `51` `47` `52` `**Outputs**` `**Outputs**` `48` `53` `49` `54` `* **output** (heterogeneous) - **T**:` `* **output** (heterogeneous) - **T**:` `50` `55` ` Sliced data tensor.` ` Sliced data tensor.` `51` `56` `52` `57` `**Type Constraints**` `**Type Constraints**` `53` `58` `54` `59` `* **T** in (` `* **T** in (` `55` `60` ` tensor(bool),` ` tensor(bool),` `56` `61` ` tensor(complex128),` ` tensor(complex128),` `57` `62` ` tensor(complex64),` ` tensor(complex64),` `58` `63` ` tensor(double),` ` tensor(double),` `59` `64` ` tensor(float),` ` tensor(float),` `60` `65` ` tensor(float16),` ` tensor(float16),` `61` `66` ` tensor(int16),` ` tensor(int16),` `62` `67` ` tensor(int32),` ` tensor(int32),` `63` `68` ` tensor(int64),` ` tensor(int64),` `64` `69` ` tensor(int8),` ` tensor(int8),` `65` `70` ` tensor(string),` ` tensor(string),` `66` `71` ` tensor(uint16),` ` tensor(uint16),` `67` `72` ` tensor(uint32),` ` tensor(uint32),` `68` `73` ` tensor(uint64),` ` tensor(uint64),` `69` `74` ` tensor(uint8)` ` tensor(uint8)` `70` `75` ` ):` ` ):` `71` `76` ` Constrain input and output types to all tensor types.` ` Constrain input and output types to all tensor types.` `77` `* **Tind** in (` `78` ` tensor(int32),` `79` ` tensor(int64)` `80` ` ):` `81` ` Constrain indices to integer types`

## Slice - 1#

Version

• name: Slice (GitHub)

• domain: main

• since_version: 1

• function: False

• support_level: SupportType.COMMON

• shape inference: True

This version of the operator has been available since version 1.

Summary

Produces a slice of the input tensor along multiple axes. Similar to numpy: https://docs.scipy.org/doc/numpy/reference/arrays.indexing.html Slices uses axes, starts and ends attributes to specify the start and end dimension for each axis in the list of axes, it uses this information to slice the input data tensor. If a negative value is passed for any of the start or end indices, it represent number of elements before the end of that dimension. If the value passed to start or end is larger than the n (the number of elements in this dimension), it represents n. For slicing to the end of a dimension with unknown size, it is recommended to pass in INT_MAX. If axes are omitted, they are set to [0, …, ndim-1]. Example 1:

data = [

[1, 2, 3, 4], [5, 6, 7, 8],

] axes = [0, 1] starts = [1, 0] ends = [2, 3] result = [

[5, 6, 7],

]

Example 2:
data = [

[1, 2, 3, 4], [5, 6, 7, 8],

] starts = [0, 1] ends = [-1, 1000] result = [

[2, 3, 4],

]

Attributes

• axes: Axes that starts and ends apply to. It’s optional. If not present, will be treated as [0, 1, …, len(starts) - 1].

• ends (required): Ending indices (exclusive) of corresponding axis in axes`

• starts (required): Starting indices of corresponding axis in axes

Inputs

• data (heterogeneous) - T: Tensor of data to extract slices from.

Outputs

• output (heterogeneous) - T: Sliced data tensor.

Type Constraints

• T in ( tensor(bool), tensor(complex128), tensor(complex64), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(string), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8) ): Constrain input and output types to all tensor types.