.. _l-onnx-doc-ScatterElements: =============== ScatterElements =============== .. contents:: :local: .. _l-onnx-op-scatterelements-18: ScatterElements - 18 ==================== **Version** * **name**: `ScatterElements (GitHub) `_ * **domain**: **main** * **since_version**: **18** * **function**: False * **support_level**: SupportType.COMMON * **shape inference**: True This version of the operator has been available **since version 18**. **Summary** ScatterElements 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. `reduction` allows specification of an optional reduction operation, which is applied to all values in `updates` tensor into `output` at the specified `indices`. In cases where `reduction` is set to "none", indices should not have duplicate entries: that is, if idx1 != idx2, then indices[idx1] != indices[idx2]. 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, When `reduction` is set to some reduction function `f`, the update corresponding to the [i][j] entry is performed as below: :: output[indices[i][j]][j] += f(output[indices[i][j]][j], updates[i][j]) if axis = 0, output[i][indices[i][j]] += f(output[i][indices[i][j]], updates[i][j]) if axis = 1, where the `f` is +/*/max/min as specified. This operator is the inverse of GatherElements. It is similar to Torch's Scatter operation. (Opset 18 change): Adds max/min to the set of allowed reduction ops. 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``. * **reduction**: Type of reduction to apply: none (default), add, mul, max, min. 'none': no reduction applied. 'add': reduction using the addition operation. 'mul': reduction using the multiplication operation.'max': reduction using the maximum operation.'min': reduction using the minimum operation. Default value is ``'none'``. **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(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) ): Input and output types can be of any tensor type. * **Tind** in ( tensor(int32), tensor(int64) ): Constrain indices to integer types **Examples** **_scatter_elements_without_axis** :: node = onnx.helper.make_node( "ScatterElements", 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_elements(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_elements_without_axis", ) **_scatter_elements_with_axis** :: axis = 1 node = onnx.helper.make_node( "ScatterElements", 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_elements(data, indices, updates, 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_elements_with_axis", ) **_scatter_elements_with_negative_indices** :: axis = 1 node = onnx.helper.make_node( "ScatterElements", 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_elements(data, indices, updates, axis) # print(y) produces # [[1.0, 1.1, 2.1, 4.0, 5.0]] expect( node, inputs=[data, indices, updates], outputs=[y], name="test_scatter_elements_with_negative_indices", ) **_scatter_elements_with_duplicate_indices** :: axis = 1 node = onnx.helper.make_node( "ScatterElements", inputs=["data", "indices", "updates"], outputs=["y"], axis=axis, reduction="add", ) data = np.array([[1.0, 2.0, 3.0, 4.0, 5.0]], dtype=np.float32) indices = np.array([[1, 1]], dtype=np.int64) updates = np.array([[1.1, 2.1]], dtype=np.float32) y = scatter_elements(data, indices, updates, axis, reduction="add") # print(y) produces # [[1.0, 5.2, 3.0, 4.0, 5.0]] expect( node, inputs=[data, indices, updates], outputs=[y], name="test_scatter_elements_with_duplicate_indices", ) **_scatter_elements_with_reduction_max** :: axis = 1 node = onnx.helper.make_node( "ScatterElements", inputs=["data", "indices", "updates"], outputs=["y"], axis=axis, reduction="max", ) data = np.array([[1.0, 2.0, 3.0, 4.0, 5.0]], dtype=np.float32) indices = np.array([[1, 1]], dtype=np.int64) updates = np.array([[1.1, 2.1]], dtype=np.float32) y = scatter_elements(data, indices, updates, axis, reduction="max") # print(y) produces # [[1.0, 2.1, 3.0, 4.0, 5.0]] expect( node, inputs=[data, indices, updates], outputs=[y], name="test_scatter_elements_with_reduction_max", ) **_scatter_elements_with_reduction_min** :: axis = 1 node = onnx.helper.make_node( "ScatterElements", inputs=["data", "indices", "updates"], outputs=["y"], axis=axis, reduction="min", ) data = np.array([[1.0, 2.0, 3.0, 4.0, 5.0]], dtype=np.float32) indices = np.array([[1, 1]], dtype=np.int64) updates = np.array([[1.1, 2.1]], dtype=np.float32) y = scatter_elements(data, indices, updates, axis, reduction="min") # print(y) produces # [[1.0, 1.1, 3.0, 4.0, 5.0]] expect( node, inputs=[data, indices, updates], outputs=[y], name="test_scatter_elements_with_reduction_min", ) **Differences** .. raw:: html
00ScatterElements takes three inputs data, updates, and indices of the sameScatterElements takes three inputs data, updates, and indices of the same
11rank r >= 1 and an optional attribute axis that identifies an axis of datarank r >= 1 and an optional attribute axis that identifies an axis of data
22(by default, the outer-most axis, that is axis 0). The output of the operation(by default, the outer-most axis, that is axis 0). The output of the operation
33is produced by creating a copy of the input data, and then updating its valueis produced by creating a copy of the input data, and then updating its value
44to values specified by updates at specific index positions specified byto values specified by updates at specific index positions specified by
55indices. Its output shape is the same as the shape of data.indices. Its output shape is the same as the shape of data.
6
67For each entry in updates, the target index in data is obtained by combiningFor each entry in updates, the target index in data is obtained by combining
78the corresponding entry in indices with the index of the entry itself: thethe corresponding entry in indices with the index of the entry itself: the
89index-value for dimension = axis is obtained from the value of the correspondingindex-value for dimension = axis is obtained from the value of the corresponding
910entry in indices and the index-value for dimension != axis is obtained from theentry in indices and the index-value for dimension != axis is obtained from the
1011index of the entry itself.index of the entry itself.
12
1113reduction allows specification of an optional reduction operation, which is applied to all values in updatesreduction allows specification of an optional reduction operation, which is applied to all values in updates
1214tensor into output at the specified indices.tensor into output at the specified indices.
1315In cases where reduction is set to "none", indices should not have duplicate entries: that is, if idx1 != idx2,In cases where reduction is set to "none", indices should not have duplicate entries: that is, if idx1 != idx2,
1416then indices[idx1] != indices[idx2]. For instance, in a 2-D tensor case, the updatethen indices[idx1] != indices[idx2]. For instance, in a 2-D tensor case, the update
1517corresponding to the [i][j] entry is performed as below:corresponding to the [i][j] entry is performed as below:
1618::::
1719
1820 output[indices[i][j]][j] = updates[i][j] if axis = 0, output[indices[i][j]][j] = updates[i][j] if axis = 0,
1921 output[i][indices[i][j]] = updates[i][j] if axis = 1, output[i][indices[i][j]] = updates[i][j] if axis = 1,
2022
2123When reduction is set to "add", the update corresponding to the [i][j] entry is performed as below:When reduction is set to some reduction function f, the update corresponding to the [i][j] entry is performed as below:
2224::::
2325
2426 output[indices[i][j]][j] += updates[i][j] if axis = 0, output[indices[i][j]][j] += f(output[indices[i][j]][j], updates[i][j]) if axis = 0,
2527 output[i][indices[i][j]] += updates[i][j] if axis = 1, output[i][indices[i][j]] += f(output[i][indices[i][j]], updates[i][j]) if axis = 1,
2628
2729When reduction is set to "mul", the update corresponding to the [i][j] entry is performed as below:where the f is +/*/max/min as specified.
28::
2930
30 output[indices[i][j]][j] *= updates[i][j] if axis = 0,
31 output[i][indices[i][j]] *= updates[i][j] if axis = 1,
32
3331This operator is the inverse of GatherElements. It is similar to Torch's Scatter operation.This operator is the inverse of GatherElements. It is similar to Torch's Scatter operation.
32
33(Opset 18 change): Adds max/min to the set of allowed reduction ops.
34
3435Example 1:Example 1:
3536::::
3637
3738 data = [ data = [
3839 [0.0, 0.0, 0.0], [0.0, 0.0, 0.0],
3940 [0.0, 0.0, 0.0], [0.0, 0.0, 0.0],
4041 [0.0, 0.0, 0.0], [0.0, 0.0, 0.0],
4142 ] ]
4243 indices = [ indices = [
4344 [1, 0, 2], [1, 0, 2],
4445 [0, 2, 1], [0, 2, 1],
4546 ] ]
4647 updates = [ updates = [
4748 [1.0, 1.1, 1.2], [1.0, 1.1, 1.2],
4849 [2.0, 2.1, 2.2], [2.0, 2.1, 2.2],
4950 ] ]
5051 output = [ output = [
5152 [2.0, 1.1, 0.0] [2.0, 1.1, 0.0]
5253 [1.0, 0.0, 2.2] [1.0, 0.0, 2.2]
5354 [0.0, 2.1, 1.2] [0.0, 2.1, 1.2]
5455 ] ]
5556
5657Example 2:Example 2:
5758::::
5859
5960 data = [[1.0, 2.0, 3.0, 4.0, 5.0]] data = [[1.0, 2.0, 3.0, 4.0, 5.0]]
6061 indices = [[1, 3]] indices = [[1, 3]]
6162 updates = [[1.1, 2.1]] updates = [[1.1, 2.1]]
6263 axis = 1 axis = 1
6364 output = [[1.0, 1.1, 3.0, 2.1, 5.0]] output = [[1.0, 1.1, 3.0, 2.1, 5.0]]
6465
6566**Attributes****Attributes**
6667
6768* **axis**:* **axis**:
6869 Which axis to scatter on. Negative value means counting dimensions Which axis to scatter on. Negative value means counting dimensions
6970 from the back. Accepted range is [-r, r-1] where r = rank(data). Default value is 0. from the back. Accepted range is [-r, r-1] where r = rank(data). Default value is 0.
7071* **reduction**:* **reduction**:
7172 Type of reduction to apply: none (default), add, mul. 'none': no Type of reduction to apply: none (default), add, mul, max, min.
7273 reduction applied. 'add': reduction using the addition operation. 'none': no reduction applied. 'add': reduction using the addition
74 operation. 'mul': reduction using the multiplication
75 operation.'max': reduction using the maximum operation.'min':
7376 'mul': reduction using the multiplication operation. Default value is 'none'. reduction using the minimum operation. Default value is 'none'.
7477
7578**Inputs****Inputs**
7679
7780* **data** (heterogeneous) - **T**:* **data** (heterogeneous) - **T**:
7881 Tensor of rank r >= 1. Tensor of rank r >= 1.
7982* **indices** (heterogeneous) - **Tind**:* **indices** (heterogeneous) - **Tind**:
8083 Tensor of int32/int64 indices, of r >= 1 (same rank as input). All Tensor of int32/int64 indices, of r >= 1 (same rank as input). All
8184 index values are expected to be within bounds [-s, s-1] along axis index values are expected to be within bounds [-s, s-1] along axis
8285 of size s. It is an error if any of the index values are out of of size s. It is an error if any of the index values are out of
8386 bounds. bounds.
8487* **updates** (heterogeneous) - **T**:* **updates** (heterogeneous) - **T**:
8588 Tensor of rank r >=1 (same rank and shape as indices) Tensor of rank r >=1 (same rank and shape as indices)
8689
8790**Outputs****Outputs**
8891
8992* **output** (heterogeneous) - **T**:* **output** (heterogeneous) - **T**:
9093 Tensor of rank r >= 1 (same rank as input). Tensor of rank r >= 1 (same rank as input).
9194
9295**Type Constraints****Type Constraints**
9396
9497* **T** in (* **T** in (
9598 tensor(bfloat16), tensor(bfloat16),
9699 tensor(bool), tensor(bool),
97100 tensor(complex128), tensor(complex128),
98101 tensor(complex64), tensor(complex64),
99102 tensor(double), tensor(double),
100103 tensor(float), tensor(float),
101104 tensor(float16), tensor(float16),
102105 tensor(int16), tensor(int16),
103106 tensor(int32), tensor(int32),
104107 tensor(int64), tensor(int64),
105108 tensor(int8), tensor(int8),
106109 tensor(string), tensor(string),
107110 tensor(uint16), tensor(uint16),
108111 tensor(uint32), tensor(uint32),
109112 tensor(uint64), tensor(uint64),
110113 tensor(uint8) tensor(uint8)
111114 ): ):
112115 Input and output types can be of any tensor type. Input and output types can be of any tensor type.
113116* **Tind** in (* **Tind** in (
114117 tensor(int32), tensor(int32),
115118 tensor(int64) tensor(int64)
116119 ): ):
117120 Constrain indices to integer types Constrain indices to integer types
.. _l-onnx-op-scatterelements-16: ScatterElements - 16 ==================== **Version** * **name**: `ScatterElements (GitHub) `_ * **domain**: **main** * **since_version**: **16** * **function**: False * **support_level**: SupportType.COMMON * **shape inference**: True This version of the operator has been available **since version 16**. **Summary** ScatterElements 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. `reduction` allows specification of an optional reduction operation, which is applied to all values in `updates` tensor into `output` at the specified `indices`. In cases where `reduction` is set to "none", indices should not have duplicate entries: that is, if idx1 != idx2, then indices[idx1] != indices[idx2]. 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, When `reduction` is set to "add", 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, When `reduction` is set to "mul", 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``. * **reduction**: Type of reduction to apply: none (default), add, mul. 'none': no reduction applied. 'add': reduction using the addition operation. 'mul': reduction using the multiplication operation. Default value is ``'none'``. **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(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) ): Input and output types can be of any tensor type. * **Tind** in ( tensor(int32), tensor(int64) ): Constrain indices to integer types **Differences** .. raw:: html
00ScatterElements takes three inputs data, updates, and indices of the sameScatterElements takes three inputs data, updates, and indices of the same
11rank r >= 1 and an optional attribute axis that identifies an axis of datarank r >= 1 and an optional attribute axis that identifies an axis of data
22(by default, the outer-most axis, that is axis 0). The output of the operation(by default, the outer-most axis, that is axis 0). The output of the operation
33is produced by creating a copy of the input data, and then updating its valueis produced by creating a copy of the input data, and then updating its value
44to values specified by updates at specific index positions specified byto values specified by updates at specific index positions specified by
55indices. Its output shape is the same as the shape of data.indices. Its output shape is the same as the shape of data.
6
76For each entry in updates, the target index in data is obtained by combiningFor each entry in updates, the target index in data is obtained by combining
87the corresponding entry in indices with the index of the entry itself: thethe corresponding entry in indices with the index of the entry itself: the
98index-value for dimension = axis is obtained from the value of the correspondingindex-value for dimension = axis is obtained from the value of the corresponding
109entry in indices and the index-value for dimension != axis is obtained from theentry in indices and the index-value for dimension != axis is obtained from the
1110index of the entry itself.index of the entry itself.
11reduction allows specification of an optional reduction operation, which is applied to all values in updates
12tensor into output at the specified indices.
13In cases where reduction is set to "none", indices should not have duplicate entries: that is, if idx1 != idx2,
14then indices[idx1] != indices[idx2]. For instance, in a 2-D tensor case, the update
15corresponding to the [i][j] entry is performed as below:
16::
1217
18 output[indices[i][j]][j] = updates[i][j] if axis = 0,
19 output[i][indices[i][j]] = updates[i][j] if axis = 1,
20
1321For instance, in a 2-D tensor case, the update corresponding to the [i][j] entryWhen reduction is set to "add", the update corresponding to the [i][j] entry is performed as below:
22::
23
24 output[indices[i][j]][j] += updates[i][j] if axis = 0,
25 output[i][indices[i][j]] += updates[i][j] if axis = 1,
26
1427is performed as below:When reduction is set to "mul", the update corresponding to the [i][j] entry is performed as below:
1528::::
1629
1730 output[indices[i][j]][j] = updates[i][j] if axis = 0, output[indices[i][j]][j] *= updates[i][j] if axis = 0,
1831 output[i][indices[i][j]] = updates[i][j] if axis = 1, output[i][indices[i][j]] *= updates[i][j] if axis = 1,
1932
2033This operator is the inverse of GatherElements. It is similar to Torch's Scatter operation.This operator is the inverse of GatherElements. It is similar to Torch's Scatter operation.
21
2234Example 1:Example 1:
2335::::
2436
2537 data = [ data = [
2638 [0.0, 0.0, 0.0], [0.0, 0.0, 0.0],
2739 [0.0, 0.0, 0.0], [0.0, 0.0, 0.0],
2840 [0.0, 0.0, 0.0], [0.0, 0.0, 0.0],
2941 ] ]
3042 indices = [ indices = [
3143 [1, 0, 2], [1, 0, 2],
3244 [0, 2, 1], [0, 2, 1],
3345 ] ]
3446 updates = [ updates = [
3547 [1.0, 1.1, 1.2], [1.0, 1.1, 1.2],
3648 [2.0, 2.1, 2.2], [2.0, 2.1, 2.2],
3749 ] ]
3850 output = [ output = [
3951 [2.0, 1.1, 0.0] [2.0, 1.1, 0.0]
4052 [1.0, 0.0, 2.2] [1.0, 0.0, 2.2]
4153 [0.0, 2.1, 1.2] [0.0, 2.1, 1.2]
4254 ] ]
4355
4456Example 2:Example 2:
4557::::
4658
4759 data = [[1.0, 2.0, 3.0, 4.0, 5.0]] data = [[1.0, 2.0, 3.0, 4.0, 5.0]]
4860 indices = [[1, 3]] indices = [[1, 3]]
4961 updates = [[1.1, 2.1]] updates = [[1.1, 2.1]]
5062 axis = 1 axis = 1
5163 output = [[1.0, 1.1, 3.0, 2.1, 5.0]] output = [[1.0, 1.1, 3.0, 2.1, 5.0]]
5264
5365**Attributes****Attributes**
5466
5567* **axis**:* **axis**:
5668 Which axis to scatter on. Negative value means counting dimensions Which axis to scatter on. Negative value means counting dimensions
5769 from the back. Accepted range is [-r, r-1] where r = rank(data). Default value is 0. from the back. Accepted range is [-r, r-1] where r = rank(data). Default value is 0.
70* **reduction**:
71 Type of reduction to apply: none (default), add, mul. 'none': no
72 reduction applied. 'add': reduction using the addition operation.
73 'mul': reduction using the multiplication operation. Default value is 'none'.
5874
5975**Inputs****Inputs**
6076
6177* **data** (heterogeneous) - **T**:* **data** (heterogeneous) - **T**:
6278 Tensor of rank r >= 1. Tensor of rank r >= 1.
6379* **indices** (heterogeneous) - **Tind**:* **indices** (heterogeneous) - **Tind**:
6480 Tensor of int32/int64 indices, of r >= 1 (same rank as input). All Tensor of int32/int64 indices, of r >= 1 (same rank as input). All
6581 index values are expected to be within bounds [-s, s-1] along axis index values are expected to be within bounds [-s, s-1] along axis
6682 of size s. It is an error if any of the index values are out of of size s. It is an error if any of the index values are out of
6783 bounds. bounds.
6884* **updates** (heterogeneous) - **T**:* **updates** (heterogeneous) - **T**:
6985 Tensor of rank r >=1 (same rank and shape as indices) Tensor of rank r >=1 (same rank and shape as indices)
7086
7187**Outputs****Outputs**
7288
7389* **output** (heterogeneous) - **T**:* **output** (heterogeneous) - **T**:
7490 Tensor of rank r >= 1 (same rank as input). Tensor of rank r >= 1 (same rank as input).
7591
7692**Type Constraints****Type Constraints**
7793
7894* **T** in (* **T** in (
7995 tensor(bfloat16), tensor(bfloat16),
8096 tensor(bool), tensor(bool),
8197 tensor(complex128), tensor(complex128),
8298 tensor(complex64), tensor(complex64),
8399 tensor(double), tensor(double),
84100 tensor(float), tensor(float),
85101 tensor(float16), tensor(float16),
86102 tensor(int16), tensor(int16),
87103 tensor(int32), tensor(int32),
88104 tensor(int64), tensor(int64),
89105 tensor(int8), tensor(int8),
90106 tensor(string), tensor(string),
91107 tensor(uint16), tensor(uint16),
92108 tensor(uint32), tensor(uint32),
93109 tensor(uint64), tensor(uint64),
94110 tensor(uint8) tensor(uint8)
95111 ): ):
96112 Input and output types can be of any tensor type. Input and output types can be of any tensor type.
97113* **Tind** in (* **Tind** in (
98114 tensor(int32), tensor(int32),
99115 tensor(int64) tensor(int64)
100116 ): ):
101117 Constrain indices to integer types Constrain indices to integer types
.. _l-onnx-op-scatterelements-13: ScatterElements - 13 ==================== **Version** * **name**: `ScatterElements (GitHub) `_ * **domain**: **main** * **since_version**: **13** * **function**: False * **support_level**: SupportType.COMMON * **shape inference**: True This version of the operator has been available **since version 13**. **Summary** ScatterElements 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(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) ): Input and output types can be of any tensor type. * **Tind** in ( tensor(int32), tensor(int64) ): Constrain indices to integer types **Differences** .. raw:: html
00ScatterElements takes three inputs data, updates, and indices of the sameScatterElements takes three inputs data, updates, and indices of the same
11rank r >= 1 and an optional attribute axis that identifies an axis of datarank r >= 1 and an optional attribute axis that identifies an axis of data
22(by default, the outer-most axis, that is axis 0). The output of the operation(by default, the outer-most axis, that is axis 0). The output of the operation
33is produced by creating a copy of the input data, and then updating its valueis produced by creating a copy of the input data, and then updating its value
44to values specified by updates at specific index positions specified byto values specified by updates at specific index positions specified by
55indices. Its output shape is the same as the shape of data.indices. Its output shape is the same as the shape of data.
66
77For each entry in updates, the target index in data is obtained by combiningFor each entry in updates, the target index in data is obtained by combining
88the corresponding entry in indices with the index of the entry itself: thethe corresponding entry in indices with the index of the entry itself: the
99index-value for dimension = axis is obtained from the value of the correspondingindex-value for dimension = axis is obtained from the value of the corresponding
1010entry in indices and the index-value for dimension != axis is obtained from theentry in indices and the index-value for dimension != axis is obtained from the
1111index of the entry itself.index of the entry itself.
1212
1313For instance, in a 2-D tensor case, the update corresponding to the [i][j] entryFor instance, in a 2-D tensor case, the update corresponding to the [i][j] entry
1414is performed as below:is performed as below:
1515::::
1616
1717 output[indices[i][j]][j] = updates[i][j] if axis = 0, output[indices[i][j]][j] = updates[i][j] if axis = 0,
1818 output[i][indices[i][j]] = updates[i][j] if axis = 1, output[i][indices[i][j]] = updates[i][j] if axis = 1,
1919
2020This operator is the inverse of GatherElements. It is similar to Torch's Scatter operation.This operator is the inverse of GatherElements. It is similar to Torch's Scatter operation.
2121
2222Example 1:Example 1:
2323::::
2424
2525 data = [ data = [
2626 [0.0, 0.0, 0.0], [0.0, 0.0, 0.0],
2727 [0.0, 0.0, 0.0], [0.0, 0.0, 0.0],
2828 [0.0, 0.0, 0.0], [0.0, 0.0, 0.0],
2929 ] ]
3030 indices = [ indices = [
3131 [1, 0, 2], [1, 0, 2],
3232 [0, 2, 1], [0, 2, 1],
3333 ] ]
3434 updates = [ updates = [
3535 [1.0, 1.1, 1.2], [1.0, 1.1, 1.2],
3636 [2.0, 2.1, 2.2], [2.0, 2.1, 2.2],
3737 ] ]
3838 output = [ output = [
3939 [2.0, 1.1, 0.0] [2.0, 1.1, 0.0]
4040 [1.0, 0.0, 2.2] [1.0, 0.0, 2.2]
4141 [0.0, 2.1, 1.2] [0.0, 2.1, 1.2]
4242 ] ]
4343
4444Example 2:Example 2:
4545::::
4646
4747 data = [[1.0, 2.0, 3.0, 4.0, 5.0]] data = [[1.0, 2.0, 3.0, 4.0, 5.0]]
4848 indices = [[1, 3]] indices = [[1, 3]]
4949 updates = [[1.1, 2.1]] updates = [[1.1, 2.1]]
5050 axis = 1 axis = 1
5151 output = [[1.0, 1.1, 3.0, 2.1, 5.0]] output = [[1.0, 1.1, 3.0, 2.1, 5.0]]
5252
5353**Attributes****Attributes**
5454
5555* **axis**:* **axis**:
5656 Which axis to scatter on. Negative value means counting dimensions Which axis to scatter on. Negative value means counting dimensions
5757 from the back. Accepted range is [-r, r-1] where r = rank(data). Default value is 0. from the back. Accepted range is [-r, r-1] where r = rank(data). Default value is 0.
5858
5959**Inputs****Inputs**
6060
6161* **data** (heterogeneous) - **T**:* **data** (heterogeneous) - **T**:
6262 Tensor of rank r >= 1. Tensor of rank r >= 1.
6363* **indices** (heterogeneous) - **Tind**:* **indices** (heterogeneous) - **Tind**:
6464 Tensor of int32/int64 indices, of r >= 1 (same rank as input). All Tensor of int32/int64 indices, of r >= 1 (same rank as input). All
6565 index values are expected to be within bounds [-s, s-1] along axis index values are expected to be within bounds [-s, s-1] along axis
6666 of size s. It is an error if any of the index values are out of of size s. It is an error if any of the index values are out of
6767 bounds. bounds.
6868* **updates** (heterogeneous) - **T**:* **updates** (heterogeneous) - **T**:
6969 Tensor of rank r >=1 (same rank and shape as indices) Tensor of rank r >=1 (same rank and shape as indices)
7070
7171**Outputs****Outputs**
7272
7373* **output** (heterogeneous) - **T**:* **output** (heterogeneous) - **T**:
7474 Tensor of rank r >= 1 (same rank as input). Tensor of rank r >= 1 (same rank as input).
7575
7676**Type Constraints****Type Constraints**
7777
7878* **T** in (* **T** in (
79 tensor(bfloat16),
7980 tensor(bool), tensor(bool),
8081 tensor(complex128), tensor(complex128),
8182 tensor(complex64), tensor(complex64),
8283 tensor(double), tensor(double),
8384 tensor(float), tensor(float),
8485 tensor(float16), tensor(float16),
8586 tensor(int16), tensor(int16),
8687 tensor(int32), tensor(int32),
8788 tensor(int64), tensor(int64),
8889 tensor(int8), tensor(int8),
8990 tensor(string), tensor(string),
9091 tensor(uint16), tensor(uint16),
9192 tensor(uint32), tensor(uint32),
9293 tensor(uint64), tensor(uint64),
9394 tensor(uint8) tensor(uint8)
9495 ): ):
9596 Input and output types can be of any tensor type. Input and output types can be of any tensor type.
9697* **Tind** in (* **Tind** in (
9798 tensor(int32), tensor(int32),
9899 tensor(int64) tensor(int64)
99100 ): ):
100101 Constrain indices to integer types Constrain indices to integer types
.. _l-onnx-op-scatterelements-11: ScatterElements - 11 ==================== **Version** * **name**: `ScatterElements (GitHub) `_ * **domain**: **main** * **since_version**: **11** * **function**: False * **support_level**: SupportType.COMMON * **shape inference**: True This version of the operator has been available **since version 11**. **Summary** ScatterElements 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