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