ScatterND¶
ScatterND - 18¶
版本¶
域:
main
起始版本:
18
函数:
False
支持级别:
SupportType.COMMON
形状推断:
True
此版本的操作符自版本 18 起可用。
摘要¶
ScatterND 接收三个输入:秩为 r >= 1 的 data
张量,秩为 q >= 1 的 indices
张量,以及秩为 q + r - indices.shape[-1] - 1 的 updates
张量。该操作通过创建输入 data
的副本,然后使用 indices
指定的特定索引位置上的 updates
值来更新它,从而产生输出。其输出形状与 data
的形状相同。
indices
是一个整数张量。令 k 表示 indices.shape[-1],即 indices
形状的最后一个维度。 indices
被视为一个 (q-1) 维的 k 元组张量,其中每个 k 元组是 data
的一个部分索引。因此,k 的值最多可以是 data
的秩。当 k 等于 rank(data) 时,每个更新条目指定对张量单个元素的更新。当 k 小于 rank(data) 时,每个更新条目指定对张量一个切片的更新。索引值允许为负数,按照通常的从末尾倒数计数的约定,但应在有效范围内。
updates
被视为一个 (q-1) 维的替换切片值张量。因此,updates.shape 的前 (q-1) 个维度必须与 indices.shape 的前 (q-1) 个维度匹配。 updates
的其余维度对应于替换切片值 values
的维度。每个替换切片值是一个 (r-k) 维张量,对应于 data
的尾部 (r-k) 维度。因此, updates
的形状必须等于 indices.shape[0:q-1] ++ data.shape[k:r-1],其中 ++ 表示形状的连接。
output
通过以下方程计算:
output = np.copy(data)
update_indices = indices.shape[:-1]
for idx in np.ndindex(update_indices):
output[indices[idx]] = updates[idx]
上述循环中的迭代顺序未指定。特别是,indices 不应有重复条目:即,如果 idx1 != idx2,则 indices[idx1] != indices[idx2]。这确保了输出值不依赖于迭代顺序。
reduction
允许指定一个可选的归约操作,该操作应用于 updates
张量中的所有值,并在指定的 indices
处应用到 output
中。当 reduction
设置为“none”时,indices 不应有重复条目:即,如果 idx1 != idx2,则 indices[idx1] != indices[idx2]。这确保了输出值不依赖于迭代顺序。当 reduction
设置为某个归约函数 f
时, output
计算如下:
output = np.copy(data)
update_indices = indices.shape[:-1]
for idx in np.ndindex(update_indices):
output[indices[idx]] = f(output[indices[idx]], updates[idx])
其中 f
是 +
, *
, max
或 min
,如指定所示。
此运算符是 GatherND 的逆运算。
(Opset 18 更改):将 max/min 添加到允许的归约操作集中。
示例 1
data = [1, 2, 3, 4, 5, 6, 7, 8]
indices = [[4], [3], [1], [7]]
updates = [9, 10, 11, 12]
output = [1, 11, 3, 10, 9, 6, 7, 12]
示例 2
data = [[[1, 2, 3, 4], [5, 6, 7, 8], [8, 7, 6, 5], [4, 3, 2, 1]],
[[1, 2, 3, 4], [5, 6, 7, 8], [8, 7, 6, 5], [4, 3, 2, 1]],
[[8, 7, 6, 5], [4, 3, 2, 1], [1, 2, 3, 4], [5, 6, 7, 8]],
[[8, 7, 6, 5], [4, 3, 2, 1], [1, 2, 3, 4], [5, 6, 7, 8]]]
indices = [[0], [2]]
updates = [[[5, 5, 5, 5], [6, 6, 6, 6], [7, 7, 7, 7], [8, 8, 8, 8]],
[[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3], [4, 4, 4, 4]]]
output = [[[5, 5, 5, 5], [6, 6, 6, 6], [7, 7, 7, 7], [8, 8, 8, 8]],
[[1, 2, 3, 4], [5, 6, 7, 8], [8, 7, 6, 5], [4, 3, 2, 1]],
[[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3], [4, 4, 4, 4]],
[[8, 7, 6, 5], [4, 3, 2, 1], [1, 2, 3, 4], [5, 6, 7, 8]]]
属性¶
reduction - STRING (默认值为
'none'
)要应用的归约类型:none (默认),add,mul,max,min。“none”:不应用归约。“add”:使用加法运算进行归约。“mul”:使用加法运算进行归约。“max”:使用最大值运算进行归约。“min”:使用最小值运算进行归约。
输入¶
data (异构) - T
秩 r >= 1 的张量。
indices (异构) - tensor(int64)
秩为 q >= 1 的张量。
updates (异构) - T
秩为 q + r - indices_shape[-1] - 1 的张量。
输出¶
输出 (异构) - 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)
) 中将输入和输出类型限制为任何张量类型。
ScatterND - 16¶
版本¶
域:
main
since_version:
16
函数:
False
支持级别:
SupportType.COMMON
形状推断:
True
此版本的运算符自 版本 16 起可用。
摘要¶
ScatterND 接收三个输入:秩为 r >= 1 的 data
张量,秩为 q >= 1 的 indices
张量,以及秩为 q + r - indices.shape[-1] - 1 的 updates
张量。该操作通过创建输入 data
的副本,然后使用 indices
指定的特定索引位置上的 updates
值来更新它,从而产生输出。其输出形状与 data
的形状相同。
indices
是一个整数张量。令 k 表示 indices.shape[-1],即 indices
形状的最后一个维度。 indices
被视为一个 (q-1) 维的 k 元组张量,其中每个 k 元组是 data
的一个部分索引。因此,k 的值最多可以是 data
的秩。当 k 等于 rank(data) 时,每个更新条目指定对张量单个元素的更新。当 k 小于 rank(data) 时,每个更新条目指定对张量一个切片的更新。索引值允许为负数,按照通常的从末尾倒数计数的约定,但应在有效范围内。
updates
被视为一个 (q-1) 维的替换切片值张量。因此,updates.shape 的前 (q-1) 个维度必须与 indices.shape 的前 (q-1) 个维度匹配。 updates
的其余维度对应于替换切片值 values
的维度。每个替换切片值是一个 (r-k) 维张量,对应于 data
的尾部 (r-k) 维度。因此, updates
的形状必须等于 indices.shape[0:q-1] ++ data.shape[k:r-1],其中 ++ 表示形状的连接。
output
通过以下方程计算: output = np.copy(data) update_indices = indices.shape[:-1] for idx in np.ndindex(update_indices): output[indices[idx]] = updates[idx] 上述循环中的迭代顺序未指定。特别是,indices 不应有重复条目:即,如果 idx1 != idx2,则 indices[idx1] != indices[idx2]。这确保了输出值不依赖于迭代顺序。
reduction
允许指定一个可选的归约操作,该操作应用于 updates
张量中的所有值,并在指定的 indices
处应用到 output
中。当 reduction
设置为“none”时,indices 不应有重复条目:即,如果 idx1 != idx2,则 indices[idx1] != indices[idx2]。这确保了输出值不依赖于迭代顺序。当 reduction
设置为“add”时, output
计算如下: output = np.copy(data) update_indices = indices.shape[:-1] for idx in np.ndindex(update_indices): output[indices[idx]] += updates[idx] 当 reduction
设置为“mul”时, output
计算如下: output = np.copy(data) update_indices = indices.shape[:-1] for idx in np.ndindex(update_indices): output[indices[idx]] *= updates[idx] 此运算符是 GatherND 的逆运算。示例 1
data = [1, 2, 3, 4, 5, 6, 7, 8]
indices = [[4], [3], [1], [7]]
updates = [9, 10, 11, 12]
output = [1, 11, 3, 10, 9, 6, 7, 12]
示例 2
data = [[[1, 2, 3, 4], [5, 6, 7, 8], [8, 7, 6, 5], [4, 3, 2, 1]],
[[1, 2, 3, 4], [5, 6, 7, 8], [8, 7, 6, 5], [4, 3, 2, 1]],
[[8, 7, 6, 5], [4, 3, 2, 1], [1, 2, 3, 4], [5, 6, 7, 8]],
[[8, 7, 6, 5], [4, 3, 2, 1], [1, 2, 3, 4], [5, 6, 7, 8]]]
indices = [[0], [2]]
updates = [[[5, 5, 5, 5], [6, 6, 6, 6], [7, 7, 7, 7], [8, 8, 8, 8]],
[[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3], [4, 4, 4, 4]]]
output = [[[5, 5, 5, 5], [6, 6, 6, 6], [7, 7, 7, 7], [8, 8, 8, 8]],
[[1, 2, 3, 4], [5, 6, 7, 8], [8, 7, 6, 5], [4, 3, 2, 1]],
[[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3], [4, 4, 4, 4]],
[[8, 7, 6, 5], [4, 3, 2, 1], [1, 2, 3, 4], [5, 6, 7, 8]]]
属性¶
reduction - STRING (默认值为
'none'
)要应用的归约类型:none (默认),add,mul。“none”:不应用归约。“add”:使用加法运算进行归约。“mul”:使用乘法运算进行归约。
输入¶
data (异构) - T
秩 r >= 1 的张量。
indices (异构) - tensor(int64)
秩为 q >= 1 的张量。
updates (异构) - T
秩为 q + r - indices_shape[-1] - 1 的张量。
输出¶
输出 (异构) - 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)
) 中将输入和输出类型限制为任何张量类型。
ScatterND - 13¶
版本¶
域:
main
起始版本:
13
函数:
False
支持级别:
SupportType.COMMON
形状推断:
True
此版本的运算符自 版本 13 起可用。
摘要¶
ScatterND 接收三个输入:秩为 r >= 1 的 data
张量,秩为 q >= 1 的 indices
张量,以及秩为 q + r - indices.shape[-1] - 1 的 updates
张量。该操作通过创建输入 data
的副本,然后使用 indices
指定的特定索引位置上的 updates
值来更新它,从而产生输出。其输出形状与 data
的形状相同。请注意,indices
不应有重复条目。也就是说,不支持对同一索引位置的两个或多个 updates
。
indices
是一个整数张量。令 k 表示 indices.shape[-1],即 indices
形状的最后一个维度。 indices
被视为一个 (q-1) 维的 k 元组张量,其中每个 k 元组是 data
的一个部分索引。因此,k 的值最多可以是 data
的秩。当 k 等于 rank(data) 时,每个更新条目指定对张量单个元素的更新。当 k 小于 rank(data) 时,每个更新条目指定对张量一个切片的更新。索引值允许为负数,按照通常的从末尾倒数计数的约定,但应在有效范围内。
updates
被视为一个 (q-1) 维的替换切片值张量。因此,updates.shape 的前 (q-1) 个维度必须与 indices.shape 的前 (q-1) 个维度匹配。 updates
的其余维度对应于替换切片值 values
的维度。每个替换切片值是一个 (r-k) 维张量,对应于 data
的尾部 (r-k) 维度。因此, updates
的形状必须等于 indices.shape[0:q-1] ++ data.shape[k:r-1],其中 ++ 表示形状的连接。
output
通过以下方程计算:
output = np.copy(data)
update_indices = indices.shape[:-1]
for idx in np.ndindex(update_indices):
output[indices[idx]] = updates[idx]
上述循环中的迭代顺序未指定。特别是,indices 不应有重复条目:即,如果 idx1 != idx2,则 indices[idx1] != indices[idx2]。这确保了输出值不依赖于迭代顺序。
此运算符是 GatherND 的逆运算。
示例 1
data = [1, 2, 3, 4, 5, 6, 7, 8]
indices = [[4], [3], [1], [7]]
updates = [9, 10, 11, 12]
output = [1, 11, 3, 10, 9, 6, 7, 12]
示例 2
data = [[[1, 2, 3, 4], [5, 6, 7, 8], [8, 7, 6, 5], [4, 3, 2, 1]],
[[1, 2, 3, 4], [5, 6, 7, 8], [8, 7, 6, 5], [4, 3, 2, 1]],
[[8, 7, 6, 5], [4, 3, 2, 1], [1, 2, 3, 4], [5, 6, 7, 8]],
[[8, 7, 6, 5], [4, 3, 2, 1], [1, 2, 3, 4], [5, 6, 7, 8]]]
indices = [[0], [2]]
updates = [[[5, 5, 5, 5], [6, 6, 6, 6], [7, 7, 7, 7], [8, 8, 8, 8]],
[[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3], [4, 4, 4, 4]]]
output = [[[5, 5, 5, 5], [6, 6, 6, 6], [7, 7, 7, 7], [8, 8, 8, 8]],
[[1, 2, 3, 4], [5, 6, 7, 8], [8, 7, 6, 5], [4, 3, 2, 1]],
[[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3], [4, 4, 4, 4]],
[[8, 7, 6, 5], [4, 3, 2, 1], [1, 2, 3, 4], [5, 6, 7, 8]]]
输入¶
data (异构) - T
秩 r >= 1 的张量。
indices (异构) - tensor(int64)
秩为 q >= 1 的张量。
updates (异构) - T
秩为 q + r - indices_shape[-1] - 1 的张量。
输出¶
输出 (异构) - 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)
) 中将输入和输出类型限制为任何张量类型。
ScatterND - 11¶
版本¶
域:
main
起始版本:
11
函数:
False
支持级别:
SupportType.COMMON
形状推断:
True
此版本的运算符自 版本 11 起可用。
摘要¶
ScatterND 接收三个输入:秩为 r >= 1 的 data
张量,秩为 q >= 1 的 indices
张量,以及秩为 q + r - indices.shape[-1] - 1 的 updates
张量。该操作通过创建输入 data
的副本,然后使用 indices
指定的特定索引位置上的 updates
值来更新它,从而产生输出。其输出形状与 data
的形状相同。请注意,indices
不应有重复条目。也就是说,不支持对同一索引位置的两个或多个 updates
。
indices
是一个整数张量。令 k 表示 indices.shape[-1],即 indices
形状的最后一个维度。 indices
被视为一个 (q-1) 维的 k 元组张量,其中每个 k 元组是 data
的一个部分索引。因此,k 的值最多可以是 data
的秩。当 k 等于 rank(data) 时,每个更新条目指定对张量单个元素的更新。当 k 小于 rank(data) 时,每个更新条目指定对张量一个切片的更新。索引值允许为负数,按照通常的从末尾倒数计数的约定,但应在有效范围内。
updates
被视为一个 (q-1) 维的替换切片值张量。因此,updates.shape 的前 (q-1) 个维度必须与 indices.shape 的前 (q-1) 个维度匹配。 updates
的其余维度对应于替换切片值 values
的维度。每个替换切片值是一个 (r-k) 维张量,对应于 data
的尾部 (r-k) 维度。因此, updates
的形状必须等于 indices.shape[0:q-1] ++ data.shape[k:r-1],其中 ++ 表示形状的连接。
output
通过以下方程计算:
output = np.copy(data)
update_indices = indices.shape[:-1]
for idx in np.ndindex(update_indices):
output[indices[idx]] = updates[idx]
上述循环中的迭代顺序未指定。特别是,indices 不应有重复条目:即,如果 idx1 != idx2,则 indices[idx1] != indices[idx2]。这确保了输出值不依赖于迭代顺序。
此运算符是 GatherND 的逆运算。
示例 1
data = [1, 2, 3, 4, 5, 6, 7, 8]
indices = [[4], [3], [1], [7]]
updates = [9, 10, 11, 12]
output = [1, 11, 3, 10, 9, 6, 7, 12]
示例 2
data = [[[1, 2, 3, 4], [5, 6, 7, 8], [8, 7, 6, 5], [4, 3, 2, 1]],
[[1, 2, 3, 4], [5, 6, 7, 8], [8, 7, 6, 5], [4, 3, 2, 1]],
[[8, 7, 6, 5], [4, 3, 2, 1], [1, 2, 3, 4], [5, 6, 7, 8]],
[[8, 7, 6, 5], [4, 3, 2, 1], [1, 2, 3, 4], [5, 6, 7, 8]]]
indices = [[0], [2]]
updates = [[[5, 5, 5, 5], [6, 6, 6, 6], [7, 7, 7, 7], [8, 8, 8, 8]],
[[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3], [4, 4, 4, 4]]]
output = [[[5, 5, 5, 5], [6, 6, 6, 6], [7, 7, 7, 7], [8, 8, 8, 8]],
[[1, 2, 3, 4], [5, 6, 7, 8], [8, 7, 6, 5], [4, 3, 2, 1]],
[[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3], [4, 4, 4, 4]],
[[8, 7, 6, 5], [4, 3, 2, 1], [1, 2, 3, 4], [5, 6, 7, 8]]]
输入¶
data (异构) - T
秩 r >= 1 的张量。
indices (异构) - tensor(int64)
秩为 q >= 1 的张量。
updates (异构) - T
秩为 q + r - indices_shape[-1] - 1 的张量。
输出¶
输出 (异构) - 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)
) 中将输入和输出类型限制为任何张量类型。