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