分散¶
分散 - 11¶
版本¶
名稱:分散 (GitHub)
網域:
main
自版本:
11
函式:
False
支援層級:
SupportType.COMMON
形狀推斷:
True
此版本的運算子自版本 11 起已棄用。
摘要¶
此運算子已棄用。請使用 ScatterElements,它提供相同的功能。
分散採用三個輸入 data
、updates
和 indices
,它們的階數 r >= 1,以及一個選用的屬性 axis,該屬性會識別 data
的軸 (預設為最外層軸,即軸 0)。運算的輸出是藉由建立輸入 data
的複本,然後將其值更新為 updates
指定的值,在 indices
指定的特定索引位置產生。其輸出形狀與 data
的形狀相同。
對於 updates
中的每個條目,data
中的目標索引是藉由將 indices
中對應的條目與條目本身的索引結合取得:維度 = axis 的索引值是從 indices
中對應條目的值取得,而維度 != axis 的索引值則是從條目本身的索引取得。
例如,在 2 維張量的情況下,對應於 [i][j] 條目的更新會如下執行
output[indices[i][j]][j] = updates[i][j] if axis = 0,
output[i][indices[i][j]] = updates[i][j] if axis = 1,
此運算子是 GatherElements 的反運算。它與 Torch 的分散運算類似。
範例 1
data = [
[0.0, 0.0, 0.0],
[0.0, 0.0, 0.0],
[0.0, 0.0, 0.0],
]
indices = [
[1, 0, 2],
[0, 2, 1],
]
updates = [
[1.0, 1.1, 1.2],
[2.0, 2.1, 2.2],
]
output = [
[2.0, 1.1, 0.0]
[1.0, 0.0, 2.2]
[0.0, 2.1, 1.2]
]
範例 2
data = [[1.0, 2.0, 3.0, 4.0, 5.0]]
indices = [[1, 3]]
updates = [[1.1, 2.1]]
axis = 1
output = [[1.0, 1.1, 3.0, 2.1, 5.0]]
屬性¶
軸 - INT (預設為
'0'
)要分散的軸。負值表示從後面計算維度。可接受的範圍為 [-r, r-1],其中 r = rank(data)。
輸入¶
資料 (異質) - T
階數 r >= 1 的張量。
索引 (異質) - Tind
int32/int64 索引的張量,r >= 1 (與輸入相同的階數)。所有索引值都應在沿大小為 s 的軸的範圍 [-s, s-1] 內。如果任何索引值超出範圍,則會發生錯誤。
更新 (異質) - T
階數 r >=1 的張量 (與索引相同的階數和形狀)
輸出¶
輸出 (異質) - T
階數 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)
)將索引限制為整數類型
分散 - 9¶
版本¶
名稱:分散 (GitHub)
網域:
main
自版本:
9
函式:
False
支援層級:
SupportType.COMMON
形狀推斷:
True
此版本的運算子自版本 9 起已可用。
摘要¶
假設 rank r >= 1 的 data
、updates
和 indices
輸入張量,將 updates
提供的值沿著 data
的 axis
維度 (預設為最外層的 axis=0) 寫入第一個輸入 data
,在對應的 indices
。對於 updates
中的每個條目,data
中的目標索引是藉由 indices
中維度 = axis 的對應條目,以及維度 != axis 的來源索引指定。例如,在 2 維張量的情況下,如果 axis = 0,則 data[indices[i][j]][j] = updates[i][j],如果 axis = 1,則 data[i][indices[i][j]] = updates[i][j],其中 i 和 j 是從 0 開始,直到 updates
中各自大小 - 1 的迴圈計數器。範例 1:data = [ [0.0, 0.0, 0.0], [0.0, 0.0, 0.0], [0.0, 0.0, 0.0], ] indices = [ [1, 0, 2], [0, 2, 1], ] updates = [ [1.0, 1.1, 1.2], [2.0, 2.1, 2.2], ] output = [ [2.0, 1.1, 0.0] [1.0, 0.0, 2.2] [0.0, 2.1, 1.2] ] 範例 2:data = [[1.0, 2.0, 3.0, 4.0, 5.0]] indices = [[1, 3]] updates = [[1.1, 2.1]] axis = 1 output = [[1.0, 1.1, 3.0, 2.1, 5.0]]
屬性¶
軸 - INT (預設為
'0'
)要分散的軸。負值表示從後面計算維度。可接受的範圍為 [-r, r-1]
輸入¶
資料 (異質) - T
階數 r >= 1 的張量。
索引 (異質) - Tind
int32/int64 索引的張量,r >= 1 (與輸入相同的階數)。
更新 (異質) - T
階數 r >=1 的張量 (與索引相同的階數和形狀)
輸出¶
輸出 (異質) - T
階數 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)
)將索引限制為整數類型