Gather¶
Gather - 13¶
版本¶
名称: Gather (GitHub)
领域:
main
起始版本:
13
函数:
False
支持级别:
SupportType.COMMON
形状推断:
True
此版本的运算符已可用 自版本 13 起。
概述¶
给定秩 r >= 1 的 data
张量和秩 q 的 indices
张量,根据 indices
索引收集 data
的 axis 维度(默认为最外层维度 axis=0)的条目,并将它们连接到秩 q + (r - 1) 的输出张量中。
它是一个索引操作,沿着单个(指定的)轴索引输入 data
。 indices
中的每个条目生成输入张量的 r-1
维切片。整个操作从概念上生成一个 q
维的 r-1
维切片张量,该张量被排列成一个 q + (r-1)
维张量,其中 q
维占据了被索引的原始 axis
的位置。
以下几个示例说明了 Gather
如何处理 data
、indices
的特定形状以及给定的 axis
值
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'
)用于收集的轴。负值表示从后往前计数维度。接受的范围是 [-r, r-1],其中 r = rank(data)。
输入¶
data (异构) - T
秩 >= 1 的张量。
indices (异构) - Tind
int32/int64 索引的张量,任意秩 q。沿大小为 s 的轴,所有索引值应在 [-s, s-1] 范围内。如果任何索引值超出范围,则会发生错误。
输出¶
output (异构) - 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 维度(默认为最外层维度 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'
)用于收集的轴。负值表示从后往前计数维度。接受的范围是 [-r, r-1],其中 r = rank(data)。
输入¶
data (异构) - T
秩 >= 1 的张量。
indices (异构) - Tind
int32/int64 索引的张量,任意秩 q。沿大小为 s 的轴,所有索引值应在 [-s, s-1] 范围内。如果任何索引值超出范围,则会发生错误。
输出¶
output (异构) - 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 维度(默认为最外层维度 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'
)用于收集的轴。负值表示从后往前计数维度。接受的范围是 [-r, r-1]
输入¶
data (异构) - T
秩 >= 1 的张量。
indices (异构) - Tind
int32/int64 索引的张量,任意秩 q。所有索引值预计在范围内。如果任何索引值超出范围,则会发生错误。
输出¶
output (异构) - 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)
)将索引限制为整数类型