ScatterND

ScatterND - 18

版本

  • 名称: ScatterND (GitHub)

  • : 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 的剩余维度对应于替换切片值的维度。每个替换切片值是一个 (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 张量中的所有值,并结合到指定 indicesoutput 中。如果 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+, *, maxmin,具体取决于指定。

此算子是 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 的张量。

输出

  • 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) )

    约束输入和输出类型为任意张量类型。

ScatterND - 16

版本

  • 名称: ScatterND (GitHub)

  • : main

  • 自版本: 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 的剩余维度对应于替换切片值的维度。每个替换切片值是一个 (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 张量中的所有值,并结合到指定 indicesoutput 中。如果 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 的张量。

输出

  • 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) )

    约束输入和输出类型为任意张量类型。

ScatterND - 13

版本

  • 名称: ScatterND (GitHub)

  • : 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 的剩余维度对应于替换切片值的维度。每个替换切片值是一个 (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 的张量。

输出

  • 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) )

    约束输入和输出类型为任意张量类型。

ScatterND - 11

版本

  • 名称: ScatterND (GitHub)

  • : 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 的剩余维度对应于替换切片值的维度。每个替换切片值是一个 (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 的张量。

输出

  • 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) )

    约束输入和输出类型为任意张量类型。