ScatterElements¶
ScatterElements - 18¶
版本¶
域:
main
起始版本:
18
函数:
False
支持级别:
SupportType.COMMON
形状推断:
True
此版本的算子自 版本 18 起可用。
摘要¶
ScatterElements 接收三个输入 data
、updates
和 indices
,它们的秩 r >= 1 相同,以及一个可选属性 axis,该属性标识 data
的一个轴(默认情况下为最外层轴,即轴 0)。操作的输出是通过创建输入 data
的副本,然后根据 indices
中指定的特定索引位置,将其值更新为 updates
中指定的值而产生的。其输出形状与 data
的形状相同。
对于 updates
中的每个条目,通过将 indices
中的相应条目与条目自身的索引相结合来获得 data
中的目标索引:维度 = axis 的索引值来自 indices
中相应条目的值,而维度 != axis 的索引值来自条目自身的索引。
reduction
允许指定一个可选的归约操作,该操作将应用于 updates
张量中的所有值到 output
中指定的 indices
位置。在 reduction
设置为“none”的情况下,indices 不应包含重复条目:也就是说,如果 idx1 != idx2,则 indices[idx1] != indices[idx2]。例如,在二维张量的情况下,对应于 [i][j] 条目的更新执行如下:
output[indices[i][j]][j] = updates[i][j] if axis = 0,
output[i][indices[i][j]] = updates[i][j] if axis = 1,
当 reduction
设置为某个归约函数 f
时,对应于 [i][j] 条目的更新执行如下:
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,
其中 f
是指定的 +
、*
、max
或 min
。
此算子是 GatherElements 的逆操作。它类似于 Torch 的 Scatter 操作。
(Opset 18 变更):在允许的归约操作集合中添加了 max/min。
示例 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]
]
示例 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]]
属性¶
axis - INT (默认值为
'0'
)要在其上执行分散的轴。负值表示从后往前计算维度。可接受范围是 [-r, r-1],其中 r = rank(data)。
reduction - STRING (默认值为
'none'
)要应用的归约类型:none (默认), add, mul, max, min。“none”:不应用归约。“add”:使用加法操作进行归约。“mul”:使用乘法操作进行归约。“max”:使用最大值操作进行归约。“min”:使用最小值操作进行归约。
输入¶
data (异构) - T
秩 r >= 1 的张量。
indices (异构) - Tind
int32/int64 索引张量,秩 r >= 1 (与输入具有相同的秩)。所有索引值应在大小为 s 的轴上的边界 [-s, s-1] 范围内。如果任何索引值超出范围,则为错误。
updates (异构) - T
秩 r >=1 的张量 (与 indices 具有相同的秩和形状)
输出¶
output (异构) - T
秩 r >= 1 的张量 (与输入具有相同的秩)。
类型约束¶
T 在 (
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)
) 中输入和输出类型可以是任何张量类型。
Tind 在 (
tensor(int32)
,tensor(int64)
) 中将 indices 限制为整数类型
ScatterElements - 16¶
版本¶
域:
main
起始版本:
16
函数:
False
支持级别:
SupportType.COMMON
形状推断:
True
此版本的算子自 版本 16 起可用。
摘要¶
ScatterElements 接收三个输入 data
、updates
和 indices
,它们的秩 r >= 1 相同,以及一个可选属性 axis,该属性标识 data
的一个轴(默认情况下为最外层轴,即轴 0)。操作的输出是通过创建输入 data
的副本,然后根据 indices
中指定的特定索引位置,将其值更新为 updates
中指定的值而产生的。其输出形状与 data
的形状相同。对于 updates
中的每个条目,通过将 indices
中的相应条目与条目自身的索引相结合来获得 data
中的目标索引:维度 = axis 的索引值来自 indices
中相应条目的值,而维度 != axis 的索引值来自条目自身的索引。reduction
允许指定一个可选的归约操作,该操作将应用于 updates
张量中的所有值到 output
中指定的 indices
位置。在 reduction
设置为“none”的情况下,indices 不应包含重复条目:也就是说,如果 idx1 != idx2,则 indices[idx1] != indices[idx2]。例如,在二维张量的情况下,对应于 [i][j] 条目的更新执行如下:
output[indices[i][j]][j] = updates[i][j] if axis = 0,
output[i][indices[i][j]] = updates[i][j] if axis = 1,
当 reduction
设置为“add”时,对应于 [i][j] 条目的更新执行如下:
output[indices[i][j]][j] += updates[i][j] if axis = 0,
output[i][indices[i][j]] += updates[i][j] if axis = 1,
当 reduction
设置为“mul”时,对应于 [i][j] 条目的更新执行如下:
output[indices[i][j]][j] *= updates[i][j] if axis = 0,
output[i][indices[i][j]] *= updates[i][j] if axis = 1,
此算子是 GatherElements 的逆操作。它类似于 Torch 的 Scatter 操作。示例 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]
]
示例 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]]
属性¶
axis - INT (默认值为
'0'
)要在其上执行分散的轴。负值表示从后往前计算维度。可接受范围是 [-r, r-1],其中 r = rank(data)。
reduction - STRING (默认值为
'none'
)要应用的归约类型:none (默认), add, mul。“none”:不应用归约。“add”:使用加法操作进行归约。“mul”:使用乘法操作进行归约。
输入¶
data (异构) - T
秩 r >= 1 的张量。
indices (异构) - Tind
int32/int64 索引张量,秩 r >= 1 (与输入具有相同的秩)。所有索引值应在大小为 s 的轴上的边界 [-s, s-1] 范围内。如果任何索引值超出范围,则为错误。
updates (异构) - T
秩 r >=1 的张量 (与 indices 具有相同的秩和形状)
输出¶
output (异构) - T
秩 r >= 1 的张量 (与输入具有相同的秩)。
类型约束¶
T 在 (
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)
) 中输入和输出类型可以是任何张量类型。
Tind 在 (
tensor(int32)
,tensor(int64)
) 中将 indices 限制为整数类型
ScatterElements - 13¶
版本¶
域:
main
起始版本:
13
函数:
False
支持级别:
SupportType.COMMON
形状推断:
True
此版本的算子自 版本 13 起可用。
摘要¶
ScatterElements 接收三个输入 data
、updates
和 indices
,它们的秩 r >= 1 相同,以及一个可选属性 axis,该属性标识 data
的一个轴(默认情况下为最外层轴,即轴 0)。操作的输出是通过创建输入 data
的副本,然后根据 indices
中指定的特定索引位置,将其值更新为 updates
中指定的值而产生的。其输出形状与 data
的形状相同。
对于 updates
中的每个条目,通过将 indices
中的相应条目与条目自身的索引相结合来获得 data
中的目标索引:维度 = axis 的索引值来自 indices
中相应条目的值,而维度 != axis 的索引值来自条目自身的索引。
例如,在二维张量的情况下,对应于 [i][j] 条目的更新执行如下:
output[indices[i][j]][j] = updates[i][j] if axis = 0,
output[i][indices[i][j]] = updates[i][j] if axis = 1,
此算子是 GatherElements 的逆操作。它类似于 Torch 的 Scatter 操作。
示例 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]
]
示例 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]]
属性¶
axis - INT (默认值为
'0'
)要在其上执行分散的轴。负值表示从后往前计算维度。可接受范围是 [-r, r-1],其中 r = rank(data)。
输入¶
data (异构) - T
秩 r >= 1 的张量。
indices (异构) - Tind
int32/int64 索引张量,秩 r >= 1 (与输入具有相同的秩)。所有索引值应在大小为 s 的轴上的边界 [-s, s-1] 范围内。如果任何索引值超出范围,则为错误。
updates (异构) - T
秩 r >=1 的张量 (与 indices 具有相同的秩和形状)
输出¶
output (异构) - T
秩 r >= 1 的张量 (与输入具有相同的秩)。
类型约束¶
T 在 (
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)
) 中输入和输出类型可以是任何张量类型。
Tind 在 (
tensor(int32)
,tensor(int64)
) 中将 indices 限制为整数类型
ScatterElements - 11¶
版本¶
域:
main
起始版本:
11
函数:
False
支持级别:
SupportType.COMMON
形状推断:
True
此版本的算子自 版本 11 起可用。
摘要¶
ScatterElements 接收三个输入 data
、updates
和 indices
,它们的秩 r >= 1 相同,以及一个可选属性 axis,该属性标识 data
的一个轴(默认情况下为最外层轴,即轴 0)。操作的输出是通过创建输入 data
的副本,然后根据 indices
中指定的特定索引位置,将其值更新为 updates
中指定的值而产生的。其输出形状与 data
的形状相同。
对于 updates
中的每个条目,通过将 indices
中的相应条目与条目自身的索引相结合来获得 data
中的目标索引:维度 = axis 的索引值来自 indices
中相应条目的值,而维度 != axis 的索引值来自条目自身的索引。
例如,在二维张量的情况下,对应于 [i][j] 条目的更新执行如下:
output[indices[i][j]][j] = updates[i][j] if axis = 0,
output[i][indices[i][j]] = updates[i][j] if axis = 1,
此算子是 GatherElements 的逆操作。它类似于 Torch 的 Scatter 操作。
示例 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]
]
示例 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]]
属性¶
axis - INT (默认值为
'0'
)要在其上执行分散的轴。负值表示从后往前计算维度。可接受范围是 [-r, r-1],其中 r = rank(data)。
输入¶
data (异构) - T
秩 r >= 1 的张量。
indices (异构) - Tind
int32/int64 索引张量,秩 r >= 1 (与输入具有相同的秩)。所有索引值应在大小为 s 的轴上的边界 [-s, s-1] 范围内。如果任何索引值超出范围,则为错误。
updates (异构) - T
秩 r >=1 的张量 (与 indices 具有相同的秩和形状)
输出¶
output (异构) - T
秩 r >= 1 的张量 (与输入具有相同的秩)。
类型约束¶
T 在 (
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)
) 中输入和输出类型可以是任何张量类型。
Tind 在 (
tensor(int32)
,tensor(int64)
) 中将 indices 限制为整数类型