GatherElements¶
GatherElements - 13¶
版本¶
域:
main
起始版本:
13
函数:
False
支持级别:
SupportType.COMMON
形状推断:
True
此版本的运算符自 版本 13 起可用。
摘要¶
GatherElements 接收两个输入 data
和 indices
,它们具有相同的秩 r >= 1,以及一个可选属性 axis
,用于标识 data
的一个轴(默认情况下,最外层的轴,即轴 0)。它是一个索引操作,通过使用 indices
张量元素确定的索引位置对输入数据张量进行索引来生成其输出。其输出形状与 indices
的形状相同,并且对于 indices
中的每个元素,都包含一个值(从 data
中收集)。
例如,在 3-D 情况下 (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 的张量。
索引 (异构) - 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¶
版本¶
域:
main
起始版本:
11
函数:
False
支持级别:
SupportType.COMMON
形状推断:
True
此版本的运算符自 版本 11 起可用。
摘要¶
GatherElements 接收两个输入 data
和 indices
,它们具有相同的秩 r >= 1,以及一个可选属性 axis
,用于标识 data
的一个轴(默认情况下,最外层的轴,即轴 0)。它是一个索引操作,通过使用 indices
张量元素确定的索引位置对输入数据张量进行索引来生成其输出。其输出形状与 indices
的形状相同,并且对于 indices
中的每个元素,都包含一个值(从 data
中收集)。
例如,在 3-D 情况下 (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 的张量。
索引 (异构) - 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)
)将索引限制为整数类型