Gather¶
Gather - 13¶
版本¶
- 名称: Gather (GitHub) 
- 域: - main
- 起始版本: - 13
- 函数: - False
- 支持级别: - SupportType.COMMON
- 形状推断: - True
此版本的运算符自 版本 13 起可用。
摘要¶
给定秩 r >= 1 的 data 张量和秩 q 的 indices 张量,根据 indices 索引,收集 data 的轴维度(默认最外层轴为 axis=0)的条目,并将它们连接到一个秩为 q + (r - 1) 的输出张量中。
它是一个索引操作,沿单个(指定)轴对输入 data 进行索引。 indices 中的每个条目都会生成输入张量的一个 r-1 维切片。整个操作概念上会生成一个 q 维的 r-1 维切片张量,该张量被排列成一个 q + (r-1) 维张量,其中 q 维度取代了被索引的原始 axis 的位置。
以下几个示例说明了 Gather 如何针对 data、indices 的特定形状以及给定的 axis 值进行工作。
| 数据形状 | 索引形状 | 轴 | 输出形状 | 输出方程 | 
|---|---|---|---|---|
| (P, Q) | ( )(标量) | 0 | (Q) | output[q] = data[indices, q] | 
| (P, Q, R) | ( )(标量) | 1 | (P, R) | output[p, r] = data[p, indices, r] | 
| (P, Q) | (R, S) | 0 | (R, S, Q) | output[r, s, q] = data[ [indices[r, s], q] | 
| (P, Q) | (R, S) | 1 | (P, R, S) | output[p, r, s] = data[ p, indices[r, s]] | 
更一般地,如果 axis = 0,设 k = indices[i_{0}, ..., i_{q-1}] 则 output[i_{0}, ..., i_{q-1}, j_{0}, ..., j_{r-2}] = input[k , j_{0}, ..., j_{r-2}]
data = [
    [1.0, 1.2],
    [2.3, 3.4],
    [4.5, 5.7],
]
indices = [
    [0, 1],
    [1, 2],
]
output = [
    [
        [1.0, 1.2],
        [2.3, 3.4],
    ],
    [
        [2.3, 3.4],
        [4.5, 5.7],
    ],
]
如果 axis = 1,设 k = indices[i_{0}, ..., i_{q-1}] 则 output[j_{0}, i_{0}, ..., i_{q-1}, j_{1}, ..., j_{r-2}] = input[j_{0}, k, j_{1}, ..., j_{r-2}]
data = [
    [1.0, 1.2, 1.9],
    [2.3, 3.4, 3.9],
    [4.5, 5.7, 5.9],
]
indices = [
    [0, 2],
]
axis = 1,
output = [
        [[1.0, 1.9]],
        [[2.3, 3.9]],
        [[4.5, 5.9]],
]
属性¶
- axis - INT (默认值为 - '0')- 要进行 Gather 操作的轴。负值表示从后往前计数维度。接受的范围是 [-r, r-1],其中 r = rank(data)。 
输入¶
- data (异构) - T - 秩 r >= 1 的张量。 
- 索引 (异构) - Tind - int32/int64 索引张量,任意秩 q。所有索引值都应在轴大小 s 的 [-s, s-1] 范围内。如果任何索引值超出范围,则会出错。 
输出¶
- 输出 (异构) - T - 秩为 q + (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))- 将索引限制为整数类型 
Gather - 11¶
版本¶
- 名称: Gather (GitHub) 
- 域: - main
- 起始版本: - 11
- 函数: - False
- 支持级别: - SupportType.COMMON
- 形状推断: - True
此版本的运算符自 版本 11 起可用。
摘要¶
给定秩 r >= 1 的 data 张量和秩 q 的 indices 张量,根据 indices 索引,收集 data 的轴维度(默认最外层轴为 axis=0)的条目,并将它们连接到一个秩为 q + (r - 1) 的输出张量中。
axis = 0
设 k = indices[i_{0}, …, i_{q-1}] 则 output[i_{0}, …, i_{q-1}, j_{0}, …, j_{r-2}] = input[k , j_{0}, …, j_{r-2}]
  data = [
      [1.0, 1.2],
      [2.3, 3.4],
      [4.5, 5.7],
  ]
  indices = [
      [0, 1],
      [1, 2],
  ]
  output = [
      [
          [1.0, 1.2],
          [2.3, 3.4],
      ],
      [
          [2.3, 3.4],
          [4.5, 5.7],
      ],
  ]
axis = 1
设 k = indices[i_{0}, …, i_{q-1}] 则 output[j_{0}, i_{0}, …, i_{q-1}, j_{1}, …, j_{r-2}] = input[j_{0}, k, j_{1}, …, j_{r-2}]
  data = [
      [1.0, 1.2, 1.9],
      [2.3, 3.4, 3.9],
      [4.5, 5.7, 5.9],
  ]
  indices = [
      [0, 2],
  ]
  axis = 1,
  output = [
      [[1.0, 1.9]],
      [[2.3, 3.9]],
      [[4.5, 5.9]],
  ]
属性¶
- axis - INT (默认值为 - '0')- 要进行 Gather 操作的轴。负值表示从后往前计数维度。接受的范围是 [-r, r-1],其中 r = rank(data)。 
输入¶
- data (异构) - T - 秩 r >= 1 的张量。 
- 索引 (异构) - Tind - int32/int64 索引张量,任意秩 q。所有索引值都应在轴大小 s 的 [-s, s-1] 范围内。如果任何索引值超出范围,则会出错。 
输出¶
- 输出 (异构) - T - 秩为 q + (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))- 将索引限制为整数类型 
Gather - 1¶
版本¶
- 名称: Gather (GitHub) 
- 域: - main
- 起始版本: - 1
- 函数: - False
- 支持级别: - SupportType.COMMON
- 形状推断: - True
此版本的运算符自 版本 1 起可用。
摘要¶
给定秩 r >= 1 的 data 张量和秩 q 的 indices 张量,根据 indices 索引,收集 data 的轴维度(默认最外层轴为 axis=0)的条目,并将它们连接到一个秩为 q + (r - 1) 的输出张量中。示例 1
  data = [
      [1.0, 1.2],
      [2.3, 3.4],
      [4.5, 5.7],
  ]
  indices = [
      [0, 1],
      [1, 2],
  ]
  output = [
      [
          [1.0, 1.2],
          [2.3, 3.4],
      ],
      [
          [2.3, 3.4],
          [4.5, 5.7],
      ],
  ]
示例 2
  data = [
      [1.0, 1.2, 1.9],
      [2.3, 3.4, 3.9],
      [4.5, 5.7, 5.9],
  ]
  indices = [
      [0, 2],
  ]
  axis = 1,
  output = [
      [[1.0, 1.9]],
      [[2.3, 3.9]],
      [[4.5, 5.9]],
  ]
属性¶
- axis - INT (默认值为 - '0')- 要进行 Gather 操作的轴。负值表示从后往前计数维度。接受的范围是 [-r, r-1] 
输入¶
- data (异构) - T - 秩 r >= 1 的张量。 
- 索引 (异构) - Tind - int32/int64 索引张量,任意秩 q。所有索引值都应在范围内。如果任何索引值超出范围,则会出错。 
输出¶
- 输出 (异构) - T - 秩为 q + (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))- 将索引限制为整数类型