Scatter#
Scatter - 11#
Version
name: Scatter (GitHub)
domain: main
since_version: 11
function: False
support_level: SupportType.COMMON
shape inference: True
This version of the operator has been deprecated since version 11.
Summary
This operator is deprecated. Please use ScatterElements, which provides the same functionality.
Scatter takes three inputs data, updates, and indices of the same rank r >= 1 and an optional attribute axis that identifies an axis of data (by default, the outer-most axis, that is axis 0). The output of the operation is produced by creating a copy of the input data, and then updating its value to values specified by updates at specific index positions specified by indices. Its output shape is the same as the shape of data.
For each entry in updates, the target index in data is obtained by combining the corresponding entry in indices with the index of the entry itself: the index-value for dimension = axis is obtained from the value of the corresponding entry in indices and the index-value for dimension != axis is obtained from the index of the entry itself.
For instance, in a 2-D tensor case, the update corresponding to the [i][j] entry is performed as below:
output[indices[i][j]][j] = updates[i][j] if axis = 0,
output[i][indices[i][j]] = updates[i][j] if axis = 1,
This operator is the inverse of GatherElements. It is similar to Torch’s Scatter operation.
Example 1:
data = [
[0.0, 0.0, 0.0],
[0.0, 0.0, 0.0],
[0.0, 0.0, 0.0],
]
indices = [
[1, 0, 2],
[0, 2, 1],
]
updates = [
[1.0, 1.1, 1.2],
[2.0, 2.1, 2.2],
]
output = [
[2.0, 1.1, 0.0]
[1.0, 0.0, 2.2]
[0.0, 2.1, 1.2]
]
Example 2:
data = [[1.0, 2.0, 3.0, 4.0, 5.0]]
indices = [[1, 3]]
updates = [[1.1, 2.1]]
axis = 1
output = [[1.0, 1.1, 3.0, 2.1, 5.0]]
Attributes
axis: Which axis to scatter on. Negative value means counting dimensions from the back. Accepted range is [-r, r-1] where r = rank(data). Default value is
0
.
Inputs
data (heterogeneous) - T: Tensor of rank r >= 1.
indices (heterogeneous) - Tind: Tensor of int32/int64 indices, of r >= 1 (same rank as input). 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.
updates (heterogeneous) - T: Tensor of rank r >=1 (same rank and shape as indices)
Outputs
output (heterogeneous) - T: Tensor of rank r >= 1 (same rank as input).
Type Constraints
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) ): Input and output types can be of any tensor type.
Tind in ( tensor(int32), tensor(int64) ): Constrain indices to integer types
Examples
scatter_without_axis
node = onnx.helper.make_node(
'Scatter',
inputs=['data', 'indices', 'updates'],
outputs=['y'],
)
data = np.zeros((3, 3), dtype=np.float32)
indices = np.array([[1, 0, 2], [0, 2, 1]], dtype=np.int64)
updates = np.array([[1.0, 1.1, 1.2], [2.0, 2.1, 2.2]], dtype=np.float32)
y = scatter(data, indices, updates)
# print(y) produces
# [[2.0, 1.1, 0.0],
# [1.0, 0.0, 2.2],
# [0.0, 2.1, 1.2]]
expect(node, inputs=[data, indices, updates], outputs=[y],
name='test_scatter_without_axis', opset_imports=[helper.make_opsetid("", 10)])
scatter_with_axis
axis = 1
node = onnx.helper.make_node(
'Scatter',
inputs=['data', 'indices', 'updates'],
outputs=['y'],
axis=axis,
)
data = np.array([[1.0, 2.0, 3.0, 4.0, 5.0]], dtype=np.float32)
indices = np.array([[1, 3]], dtype=np.int64)
updates = np.array([[1.1, 2.1]], dtype=np.float32)
y = scatter(data, indices, updates, axis=axis)
# print(y) produces
# [[1.0, 1.1, 3.0, 2.1, 5.0]]
expect(node, inputs=[data, indices, updates], outputs=[y],
name='test_scatter_with_axis', opset_imports=[helper.make_opsetid("", 10)])
Differences
0 | Given data, updates and indices input tensors of rank r >= 1, write the values provided by updates | ||
0 | This operator is deprecated. Please use ScatterElements, which provides the same functionality. | ||
1 |
| ||
2 | Scatter takes three inputs data, updates, and indices of the same | ||
3 | rank r >= 1 and an optional attribute axis that identifies an axis of data | ||
4 | (by default, the outer-most axis, that is axis 0). The output of the operation | ||
5 | is produced by creating a copy of the input data, and then updating its value | ||
6 | to values specified by updates at specific index positions specified by | ||
1 | 7 | into the first input, data, along axis dimension of data (by default outer-most one as axis=0) at corresponding indices. |
|
8 |
| ||
2 | 9 | For each entry in updates, the target index in data is specified by corresponding entry in indices |
|
10 | the corresponding entry in indices with the index of the entry itself: the | ||
11 | index-value for dimension = axis is obtained from the value of the corresponding | ||
3 | 12 | for dimension = axis, and index in source for dimension != axis. For instance, in a 2-D tensor case, |
|
4 | 13 | data[indices[i][j]][j] = updates[i][j] if axis = 0, or data[i][indices[i][j]] = updates[i][j] if axis = 1, |
|
14 |
| ||
15 | For instance, in a 2-D tensor case, the update corresponding to the [i][j] entry | ||
5 | 16 | where i and j are loop counters from 0 up to the respective size in updates - 1. |
|
17 | :: | ||
18 |
| ||
6 | 19 | Example 1: |
|
7 | data = [ | ||
8 | 20 | [0.0, 0.0, 0.0], |
|
21 |
| ||
9 | 22 | [0.0, 0.0, 0.0], |
|
23 |
| ||
24 | Example 1: | ||
25 | :: | ||
26 |
| ||
27 | data = [ | ||
10 | 28 | [0.0, 0.0, 0.0], |
|
11 | ] | ||
29 | [0.0, 0.0, 0.0], | ||
30 | [0.0, 0.0, 0.0], | ||
31 | ] | ||
12 | 32 | indices = [ |
|
13 | 33 | [1, 0, 2], |
|
14 | 34 | [0, 2, 1], |
|
15 | ] | ||
35 | ] | ||
16 | 36 | updates = [ |
|
17 | 37 | [1.0, 1.1, 1.2], |
|
18 | 38 | [2.0, 2.1, 2.2], |
|
19 | ] | ||
39 | ] | ||
20 | 40 | output = [ |
|
21 | 41 | [2.0, 1.1, 0.0] |
|
22 | 42 | [1.0, 0.0, 2.2] |
|
23 | 43 | [0.0, 2.1, 1.2] |
|
24 | ] | ||
44 | ] | ||
45 |
| ||
25 | 46 | Example 2: | Example 2: |
47 | :: | ||
48 |
| ||
26 | 49 | data = [[1.0, 2.0, 3.0, 4.0, 5.0]] |
|
27 | 50 | indices = [[1, 3]] |
|
28 | 51 | updates = [[1.1, 2.1]] |
|
29 | 52 | axis = 1 |
|
30 | 53 | output = [[1.0, 1.1, 3.0, 2.1, 5.0]] |
|
31 | 54 |
|
|
32 | 55 | **Attributes** | **Attributes** |
33 | 56 |
|
|
34 | 57 | * **axis**: | * **axis**: |
35 | 58 | Which axis to scatter on. Negative value means counting dimensions | Which axis to scatter on. Negative value means counting dimensions |
36 | 59 | from the back. Accepted range is [-r, r-1] Default value is 0. |
|
37 | 60 |
|
|
38 | 61 | **Inputs** | **Inputs** |
39 | 62 |
|
|
40 | 63 | * **data** (heterogeneous) - **T**: | * **data** (heterogeneous) - **T**: |
41 | 64 | Tensor of rank r >= 1. | Tensor of rank r >= 1. |
42 | 65 | * **indices** (heterogeneous) - **Tind**: | * **indices** (heterogeneous) - **Tind**: |
43 | 66 | Tensor of int32/int64 indices, of r >= 1 (same rank as input). |
|
67 | index values are expected to be within bounds [-s, s-1] along axis | ||
68 | of size s. It is an error if any of the index values are out of | ||
69 | bounds. | ||
44 | 70 | * **updates** (heterogeneous) - **T**: | * **updates** (heterogeneous) - **T**: |
45 | 71 | Tensor of rank r >=1 (same rank and shape as indices) | Tensor of rank r >=1 (same rank and shape as indices) |
46 | 72 |
|
|
47 | 73 | **Outputs** | **Outputs** |
48 | 74 |
|
|
49 | 75 | * **output** (heterogeneous) - **T**: | * **output** (heterogeneous) - **T**: |
50 | 76 | Tensor of rank r >= 1 (same rank as input). | Tensor of rank r >= 1 (same rank as input). |
51 | 77 |
|
|
52 | 78 | **Type Constraints** | **Type Constraints** |
53 | 79 |
|
|
54 | 80 | * **T** in ( | * **T** in ( |
55 | 81 | tensor(bool), | tensor(bool), |
56 | 82 | tensor(complex128), | tensor(complex128), |
57 | 83 | tensor(complex64), | tensor(complex64), |
58 | 84 | tensor(double), | tensor(double), |
59 | 85 | tensor(float), | tensor(float), |
60 | 86 | tensor(float16), | tensor(float16), |
61 | 87 | tensor(int16), | tensor(int16), |
62 | 88 | tensor(int32), | tensor(int32), |
63 | 89 | tensor(int64), | tensor(int64), |
64 | 90 | tensor(int8), | tensor(int8), |
65 | 91 | tensor(string), | tensor(string), |
66 | 92 | tensor(uint16), | tensor(uint16), |
67 | 93 | tensor(uint32), | tensor(uint32), |
68 | 94 | tensor(uint64), | tensor(uint64), |
69 | 95 | tensor(uint8) | tensor(uint8) |
70 | 96 | ): | ): |
71 | 97 | Input and output types can be of any tensor type. | Input and output types can be of any tensor type. |
72 | 98 | * **Tind** in ( | * **Tind** in ( |
73 | 99 | tensor(int32), | tensor(int32), |
74 | 100 | tensor(int64) | tensor(int64) |
75 | 101 | ): | ): |
76 | 102 | Constrain indices to integer types | Constrain indices to integer types |
Scatter - 9#
Version
name: Scatter (GitHub)
domain: main
since_version: 9
function: False
support_level: SupportType.COMMON
shape inference: True
This version of the operator has been available since version 9.
Summary
Given data, updates and indices input tensors of rank r >= 1, write the values provided by updates into the first input, data, along axis dimension of data (by default outer-most one as axis=0) at corresponding indices. For each entry in updates, the target index in data is specified by corresponding entry in indices for dimension = axis, and index in source for dimension != axis. For instance, in a 2-D tensor case, data[indices[i][j]][j] = updates[i][j] if axis = 0, or data[i][indices[i][j]] = updates[i][j] if axis = 1, where i and j are loop counters from 0 up to the respective size in updates - 1. Example 1:
- data = [
[0.0, 0.0, 0.0], [0.0, 0.0, 0.0], [0.0, 0.0, 0.0],
] indices = [
[1, 0, 2], [0, 2, 1],
] updates = [
[1.0, 1.1, 1.2], [2.0, 2.1, 2.2],
] output = [
[2.0, 1.1, 0.0] [1.0, 0.0, 2.2] [0.0, 2.1, 1.2]
]
- Example 2:
data = [[1.0, 2.0, 3.0, 4.0, 5.0]] indices = [[1, 3]] updates = [[1.1, 2.1]] axis = 1 output = [[1.0, 1.1, 3.0, 2.1, 5.0]]
Attributes
axis: Which axis to scatter on. Negative value means counting dimensions from the back. Accepted range is [-r, r-1] Default value is
0
.
Inputs
data (heterogeneous) - T: Tensor of rank r >= 1.
indices (heterogeneous) - Tind: Tensor of int32/int64 indices, of r >= 1 (same rank as input).
updates (heterogeneous) - T: Tensor of rank r >=1 (same rank and shape as indices)
Outputs
output (heterogeneous) - T: Tensor of rank r >= 1 (same rank as input).
Type Constraints
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) ): Input and output types can be of any tensor type.
Tind in ( tensor(int32), tensor(int64) ): Constrain indices to integer types