Slice - 11 vs 13¶
- Slice11 → Slice13 +34 -14
Slice11 → Slice13
RENAMED
@@ -1 +1 @@
|
|
1
1
|
Produces a slice of the input tensor along multiple axes. Similar to numpy:
|
2
|
-
https://
|
2
|
+
https://numpy.org/doc/stable/user/basics.indexing.html?highlight=slice#slicing-and-striding
|
3
|
+
|
3
|
-
|
4
|
+
Slice uses the starts, ends, axes and steps inputs to select a sub-tensor
|
5
|
+
of its input data tensor.
|
6
|
+
|
7
|
+
An effective start[i], end[i], and step[i] must be computed for each i
|
8
|
+
in [0, ... r-1] where r = rank(input) as follows:
|
9
|
+
|
4
|
-
dimension and step for each axis in the list of axes, it uses this information to
|
5
|
-
slice the input data tensor. If a negative value is passed for any of the
|
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
|
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.
|
12
|
-
However step value cannot be 0.
|
13
|
-
If axes are omitted, they are set to [0, ...,
|
10
|
+
If axes are omitted, they are set to [0, ..., r-1].
|
14
11
|
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
|
+
|
15
34
|
Example 1:
|
16
35
|
data = [
|
17
36
|
[1, 2, 3, 4],
|
18
37
|
[5, 6, 7, 8],
|
19
38
|
]
|
20
39
|
axes = [0, 1]
|
21
40
|
starts = [1, 0]
|
22
41
|
ends = [2, 3]
|
23
42
|
steps = [1, 2]
|
24
43
|
result = [
|
25
44
|
[5, 7],
|
26
45
|
]
|
27
46
|
Example 2:
|
28
47
|
data = [
|
29
48
|
[1, 2, 3, 4],
|
30
49
|
[5, 6, 7, 8],
|
31
50
|
]
|
32
51
|
starts = [0, 1]
|
33
52
|
ends = [-1, 1000]
|
34
53
|
result = [
|
35
54
|
[2, 3, 4],
|
36
55
|
]
|
37
56
|
**Inputs**
|
38
57
|
Between 3 and 5 inputs.
|
39
58
|
* **data** (heterogeneous) - **T**:
|
40
59
|
Tensor of data to extract slices from.
|
41
60
|
* **starts** (heterogeneous) - **Tind**:
|
42
61
|
1-D tensor of starting indices of corresponding axis in axes
|
43
62
|
* **ends** (heterogeneous) - **Tind**:
|
44
63
|
1-D tensor of ending indices (exclusive) of corresponding axis in
|
45
64
|
axes
|
46
65
|
* **axes** (optional, heterogeneous) - **Tind**:
|
47
66
|
1-D tensor of axes that starts and ends apply to. Negative value
|
48
67
|
means counting dimensions from the back. Accepted range is [-r, r-1]
|
49
|
-
where r = rank(data).
|
68
|
+
where r = rank(data). Behavior is undefined if an axis is repeated.
|
50
69
|
* **steps** (optional, heterogeneous) - **Tind**:
|
51
70
|
1-D tensor of slice step of corresponding axis in axes. Negative
|
52
|
-
value means slicing backward. 'steps' cannot be 0. Defaults to
|
71
|
+
value means slicing backward. 'steps' cannot be 0. Defaults to 1s.
|
53
72
|
**Outputs**
|
54
73
|
* **output** (heterogeneous) - **T**:
|
55
74
|
Sliced data tensor.
|
56
75
|
**Type Constraints**
|
57
76
|
* **T** in (
|
77
|
+
tensor(bfloat16),
|
58
78
|
tensor(bool),
|
59
79
|
tensor(complex128),
|
60
80
|
tensor(complex64),
|
61
81
|
tensor(double),
|
62
82
|
tensor(float),
|
63
83
|
tensor(float16),
|
64
84
|
tensor(int16),
|
65
85
|
tensor(int32),
|
66
86
|
tensor(int64),
|
67
87
|
tensor(int8),
|
68
88
|
tensor(string),
|
69
89
|
tensor(uint16),
|
70
90
|
tensor(uint32),
|
71
91
|
tensor(uint64),
|
72
92
|
tensor(uint8)
|
73
93
|
):
|
74
94
|
Constrain input and output types to all tensor types.
|
75
95
|
* **Tind** in (
|
76
96
|
tensor(int32),
|
77
97
|
tensor(int64)
|
78
98
|
):
|
79
99
|
Constrain indices to integer types
|