GatherElements

GatherElements - 13

版本

  • 名称: GatherElements (GitHub)

  • 域名: main

  • since_version: 13

  • 函数: False

  • support_level: SupportType.COMMON

  • 形状推断: True

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

摘要

GatherElements 接受两个输入 dataindices,它们的秩相同且 r >= 1, 以及一个可选的属性 axis,用于标识 data 的一个轴 (默认情况下,是最外层的轴,即轴 0)。这是一个索引操作, 通过根据 indices 张量的元素确定的索引位置,从输入数据张量中索引生成输出。 其输出形状与 indices 的形状相同,并且由 indices 中的每个元素 (从 data 中收集)的一个值组成。

例如,在三维情况下(r = 3),输出由以下方程确定:

out[i][j][k] = input[index[i][j][k]][j][k] if axis = 0,
out[i][j][k] = input[i][index[i][j][k]][k] if axis = 1,
out[i][j][k] = input[i][j][index[i][j][k]] if axis = 2,

此运算符也是ScatterElements的逆运算。它类似于Torch的gather操作。

示例 1:

data = [
    [1, 2],
    [3, 4],
]
indices = [
    [0, 0],
    [1, 0],
]
axis = 1
output = [
    [1, 1],
    [4, 3],
]

示例 2:

data = [
    [1, 2, 3],
    [4, 5, 6],
    [7, 8, 9],
]
indices = [
    [1, 2, 0],
    [2, 0, 0],
]
axis = 0
output = [
    [4, 8, 3],
    [7, 2, 3],
]

属性

  • axis - INT (默认为 '0'):

    在哪个轴上收集。负值表示从后面开始计算维度。可接受的范围是 [-r, r-1],其中 r = rank(data)。

输入

  • data (异构) - T:

    秩为 r >= 1 的张量。

  • indices(异构) - Tind:

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

输出

  • 输出 (异构) - T:

    与索引形状相同的张量。

类型约束

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

    将索引限制为整数类型

GatherElements - 11

版本

  • 名称: GatherElements (GitHub)

  • 域名: main

  • since_version: 11

  • 函数: False

  • support_level: SupportType.COMMON

  • 形状推断: True

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

摘要

GatherElements 接受两个输入 dataindices,它们的秩相同且 r >= 1, 以及一个可选的属性 axis,用于标识 data 的一个轴 (默认情况下,是最外层的轴,即轴 0)。这是一个索引操作, 通过根据 indices 张量的元素确定的索引位置,从输入数据张量中索引生成输出。 其输出形状与 indices 的形状相同,并且由 indices 中的每个元素 (从 data 中收集)的一个值组成。

例如,在三维情况下(r = 3),输出由以下方程确定:

  out[i][j][k] = input[index[i][j][k]][j][k] if axis = 0,
  out[i][j][k] = input[i][index[i][j][k]][k] if axis = 1,
  out[i][j][k] = input[i][j][index[i][j][k]] if axis = 2,

此运算符也是ScatterElements的逆运算。它类似于Torch的gather操作。

示例 1:

  data = [
      [1, 2],
      [3, 4],
  ]
  indices = [
      [0, 0],
      [1, 0],
  ]
  axis = 1
  output = [
      [
        [1, 1],
        [4, 3],
      ],
  ]

示例 2:

  data = [
      [1, 2, 3],
      [4, 5, 6],
      [7, 8, 9],
  ]
  indices = [
      [1, 2, 0],
      [2, 0, 0],
  ]
  axis = 0
  output = [
      [
        [4, 8, 3],
        [7, 2, 3],
      ],
  ]

属性

  • axis - INT (默认为 '0'):

    在哪个轴上收集。负值表示从后面开始计算维度。可接受的范围是[-r, r-1],其中r = rank(data)。

输入

  • data (异构) - T:

    秩为 r >= 1 的张量。

  • indices(异构) - Tind:

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

输出

  • 输出 (异构) - T:

    与索引形状相同的张量。

类型约束

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

    将索引限制为整数类型