Gather - 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.
- Gather11 → Gather13 +54 -46
Gather11 → Gather13
RENAMED
@@ -1 +1 @@
|
|
1
1
|
Given data tensor of rank r >= 1, and indices tensor of rank q, gather
|
2
2
|
entries of the axis dimension of data (by default outer-most one as axis=0) indexed by indices, and concatenates
|
3
3
|
them in an output tensor of rank q + (r - 1).
|
4
|
+
It is an indexing operation that indexes into the input data along a single (specified) axis.
|
5
|
+
Each entry in indices produces a r-1 dimensional slice of the input tensor.
|
6
|
+
The entire operation produces, conceptually, a q-dimensional tensor of r-1 dimensional slices,
|
7
|
+
which is arranged into a q + (r-1)-dimensional tensor, with the q dimensions taking the
|
4
|
-
axis
|
8
|
+
place of the original axis that is being indexed into.
|
9
|
+
The following few examples illustrate how Gather works for specific shapes of data,
|
5
|
-
|
10
|
+
indices, and given value of axis:
|
11
|
+
| data shape | indices shape | axis | output shape | output equation |
|
12
|
+
| --- | --- | --- | --- | --- |
|
13
|
+
| (P, Q) | ( ) (a scalar) | 0 | (Q) | output[q] = data[indices, q] |
|
14
|
+
| (P, Q, R) | ( ) (a scalar) | 1 | (P, R) | output[p, r] = data[p, indices, r] |
|
15
|
+
| (P, Q) | (R, S) | 0 | (R, S, Q) | output[r, s, q] = data[ [indices[r, s], q] |
|
16
|
+
| (P, Q) | (R, S) | 1 | (P, R, S) | output[p, r, s] = data[ p, indices[r, s]] |
|
17
|
+
|
6
|
-
k = indices[i_{0}, ..., i_{q-1}]
|
18
|
+
More generally, if axis = 0, let k = indices[i_{0}, ..., i_{q-1}]
|
7
|
-
Then
|
8
|
-
output[i_{0}, ..., i_{q-1}, j_{0}, ..., j_{r-2}] = input[k , j_{0}, ..., j_{r-2}]
|
19
|
+
then output[i_{0}, ..., i_{q-1}, j_{0}, ..., j_{r-2}] = input[k , j_{0}, ..., j_{r-2}]:
|
9
|
-
|
20
|
+
data = [
|
10
|
-
|
21
|
+
[1.0, 1.2],
|
11
|
-
|
22
|
+
[2.3, 3.4],
|
12
|
-
|
23
|
+
[4.5, 5.7],
|
13
|
-
|
24
|
+
]
|
14
|
-
|
25
|
+
indices = [
|
15
|
-
|
26
|
+
[0, 1],
|
16
|
-
|
27
|
+
[1, 2],
|
17
|
-
|
28
|
+
]
|
18
|
-
|
29
|
+
output = [
|
19
|
-
|
30
|
+
[
|
20
|
-
|
31
|
+
[1.0, 1.2],
|
21
|
-
|
32
|
+
[2.3, 3.4],
|
22
|
-
|
33
|
+
],
|
23
|
-
|
34
|
+
[
|
24
|
-
|
35
|
+
[2.3, 3.4],
|
25
|
-
|
36
|
+
[4.5, 5.7],
|
26
|
-
|
37
|
+
],
|
38
|
+
]
|
27
|
-
]
|
28
|
-
|
29
|
-
axis = 1 :
|
30
|
-
|
31
|
-
Let
|
32
|
-
k = indices[i_{0}, ..., i_{q-1}]
|
39
|
+
If axis = 1, let k = indices[i_{0}, ..., i_{q-1}]
|
33
|
-
Then
|
34
|
-
output[j_{0}, i_{0}, ..., i_{q-1}, j_{1}, ..., j_{r-2}] = input[j_{0}, k, j_{1}, ..., j_{r-2}]
|
40
|
+
then output[j_{0}, i_{0}, ..., i_{q-1}, j_{1}, ..., j_{r-2}] = input[j_{0}, k, j_{1}, ..., j_{r-2}]:
|
41
|
+
|
42
|
+
|
35
|
-
|
43
|
+
data = [
|
36
|
-
|
44
|
+
[1.0, 1.2, 1.9],
|
37
|
-
|
45
|
+
[2.3, 3.4, 3.9],
|
38
|
-
|
46
|
+
[4.5, 5.7, 5.9],
|
39
|
-
|
47
|
+
]
|
40
|
-
|
48
|
+
indices = [
|
41
|
-
|
49
|
+
[0, 2],
|
42
|
-
|
50
|
+
]
|
43
|
-
|
51
|
+
axis = 1,
|
44
|
-
|
52
|
+
output = [
|
45
|
-
|
53
|
+
[[1.0, 1.9]],
|
46
|
-
|
54
|
+
[[2.3, 3.9]],
|
47
|
-
|
55
|
+
[[4.5, 5.9]],
|
48
|
-
|
56
|
+
]
|
49
57
|
### Attributes
|
50
58
|
* **axis - INT** (default is '0'):
|
51
59
|
Which axis to gather on. Negative value means counting dimensions from the back. Accepted range is [-r, r-1] where r = rank(data).
|
52
60
|
### Inputs
|
53
61
|
- **data** (heterogeneous) - **T**:
|
54
62
|
Tensor of rank r >= 1.
|
55
63
|
- **indices** (heterogeneous) - **Tind**:
|
56
64
|
Tensor of int32/int64 indices, of any rank q. All index values are expected to be within bounds [-s, s-1] along axis of size s. It is an error if any of the index values are out of bounds.
|
57
65
|
### Outputs
|
58
66
|
- **output** (heterogeneous) - **T**:
|
59
67
|
Tensor of rank q + (r - 1).
|
60
68
|
### Type Constraints
|
61
|
-
* **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) ):
|
69
|
+
* **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) ):
|
62
70
|
Constrain input and output types to any tensor type.
|
63
71
|
* **Tind** in ( tensor(int32), tensor(int64) ):
|
64
72
|
Constrain indices to integer types
|