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://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 sclicing 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(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

00Produces 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:
11https://docs.scipy.org/doc/numpy/reference/arrays.indexing.htmlhttps://docs.scipy.org/doc/numpy/reference/arrays.indexing.html
22Slices uses starts, ends, axes and steps inputs to specify the start and endSlices uses starts, ends, axes and steps inputs to specify the start and end
33dimension and step for each axis in the list of axes, it uses this information todimension and step for each axis in the list of axes, it uses this information to
44slice the input data tensor. If a negative value is passed for any of theslice the input data tensor. If a negative value is passed for any of the
55start or end indices, it represents number of elements before the end of thatstart or end indices, it represents number of elements before the end of that
66dimension. If the value passed to start or end is larger than the n (thedimension. If the value passed to start or end is larger than the n (the
77number of elements in this dimension), it represents n. For slicing to thenumber of elements in this dimension), it represents n. For slicing to the
88end of a dimension with unknown size, it is recommended to pass in INT_MAXend of a dimension with unknown size, it is recommended to pass in INT_MAX
99when sclicing forward and 'INT_MIN' when slicing backward.when sclicing forward and 'INT_MIN' when slicing backward.
1010If a negative value is passed for step, it represents slicing backward.If a negative value is passed for step, it represents slicing backward.
1111However step value cannot be 0.However step value cannot be 0.
1212If axes are omitted, they are set to [0, ..., ndim-1].If axes are omitted, they are set to [0, ..., ndim-1].
1313If 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)
1414Example 1:Example 1:
1515 data = [ data = [
1616 [1, 2, 3, 4], [1, 2, 3, 4],
1717 [5, 6, 7, 8], [5, 6, 7, 8],
1818 ] ]
1919 axes = [0, 1] axes = [0, 1]
2020 starts = [1, 0] starts = [1, 0]
2121 ends = [2, 3] ends = [2, 3]
2222 steps = [1, 2] steps = [1, 2]
2323 result = [ result = [
2424 [5, 7], [5, 7],
2525 ] ]
2626Example 2:Example 2:
2727 data = [ data = [
2828 [1, 2, 3, 4], [1, 2, 3, 4],
2929 [5, 6, 7, 8], [5, 6, 7, 8],
3030 ] ]
3131 starts = [0, 1] starts = [0, 1]
3232 ends = [-1, 1000] ends = [-1, 1000]
3333 result = [ result = [
3434 [2, 3, 4], [2, 3, 4],
3535 ] ]
3636
3737**Inputs****Inputs**
3838
3939Between 3 and 5 inputs.Between 3 and 5 inputs.
4040
4141* **data** (heterogeneous) - **T**:* **data** (heterogeneous) - **T**:
4242 Tensor of data to extract slices from. Tensor of data to extract slices from.
4343* **starts** (heterogeneous) - **Tind**:* **starts** (heterogeneous) - **Tind**:
4444 1-D tensor of starting indices of corresponding axis in axes 1-D tensor of starting indices of corresponding axis in axes
4545* **ends** (heterogeneous) - **Tind**:* **ends** (heterogeneous) - **Tind**:
4646 1-D tensor of ending indices (exclusive) of corresponding axis in 1-D tensor of ending indices (exclusive) of corresponding axis in
4747 axes axes
4848* **axes** (optional, heterogeneous) - **Tind**:* **axes** (optional, heterogeneous) - **Tind**:
4949 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
5050 means counting dimensions from the back. Accepted range is [-r, r-1] means counting dimensions from the back. Accepted range is [-r, r-1]
5151 where r = rank(data). where r = rank(data).
5252* **steps** (optional, heterogeneous) - **Tind**:* **steps** (optional, heterogeneous) - **Tind**:
5353 1-D tensor of slice step of corresponding axis in axes. Negative 1-D tensor of slice step of corresponding axis in axes. Negative
5454 value means slicing backward. 'steps' cannot be 0. Defaults to 1. value means slicing backward. 'steps' cannot be 0. Defaults to 1.
5555
5656**Outputs****Outputs**
5757
5858* **output** (heterogeneous) - **T**:* **output** (heterogeneous) - **T**:
5959 Sliced data tensor. Sliced data tensor.
6060
6161**Type Constraints****Type Constraints**
6262
6363* **T** in (* **T** in (
64 tensor(bfloat16),
6465 tensor(bool), tensor(bool),
6566 tensor(complex128), tensor(complex128),
6667 tensor(complex64), tensor(complex64),
6768 tensor(double), tensor(double),
6869 tensor(float), tensor(float),
6970 tensor(float16), tensor(float16),
7071 tensor(int16), tensor(int16),
7172 tensor(int32), tensor(int32),
7273 tensor(int64), tensor(int64),
7374 tensor(int8), tensor(int8),
7475 tensor(string), tensor(string),
7576 tensor(uint16), tensor(uint16),
7677 tensor(uint32), tensor(uint32),
7778 tensor(uint64), tensor(uint64),
7879 tensor(uint8) tensor(uint8)
7980 ): ):
8081 Constrain input and output types to all tensor types. Constrain input and output types to all tensor types.
8182* **Tind** in (* **Tind** in (
8283 tensor(int32), tensor(int32),
8384 tensor(int64) tensor(int64)
8485 ): ):
8586 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 sclicing 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

00Produces 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:
11https://docs.scipy.org/doc/numpy/reference/arrays.indexing.htmlhttps://docs.scipy.org/doc/numpy/reference/arrays.indexing.html
22Slices uses starts, ends, axes and steps inputs to specify the start and endSlices uses starts, ends, axes and steps inputs to specify the start and end
33dimension and step for each axis in the list of axes, it uses this information todimension and step for each axis in the list of axes, it uses this information to
44slice the input data tensor. If a negative value is passed for any of theslice the input data tensor. If a negative value is passed for any of the
55start or end indices, it represent number of elements before the end of thatstart or end indices, it represents number of elements before the end of that
66dimension. If the value passed to start or end is larger than the n (thedimension. If the value passed to start or end is larger than the n (the
77number of elements in this dimension), it represents n. For slicing to thenumber of elements in this dimension), it represents n. For slicing to the
88end 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
9when sclicing forward and 'INT_MIN' when slicing backward.
910If a negative value is passed for step, it represents slicing backward.If a negative value is passed for step, it represents slicing backward.
11However step value cannot be 0.
1012If axes are omitted, they are set to [0, ..., ndim-1].If axes are omitted, they are set to [0, ..., ndim-1].
1113If 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)
1214Example 1:Example 1:
1315 data = [ data = [
1416 [1, 2, 3, 4], [1, 2, 3, 4],
1517 [5, 6, 7, 8], [5, 6, 7, 8],
1618 ] ]
1719 axes = [0, 1] axes = [0, 1]
1820 starts = [1, 0] starts = [1, 0]
1921 ends = [2, 3] ends = [2, 3]
2022 steps = [1, 2] steps = [1, 2]
2123 result = [ result = [
2224 [5, 7], [5, 7],
2325 ] ]
2426Example 2:Example 2:
2527 data = [ data = [
2628 [1, 2, 3, 4], [1, 2, 3, 4],
2729 [5, 6, 7, 8], [5, 6, 7, 8],
2830 ] ]
2931 starts = [0, 1] starts = [0, 1]
3032 ends = [-1, 1000] ends = [-1, 1000]
3133 result = [ result = [
3234 [2, 3, 4], [2, 3, 4],
3335 ] ]
3436
3537**Inputs****Inputs**
3638
3739Between 3 and 5 inputs.Between 3 and 5 inputs.
3840
3941* **data** (heterogeneous) - **T**:* **data** (heterogeneous) - **T**:
4042 Tensor of data to extract slices from. Tensor of data to extract slices from.
4143* **starts** (heterogeneous) - **Tind**:* **starts** (heterogeneous) - **Tind**:
4244 1-D tensor of starting indices of corresponding axis in axes 1-D tensor of starting indices of corresponding axis in axes
4345* **ends** (heterogeneous) - **Tind**:* **ends** (heterogeneous) - **Tind**:
4446 1-D tensor of ending indices (exclusive) of corresponding axis in 1-D tensor of ending indices (exclusive) of corresponding axis in
4547 axes axes
4648* **axes** (optional, heterogeneous) - **Tind**:* **axes** (optional, heterogeneous) - **Tind**:
4749 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).
4852* **steps** (optional, heterogeneous) - **Tind**:* **steps** (optional, heterogeneous) - **Tind**:
4953 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.
5155
5256**Outputs****Outputs**
5357
5458* **output** (heterogeneous) - **T**:* **output** (heterogeneous) - **T**:
5559 Sliced data tensor. Sliced data tensor.
5660
5761**Type Constraints****Type Constraints**
5862
5963* **T** in (* **T** in (
6064 tensor(bool), tensor(bool),
6165 tensor(complex128), tensor(complex128),
6266 tensor(complex64), tensor(complex64),
6367 tensor(double), tensor(double),
6468 tensor(float), tensor(float),
6569 tensor(float16), tensor(float16),
6670 tensor(int16), tensor(int16),
6771 tensor(int32), tensor(int32),
6872 tensor(int64), tensor(int64),
6973 tensor(int8), tensor(int8),
7074 tensor(string), tensor(string),
7175 tensor(uint16), tensor(uint16),
7276 tensor(uint32), tensor(uint32),
7377 tensor(uint64), tensor(uint64),
7478 tensor(uint8) tensor(uint8)
7579 ): ):
7680 Constrain input and output types to all tensor types. Constrain input and output types to all tensor types.
7781* **Tind** in (* **Tind** in (
7882 tensor(int32), tensor(int32),
7983 tensor(int64) tensor(int64)
8084 ): ):
8185 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

00Produces 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:
11https://docs.scipy.org/doc/numpy/reference/arrays.indexing.htmlhttps://docs.scipy.org/doc/numpy/reference/arrays.indexing.html
22Slices uses axes, starts and ends attributes to specify the start and endSlices uses starts, ends, axes and steps inputs to specify the start and end
33dimension for each axis in the list of axes, it uses this information todimension and step for each axis in the list of axes, it uses this information to
44slice the input data tensor. If a negative value is passed for any of theslice the input data tensor. If a negative value is passed for any of the
55start or end indices, it represent number of elements before the end of thatstart or end indices, it represent number of elements before the end of that
66dimension. If the value passed to start or end is larger than the n (thedimension. If the value passed to start or end is larger than the n (the
77number of elements in this dimension), it represents n. For slicing to thenumber of elements in this dimension), it represents n. For slicing to the
88end 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.
9If a negative value is passed for step, it represents slicing backward.
910If axes are omitted, they are set to [0, ..., ndim-1].If axes are omitted, they are set to [0, ..., ndim-1].
11If steps are omitted, they are set to [1, ..., 1] of length len(starts)
1012Example 1:Example 1:
1113 data = [ data = [
1214 [1, 2, 3, 4], [1, 2, 3, 4],
1315 [5, 6, 7, 8], [5, 6, 7, 8],
1416 ] ]
1517 axes = [0, 1] axes = [0, 1]
1618 starts = [1, 0] starts = [1, 0]
1719 ends = [2, 3] ends = [2, 3]
20 steps = [1, 2]
1821 result = [ result = [
1922 [5, 6, 7], [5, 7],
2023 ] ]
2124Example 2:Example 2:
2225 data = [ data = [
2326 [1, 2, 3, 4], [1, 2, 3, 4],
2427 [5, 6, 7, 8], [5, 6, 7, 8],
2528 ] ]
2629 starts = [0, 1] starts = [0, 1]
2730 ends = [-1, 1000] ends = [-1, 1000]
2831 result = [ result = [
2932 [2, 3, 4], [2, 3, 4],
3033 ] ]
3134
32**Attributes**
33
34* **axes**:
3535 Axes that starts and ends apply to. It's optional. If not**Inputs**
36
3637 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**:
3742* **ends** (required): 1-D tensor of starting indices of corresponding axis in axes
43* **ends** (heterogeneous) - **Tind**:
3844 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
4246**Inputs*** **axes** (optional, heterogeneous) - **Tind**:
43
47 1-D tensor of axes that starts and ends apply to.
4448* **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.
4651
4752**Outputs****Outputs**
4853
4954* **output** (heterogeneous) - **T**:* **output** (heterogeneous) - **T**:
5055 Sliced data tensor. Sliced data tensor.
5156
5257**Type Constraints****Type Constraints**
5358
5459* **T** in (* **T** in (
5560 tensor(bool), tensor(bool),
5661 tensor(complex128), tensor(complex128),
5762 tensor(complex64), tensor(complex64),
5863 tensor(double), tensor(double),
5964 tensor(float), tensor(float),
6065 tensor(float16), tensor(float16),
6166 tensor(int16), tensor(int16),
6267 tensor(int32), tensor(int32),
6368 tensor(int64), tensor(int64),
6469 tensor(int8), tensor(int8),
6570 tensor(string), tensor(string),
6671 tensor(uint16), tensor(uint16),
6772 tensor(uint32), tensor(uint32),
6873 tensor(uint64), tensor(uint64),
6974 tensor(uint8) tensor(uint8)
7075 ): ):
7176 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.