ScatterElements

ScatterElements - 18

版本

  • 名称: ScatterElements (GitHub)

  • 域名: main

  • since_version: 18

  • 函数: False

  • support_level: SupportType.COMMON

  • 形状推断: True

此版本的运算符自版本18起可用。

摘要

ScatterElements 接受三个输入 dataupdatesindices,它们的秩 r >= 1,并且有一个可选的属性 axis,用于标识 data 的一个轴(默认情况下是最外层的轴,即 axis 0)。该操作的输出是通过创建输入 data 的副本,然后根据 indices 指定的特定索引位置更新其值为 updates 指定的值来生成的。其输出形状与 data 的形状相同。

对于updates中的每个条目,data中的目标索引是通过将indices中的相应条目与条目本身的索引组合得到的:维度 = axis 的索引值从indices中的相应条目的值获得,而维度 != axis 的索引值从条目本身的索引获得。

reduction 允许指定一个可选的归约操作,该操作应用于 updates 张量中的所有值,并将其应用到 output 中指定的 indices 处。 在 reduction 设置为“none”的情况下,索引不应有重复的条目:也就是说,如果 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+, *, maxmin 如所指定的。

此操作符是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'):

    应用的缩减类型:无(默认)、加、乘、最大、最小。‘无’:不应用缩减。‘加’:使用加法操作进行缩减。‘乘’:使用乘法操作进行缩减。‘最大’:使用最大操作进行缩减。‘最小’:使用最小操作进行缩减。

输入

  • data (异构) - T:

    秩为 r >= 1 的张量。

  • indices(异构) - Tind:

    int32/int64索引的张量,r >= 1(与输入相同的秩)。所有索引值都应在大小为s的轴上的边界[-s, s-1]内。如果任何索引值超出边界,则会出现错误。

  • 更新 (异构) - T:

    秩为 r >=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) ):

    输入和输出类型可以是任何张量类型。

  • Tind 在 ( tensor(int32), tensor(int64) ) 中:

    将索引限制为整数类型

ScatterElements - 16

版本

  • 名称: ScatterElements (GitHub)

  • 域名: main

  • since_version: 16

  • 函数: False

  • support_level: SupportType.COMMON

  • 形状推断: True

此版本的运算符自版本16起可用。

摘要

ScatterElements 接受三个输入 dataupdatesindices,它们的秩 r >= 1,并且有一个可选的属性 axis,用于标识 data 的一个轴(默认情况下是最外层的轴,即 axis 0)。该操作的输出是通过创建输入 data 的副本,然后根据 indices 指定的特定索引位置更新其值为 updates 指定的值。其输出形状与 data 的形状相同。 对于 updates 中的每个条目,data 中的目标索引是通过将 indices 中的相应条目与条目本身的索引组合得到的:维度 = axis 的索引值从 indices 中的相应条目的值获得,而维度 != axis 的索引值从条目本身的索引获得。 reduction 允许指定一个可选的归约操作,该操作应用于 updates 张量中的所有值,并将其归约到指定 indicesoutput 中。 在 reduction 设置为“none”的情况下,索引不应有重复条目:即如果 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]内。如果任何索引值超出边界,则会出现错误。

  • 更新 (异构) - T:

    秩为 r >=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) ):

    输入和输出类型可以是任何张量类型。

  • Tind 在 ( tensor(int32), tensor(int64) ) 中:

    将索引限制为整数类型

ScatterElements - 13

版本

  • 名称: ScatterElements (GitHub)

  • 域名: main

  • since_version: 13

  • 函数: False

  • support_level: SupportType.COMMON

  • 形状推断: True

此版本的运算符自版本13起可用。

总结

ScatterElements 接受三个输入 dataupdatesindices,它们的秩 r >= 1,并且有一个可选的属性 axis,用于标识 data 的一个轴(默认情况下是最外层的轴,即 axis 0)。该操作的输出是通过创建输入 data 的副本,然后根据 indices 指定的特定索引位置更新其值为 updates 指定的值来生成的。其输出形状与 data 的形状相同。

对于updates中的每个条目,data中的目标索引是通过将indices中的相应条目与条目本身的索引组合得到的:维度 = 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]内。如果任何索引值超出边界,则会出现错误。

  • 更新 (异构) - T:

    秩为 r >=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) ):

    输入和输出类型可以是任何张量类型。

  • Tind 在 ( tensor(int32), tensor(int64) ) 中:

    将索引限制为整数类型

ScatterElements - 11

版本

  • 名称: ScatterElements (GitHub)

  • 域名: main

  • since_version: 11

  • 函数: False

  • support_level: SupportType.COMMON

  • 形状推断: True

此版本的运算符自版本11起可用。

摘要

ScatterElements 接受三个输入 dataupdatesindices,它们的秩 r >= 1,并且有一个可选的属性 axis,用于标识 data 的一个轴(默认情况下是最外层的轴,即 axis 0)。该操作的输出是通过创建输入 data 的副本,然后根据 indices 指定的特定索引位置更新其值为 updates 指定的值来生成的。其输出形状与 data 的形状相同。

对于updates中的每个条目,data中的目标索引是通过将indices中的相应条目与条目本身的索引组合得到的:维度 = 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]内。如果任何索引值超出边界,则会出现错误。

  • 更新 (异构) - T:

    秩为 r >=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) ):

    输入和输出类型可以是任何张量类型。

  • Tind 在 ( tensor(int32), tensor(int64) ) 中:

    将索引限制为整数类型