ScatterND¶
ScatterND - 18¶
版本¶
域名:
mainsince_version:
18函数:
Falsesupport_level:
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 的其余维度对应于替换切片值的维度。每个替换切片值是一个 (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]
上述循环中的迭代顺序未指定。 特别是,索引不应有重复条目:即,如果 idx1 != idx2,则 indices[idx1] != indices[idx2]。 这确保了输出值不依赖于迭代顺序。
reduction 允许指定一个可选的归约操作,该操作应用于 updates 张量中的所有值,并将其应用到 output 中指定的 indices 处。
在 reduction 设置为“none”的情况下,索引不应有重复条目:即如果 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'):应用的缩减类型:无(默认)、加、乘、最大、最小。‘无’:不应用缩减。‘加’:使用加法操作进行缩减。‘乘’:使用乘法操作进行缩减。‘最大’:使用最大值操作进行缩减。‘最小’:使用最小值操作进行缩减。
输入¶
data (异构) - T:
秩为 r >= 1 的张量。
indices (异构) - tensor(int64):
秩为 q >= 1 的张量。
更新 (异构) - 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¶
版本¶
域名:
mainsince_version:
16函数:
Falsesupport_level:
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 的其余维度对应于替换切片值的维度。每个替换切片值是一个 (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]
上述循环中的迭代顺序未指定。
特别是,索引不应有重复条目:即如果 idx1 != idx2,则 indices[idx1] != indices[idx2]。
这确保了输出值不依赖于迭代顺序。
reduction 允许指定一个可选的归约操作,该操作应用于 updates 张量中的所有值,并将其放入指定 indices 的 output 中。
在 reduction 设置为“none”的情况下,索引不应有重复条目:即如果 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 的张量。
更新 (异构) - 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¶
版本¶
域名:
mainsince_version:
13函数:
Falsesupport_level:
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 的其余维度对应于替换切片值的维度。每个替换切片值是一个 (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]
上述循环中的迭代顺序未指定。 特别是,索引不应有重复条目:即,如果 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 的张量。
更新 (异构) - 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¶
版本¶
域名:
mainsince_version:
11函数:
Falsesupport_level:
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 的其余维度对应于替换切片值的维度。每个替换切片值是一个 (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]
上述循环中的迭代顺序未指定。 特别是,索引不应有重复条目:即,如果 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 的张量。
更新 (异构) - 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)):将输入和输出类型限制为任何张量类型。