Slice - 10 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.

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