ScatterND¶
ScatterND - 18¶
版本¶
網域:
main
since_version:
18
函數:
False
支援等級:
SupportType.COMMON
形狀推論:
True
此版本的運算子自版本 18 起可用。
摘要¶
ScatterND 採用三個輸入:等級 r >= 1 的 data
張量、等級 q >= 1 的 indices
張量,以及等級 q + r - indices.shape[-1] - 1 的 updates
張量。此運算的輸出是透過建立輸入 data
的副本,然後將其值更新為 updates
所指定的值,並以 indices
所指定的特定索引位置進行。其輸出形狀與 data
的形狀相同。
indices
是整數張量。讓 k 表示 indices.shape[-1],indices
形狀中的最後一個維度。indices
被視為 k 元組的 (q-1) 維張量,其中每個 k 元組是 data
的部分索引。因此,k 的值最多可以是 data
的等級。當 k 等於 rank(data) 時,每個更新項目會指定張量單一元素的更新。當 k 小於 rank(data) 時,每個更新項目會指定張量切片的更新。索引值允許為負數,依據從結尾倒數的慣例,但預期在有效範圍內。
updates
被視為替換切片值的 (q-1) 維張量。因此,updates.shape 的前 (q-1) 個維度必須與 indices.shape 的前 (q-1) 個維度相符。 updates
的其餘維度對應於替換切片值的維度。每個替換切片值都是 (r-k) 維張量,對應於 data
的尾端 (r-k) 維度。因此,updates
的形狀必須等於 indices.shape[0:q-1] ++ data.shape[k:r-1],其中 ++ 表示形狀的串連。
output
是透過下列方程式計算得出
output = np.copy(data)
update_indices = indices.shape[:-1]
for idx in np.ndindex(update_indices):
output[indices[idx]] = updates[idx]
上述迴圈中的疊代順序並未指定。特別是,索引不應有重複的項目:也就是說,如果 idx1 != idx2,則 indices[idx1] != indices[idx2]。這確保輸出值不取決於疊代順序。
reduction
允許指定選用的縮減運算,此運算會應用於 updates
張量中的所有值,將值寫入 output
中指定的 indices
。在 reduction
設定為「none」的情況下,索引不應有重複的項目:也就是說,如果 idx1 != idx2,則 indices[idx1] != indices[idx2]。這確保輸出值不取決於疊代順序。當 reduction
設定為某個縮減函數 f
時,output
的計算方式如下
output = np.copy(data)
update_indices = indices.shape[:-1]
for idx in np.ndindex(update_indices):
output[indices[idx]] = f(output[indices[idx]], updates[idx])
其中,f
是 +
、*
、max
或 min
,如指定所示。
此運算子是 GatherND 的相反運算。
(Opset 18 變更):將 max/min 新增至允許的縮減運算集合中。
範例 1
data = [1, 2, 3, 4, 5, 6, 7, 8]
indices = [[4], [3], [1], [7]]
updates = [9, 10, 11, 12]
output = [1, 11, 3, 10, 9, 6, 7, 12]
範例 2
data = [[[1, 2, 3, 4], [5, 6, 7, 8], [8, 7, 6, 5], [4, 3, 2, 1]],
[[1, 2, 3, 4], [5, 6, 7, 8], [8, 7, 6, 5], [4, 3, 2, 1]],
[[8, 7, 6, 5], [4, 3, 2, 1], [1, 2, 3, 4], [5, 6, 7, 8]],
[[8, 7, 6, 5], [4, 3, 2, 1], [1, 2, 3, 4], [5, 6, 7, 8]]]
indices = [[0], [2]]
updates = [[[5, 5, 5, 5], [6, 6, 6, 6], [7, 7, 7, 7], [8, 8, 8, 8]],
[[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3], [4, 4, 4, 4]]]
output = [[[5, 5, 5, 5], [6, 6, 6, 6], [7, 7, 7, 7], [8, 8, 8, 8]],
[[1, 2, 3, 4], [5, 6, 7, 8], [8, 7, 6, 5], [4, 3, 2, 1]],
[[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3], [4, 4, 4, 4]],
[[8, 7, 6, 5], [4, 3, 2, 1], [1, 2, 3, 4], [5, 6, 7, 8]]]
屬性¶
reduction - 字串 (預設為
'none'
)要套用的縮減類型:none (預設)、add、mul、max、min。‘none’: 未套用縮減。‘add’: 使用加法運算的縮減。‘mul’: 使用加法運算的縮減。‘max’: 使用最大值運算的縮減。‘min’: 使用最小值運算的縮減。
輸入¶
data (異質) - T
等級 r >= 1 的張量。
indices (異質) - tensor(int64)
等級 q >= 1 的張量。
updates (異質) - T
等級 q + r - indices_shape[-1] - 1 的張量。
輸出¶
output (異質) - T
等級 r >= 1 的張量。
類型限制¶
T in (
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)
)將輸入和輸出類型限制為任何張量類型。
ScatterND - 16¶
版本¶
網域:
main
since_version:
16
函數:
False
支援等級:
SupportType.COMMON
形狀推論:
True
此版本的運算子自版本 16 起可用。
摘要¶
ScatterND 採用三個輸入:等級 r >= 1 的 data
張量、等級 q >= 1 的 indices
張量,以及等級 q + r - indices.shape[-1] - 1 的 updates
張量。此運算的輸出是透過建立輸入 data
的副本,然後將其值更新為 updates
所指定的值,並以 indices
所指定的特定索引位置進行。其輸出形狀與 data
的形狀相同。
indices
是整數張量。讓 k 表示 indices.shape[-1],indices
形狀中的最後一個維度。indices
被視為 k 元組的 (q-1) 維張量,其中每個 k 元組是 data
的部分索引。因此,k 的值最多可以是 data
的等級。當 k 等於 rank(data) 時,每個更新項目會指定張量單一元素的更新。當 k 小於 rank(data) 時,每個更新項目會指定張量切片的更新。索引值允許為負數,依據從結尾倒數的慣例,但預期在有效範圍內。
updates
被視為替換切片值的 (q-1) 維張量。因此,updates.shape 的前 (q-1) 個維度必須與 indices.shape 的前 (q-1) 個維度相符。 updates
的其餘維度對應於替換切片值的維度。每個替換切片值都是 (r-k) 維張量,對應於 data
的尾端 (r-k) 維度。因此,updates
的形狀必須等於 indices.shape[0:q-1] ++ data.shape[k:r-1],其中 ++ 表示形狀的串連。
output
的計算方式如下:output = np.copy(data) update_indices = indices.shape[:-1] for idx in np.ndindex(update_indices): output[indices[idx]] = updates[idx] 上述迴圈中的疊代順序並未指定。特別是,索引不應有重複的項目:也就是說,如果 idx1 != idx2,則 indices[idx1] != indices[idx2]。這確保輸出值不取決於疊代順序。
reduction
允許指定一個可選的歸約操作,該操作會應用於 updates
張量中的所有值,並將結果寫入到指定 indices
位置的 output
中。當 reduction
設為 “none” 時,索引不應包含重複的條目:也就是說,如果 idx1 != idx2,則 indices[idx1] != indices[idx2]。這樣可以確保輸出的值不依賴於迭代順序。當 reduction
設為 “add” 時,output
的計算方式如下: output = np.copy(data) update_indices = indices.shape[:-1] for idx in np.ndindex(update_indices): output[indices[idx]] += updates[idx] 當 reduction
設為 “mul” 時,output
的計算方式如下: output = np.copy(data) update_indices = indices.shape[:-1] for idx in np.ndindex(update_indices): output[indices[idx]] *= updates[idx] 此運算子是 GatherND 的逆運算。範例 1
data = [1, 2, 3, 4, 5, 6, 7, 8]
indices = [[4], [3], [1], [7]]
updates = [9, 10, 11, 12]
output = [1, 11, 3, 10, 9, 6, 7, 12]
範例 2
data = [[[1, 2, 3, 4], [5, 6, 7, 8], [8, 7, 6, 5], [4, 3, 2, 1]],
[[1, 2, 3, 4], [5, 6, 7, 8], [8, 7, 6, 5], [4, 3, 2, 1]],
[[8, 7, 6, 5], [4, 3, 2, 1], [1, 2, 3, 4], [5, 6, 7, 8]],
[[8, 7, 6, 5], [4, 3, 2, 1], [1, 2, 3, 4], [5, 6, 7, 8]]]
indices = [[0], [2]]
updates = [[[5, 5, 5, 5], [6, 6, 6, 6], [7, 7, 7, 7], [8, 8, 8, 8]],
[[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3], [4, 4, 4, 4]]]
output = [[[5, 5, 5, 5], [6, 6, 6, 6], [7, 7, 7, 7], [8, 8, 8, 8]],
[[1, 2, 3, 4], [5, 6, 7, 8], [8, 7, 6, 5], [4, 3, 2, 1]],
[[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3], [4, 4, 4, 4]],
[[8, 7, 6, 5], [4, 3, 2, 1], [1, 2, 3, 4], [5, 6, 7, 8]]]
屬性¶
reduction - 字串 (預設為
'none'
)要應用的歸約類型:none(預設值)、add、mul。 ‘none’:不應用歸約。 ‘add’:使用加法運算進行歸約。 ‘mul’:使用乘法運算進行歸約。
輸入¶
data (異質) - T
等級 r >= 1 的張量。
indices (異質) - tensor(int64)
等級 q >= 1 的張量。
updates (異質) - T
等級 q + r - indices_shape[-1] - 1 的張量。
輸出¶
output (異質) - T
等級 r >= 1 的張量。
類型約束¶
T in (
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)
)將輸入和輸出類型限制為任何張量類型。
ScatterND - 13¶
版本¶
網域:
main
since_version:
13
函數:
False
支援等級:
SupportType.COMMON
形狀推論:
True
此運算子的版本已於 13 版 開始提供。
摘要¶
ScatterND 接受三個輸入:rank 為 r >= 1 的 data
張量、rank 為 q >= 1 的 indices
張量,以及 rank 為 q + r - indices.shape[-1] - 1 的 updates
張量。此運算的輸出是透過建立輸入 data
的副本,然後將其值更新為 updates
指定的值,並更新的位置由 indices
指定。其輸出形狀與 data
的形狀相同。請注意,indices
不應包含重複的條目。也就是說,不支援對同一個索引位置進行兩個或多個 updates
。
indices
是整數張量。讓 k 表示 indices.shape[-1],indices
形狀中的最後一個維度。indices
被視為 k 元組的 (q-1) 維張量,其中每個 k 元組是 data
的部分索引。因此,k 的值最多可以是 data
的等級。當 k 等於 rank(data) 時,每個更新項目會指定張量單一元素的更新。當 k 小於 rank(data) 時,每個更新項目會指定張量切片的更新。索引值允許為負數,依據從結尾倒數的慣例,但預期在有效範圍內。
updates
被視為替換切片值的 (q-1) 維張量。因此,updates.shape 的前 (q-1) 個維度必須與 indices.shape 的前 (q-1) 個維度相符。 updates
的其餘維度對應於替換切片值的維度。每個替換切片值都是 (r-k) 維張量,對應於 data
的尾端 (r-k) 維度。因此,updates
的形狀必須等於 indices.shape[0:q-1] ++ data.shape[k:r-1],其中 ++ 表示形狀的串連。
output
是透過下列方程式計算得出
output = np.copy(data)
update_indices = indices.shape[:-1]
for idx in np.ndindex(update_indices):
output[indices[idx]] = updates[idx]
上述迴圈中的疊代順序並未指定。特別是,索引不應有重複的項目:也就是說,如果 idx1 != idx2,則 indices[idx1] != indices[idx2]。這確保輸出值不取決於疊代順序。
此運算子是 GatherND 的相反運算。
範例 1
data = [1, 2, 3, 4, 5, 6, 7, 8]
indices = [[4], [3], [1], [7]]
updates = [9, 10, 11, 12]
output = [1, 11, 3, 10, 9, 6, 7, 12]
範例 2
data = [[[1, 2, 3, 4], [5, 6, 7, 8], [8, 7, 6, 5], [4, 3, 2, 1]],
[[1, 2, 3, 4], [5, 6, 7, 8], [8, 7, 6, 5], [4, 3, 2, 1]],
[[8, 7, 6, 5], [4, 3, 2, 1], [1, 2, 3, 4], [5, 6, 7, 8]],
[[8, 7, 6, 5], [4, 3, 2, 1], [1, 2, 3, 4], [5, 6, 7, 8]]]
indices = [[0], [2]]
updates = [[[5, 5, 5, 5], [6, 6, 6, 6], [7, 7, 7, 7], [8, 8, 8, 8]],
[[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3], [4, 4, 4, 4]]]
output = [[[5, 5, 5, 5], [6, 6, 6, 6], [7, 7, 7, 7], [8, 8, 8, 8]],
[[1, 2, 3, 4], [5, 6, 7, 8], [8, 7, 6, 5], [4, 3, 2, 1]],
[[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3], [4, 4, 4, 4]],
[[8, 7, 6, 5], [4, 3, 2, 1], [1, 2, 3, 4], [5, 6, 7, 8]]]
輸入¶
data (異質) - T
等級 r >= 1 的張量。
indices (異質) - tensor(int64)
等級 q >= 1 的張量。
updates (異質) - T
等級 q + r - indices_shape[-1] - 1 的張量。
輸出¶
output (異質) - T
等級 r >= 1 的張量。
類型約束¶
T in (
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)
)將輸入和輸出類型限制為任何張量類型。
ScatterND - 11¶
版本¶
網域:
main
since_version:
11
函數:
False
支援等級:
SupportType.COMMON
形狀推論:
True
此運算子的版本已於 11 版 開始提供。
摘要¶
ScatterND 接受三個輸入:rank 為 r >= 1 的 data
張量、rank 為 q >= 1 的 indices
張量,以及 rank 為 q + r - indices.shape[-1] - 1 的 updates
張量。此運算的輸出是透過建立輸入 data
的副本,然後將其值更新為 updates
指定的值,並更新的位置由 indices
指定。其輸出形狀與 data
的形狀相同。請注意,indices
不應包含重複的條目。也就是說,不支援對同一個索引位置進行兩個或多個 updates
。
indices
是整數張量。讓 k 表示 indices.shape[-1],indices
形狀中的最後一個維度。indices
被視為 k 元組的 (q-1) 維張量,其中每個 k 元組是 data
的部分索引。因此,k 的值最多可以是 data
的等級。當 k 等於 rank(data) 時,每個更新項目會指定張量單一元素的更新。當 k 小於 rank(data) 時,每個更新項目會指定張量切片的更新。索引值允許為負數,依據從結尾倒數的慣例,但預期在有效範圍內。
updates
被視為替換切片值的 (q-1) 維張量。因此,updates.shape 的前 (q-1) 個維度必須與 indices.shape 的前 (q-1) 個維度相符。 updates
的其餘維度對應於替換切片值的維度。每個替換切片值都是 (r-k) 維張量,對應於 data
的尾端 (r-k) 維度。因此,updates
的形狀必須等於 indices.shape[0:q-1] ++ data.shape[k:r-1],其中 ++ 表示形狀的串連。
output
是透過下列方程式計算得出
output = np.copy(data)
update_indices = indices.shape[:-1]
for idx in np.ndindex(update_indices):
output[indices[idx]] = updates[idx]
上述迴圈中的疊代順序並未指定。特別是,索引不應有重複的項目:也就是說,如果 idx1 != idx2,則 indices[idx1] != indices[idx2]。這確保輸出值不取決於疊代順序。
此運算子是 GatherND 的相反運算。
範例 1
data = [1, 2, 3, 4, 5, 6, 7, 8]
indices = [[4], [3], [1], [7]]
updates = [9, 10, 11, 12]
output = [1, 11, 3, 10, 9, 6, 7, 12]
範例 2
data = [[[1, 2, 3, 4], [5, 6, 7, 8], [8, 7, 6, 5], [4, 3, 2, 1]],
[[1, 2, 3, 4], [5, 6, 7, 8], [8, 7, 6, 5], [4, 3, 2, 1]],
[[8, 7, 6, 5], [4, 3, 2, 1], [1, 2, 3, 4], [5, 6, 7, 8]],
[[8, 7, 6, 5], [4, 3, 2, 1], [1, 2, 3, 4], [5, 6, 7, 8]]]
indices = [[0], [2]]
updates = [[[5, 5, 5, 5], [6, 6, 6, 6], [7, 7, 7, 7], [8, 8, 8, 8]],
[[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3], [4, 4, 4, 4]]]
output = [[[5, 5, 5, 5], [6, 6, 6, 6], [7, 7, 7, 7], [8, 8, 8, 8]],
[[1, 2, 3, 4], [5, 6, 7, 8], [8, 7, 6, 5], [4, 3, 2, 1]],
[[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3], [4, 4, 4, 4]],
[[8, 7, 6, 5], [4, 3, 2, 1], [1, 2, 3, 4], [5, 6, 7, 8]]]
輸入¶
data (異質) - T
等級 r >= 1 的張量。
indices (異質) - tensor(int64)
等級 q >= 1 的張量。
updates (異質) - T
等級 q + r - indices_shape[-1] - 1 的張量。
輸出¶
output (異質) - T
等級 r >= 1 的張量。
類型約束¶
T in (
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)
)將輸入和輸出類型限制為任何張量類型。