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
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 represents 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 | 9 | when sclicing forward and 'INT_MIN' when slicing backward. | when sclicing forward and 'INT_MIN' when slicing backward. |
10 | 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 | 11 | However step value cannot be 0. | However step value cannot be 0. |
12 | 12 | If axes are omitted, they are set to [0, ..., ndim-1]. | If axes are omitted, they are set to [0, ..., ndim-1]. |
13 | 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) |
14 | 14 | Example 1: | Example 1: |
15 | 15 | data = [ | data = [ |
16 | 16 | [1, 2, 3, 4], | [1, 2, 3, 4], |
17 | 17 | [5, 6, 7, 8], | [5, 6, 7, 8], |
18 | 18 | ] | ] |
19 | 19 | axes = [0, 1] | axes = [0, 1] |
20 | 20 | starts = [1, 0] | starts = [1, 0] |
21 | 21 | ends = [2, 3] | ends = [2, 3] |
22 | 22 | steps = [1, 2] | steps = [1, 2] |
23 | 23 | result = [ | result = [ |
24 | 24 | [5, 7], | [5, 7], |
25 | 25 | ] | ] |
26 | 26 | Example 2: | Example 2: |
27 | 27 | data = [ | data = [ |
28 | 28 | [1, 2, 3, 4], | [1, 2, 3, 4], |
29 | 29 | [5, 6, 7, 8], | [5, 6, 7, 8], |
30 | 30 | ] | ] |
31 | 31 | starts = [0, 1] | starts = [0, 1] |
32 | 32 | ends = [-1, 1000] | ends = [-1, 1000] |
33 | 33 | result = [ | result = [ |
34 | 34 | [2, 3, 4], | [2, 3, 4], |
35 | 35 | ] | ] |
36 | 36 |
|
|
37 | 37 | **Inputs** | **Inputs** |
38 | 38 |
|
|
39 | 39 | Between 3 and 5 inputs. | Between 3 and 5 inputs. |
40 | 40 |
|
|
41 | 41 | * **data** (heterogeneous) - **T**: | * **data** (heterogeneous) - **T**: |
42 | 42 | Tensor of data to extract slices from. | Tensor of data to extract slices from. |
43 | 43 | * **starts** (heterogeneous) - **Tind**: | * **starts** (heterogeneous) - **Tind**: |
44 | 44 | 1-D tensor of starting indices of corresponding axis in axes | 1-D tensor of starting indices of corresponding axis in axes |
45 | 45 | * **ends** (heterogeneous) - **Tind**: | * **ends** (heterogeneous) - **Tind**: |
46 | 46 | 1-D tensor of ending indices (exclusive) of corresponding axis in | 1-D tensor of ending indices (exclusive) of corresponding axis in |
47 | 47 | axes | axes |
48 | 48 | * **axes** (optional, heterogeneous) - **Tind**: | * **axes** (optional, heterogeneous) - **Tind**: |
49 | 49 | 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 | 50 | 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 | 51 | where r = rank(data). | where r = rank(data). |
52 | 52 | * **steps** (optional, heterogeneous) - **Tind**: | * **steps** (optional, heterogeneous) - **Tind**: |
53 | 53 | 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 | 54 | value means slicing backward. 'steps' cannot be 0. Defaults to 1. | value means slicing backward. 'steps' cannot be 0. Defaults to 1. |
55 | 55 |
|
|
56 | 56 | **Outputs** | **Outputs** |
57 | 57 |
|
|
58 | 58 | * **output** (heterogeneous) - **T**: | * **output** (heterogeneous) - **T**: |
59 | 59 | Sliced data tensor. | Sliced data tensor. |
60 | 60 |
|
|
61 | 61 | **Type Constraints** | **Type Constraints** |
62 | 62 |
|
|
63 | 63 | * **T** in ( | * **T** in ( |
64 | tensor(bfloat16), | ||
64 | 65 | tensor(bool), | tensor(bool), |
65 | 66 | tensor(complex128), | tensor(complex128), |
66 | 67 | tensor(complex64), | tensor(complex64), |
67 | 68 | tensor(double), | tensor(double), |
68 | 69 | tensor(float), | tensor(float), |
69 | 70 | tensor(float16), | tensor(float16), |
70 | 71 | tensor(int16), | tensor(int16), |
71 | 72 | tensor(int32), | tensor(int32), |
72 | 73 | tensor(int64), | tensor(int64), |
73 | 74 | tensor(int8), | tensor(int8), |
74 | 75 | tensor(string), | tensor(string), |
75 | 76 | tensor(uint16), | tensor(uint16), |
76 | 77 | tensor(uint32), | tensor(uint32), |
77 | 78 | tensor(uint64), | tensor(uint64), |
78 | 79 | tensor(uint8) | tensor(uint8) |
79 | 80 | ): | ): |
80 | 81 | Constrain input and output types to all tensor types. | Constrain input and output types to all tensor types. |
81 | 82 | * **Tind** in ( | * **Tind** in ( |
82 | 83 | tensor(int32), | tensor(int32), |
83 | 84 | tensor(int64) | tensor(int64) |
84 | 85 | ): | ): |
85 | 86 | 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
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 |
|
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. |
|
9 | when sclicing 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. |
|
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 |
|
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 |
|
3 | 3 | dimension 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], |
|
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 |
|
36 |
| ||
36 | 37 | present, will be treated as [0, 1, ..., len(starts) - 1]. |
|
38 |
| ||
39 | * **data** (heterogeneous) - **T**: | ||
40 | Tensor of data to extract slices from. | ||
41 | * **starts** (heterogeneous) - **Tind**: | ||
37 | 42 | * **ends** (required): |
|
43 | * **ends** (heterogeneous) - **Tind**: | ||
38 | 44 | Ending indices (exclusive) of corresponding axis in axes |
|
39 | * **starts** (required): | ||
40 | Starting indices of corresponding axis in axes | ||
41 |
| ||
45 | axes | ||
42 | 46 | **Inputs** |
|
43 |
| ||
47 | 1-D tensor of axes that starts and ends apply to. | ||
44 | 48 | * **data** (heterogeneous) - **T**: |
|
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.