GatherElements

GatherElements - 13

版本

  • 名称: GatherElements (GitHub)

  • : main

  • 起始版本: 13

  • 函数: False

  • 支持级别: SupportType.COMMON

  • 形状推断: True

此版本的算子已自版本 13 起可用。

摘要

GatherElements 接收两个同等秩 r >= 1 的输入 dataindices,以及一个可选属性 axis,用于指定 data 的轴(默认为最外层轴,即轴 0)。它是一种索引操作,通过使用 indices 张量中的元素确定的索引位置索引输入数据张量来生成输出。其输出形状与 indices 的形状相同,并且 indices 中的每个元素对应一个(从 data 中)收集的值。

例如,在 3D 情况 (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 的逆操作。它类似于 PyTorch 的 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] 范围内。如果任何索引值超出范围,则会报错。

输出

  • output (异构) - T

    与 indices 形状相同的张量。

类型约束

  • 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

  • 起始版本: 11

  • 函数: False

  • 支持级别: SupportType.COMMON

  • 形状推断: True

此版本的算子已自版本 11 起可用。

摘要

GatherElements 接收两个同等秩 r >= 1 的输入 dataindices,以及一个可选属性 axis,用于指定 data 的轴(默认为最外层轴,即轴 0)。它是一种索引操作,通过使用 indices 张量中的元素确定的索引位置索引输入数据张量来生成输出。其输出形状与 indices 的形状相同,并且 indices 中的每个元素对应一个(从 data 中)收集的值。

例如,在 3D 情况 (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 的逆操作。它类似于 PyTorch 的 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] 范围内。如果任何索引值超出范围,则会报错。

输出

  • output (异构) - T

    与 indices 形状相同的张量。

类型约束

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

    将索引约束为整数类型