torch.Tensor.dim_order¶
- Tensor.dim_order(ambiguity_check=False) tuple[原始碼][原始碼]¶
返回描述
self的維度順序或物理佈局的唯一確定的 int 元組。維度順序表示密集 tensor 的維度如何在記憶體中佈局,從最外層維度到最內層維度。
請注意,維度順序可能並不總是唯一確定。如果 ambiguity_check 為 True,當維度順序無法唯一確定時,此函式將引發 RuntimeError;如果 ambiguity_check 是記憶體格式的列表,當 tensor 無法被解釋為正好是給定的記憶體格式之一,或者無法唯一確定時,此函式將引發 RuntimeError。如果 ambiguity_check 為 False,它將返回一種合法的維度順序,而不檢查其唯一性。否則,它將引發 TypeError。
- 引數
ambiguity_check (bool 或 List[torch.memory_format]) – 維度順序歧義的檢查方法。
示例
>>> torch.empty((2, 3, 5, 7)).dim_order() (0, 1, 2, 3) >>> torch.empty((2, 3, 5, 7)).transpose(1, 2).dim_order() (0, 2, 1, 3) >>> torch.empty((2, 3, 5, 7), memory_format=torch.channels_last).dim_order() (0, 2, 3, 1) >>> torch.empty((1, 2, 3, 4)).dim_order() (0, 1, 2, 3) >>> try: ... torch.empty((1, 2, 3, 4)).dim_order(ambiguity_check=True) ... except RuntimeError as e: ... print(e) The tensor does not have unique dim order, or cannot map to exact one of the given memory formats. >>> torch.empty((1, 2, 3, 4)).dim_order( ... ambiguity_check=[torch.contiguous_format, torch.channels_last] ... ) # It can be mapped to contiguous format (0, 1, 2, 3) >>> try: ... torch.empty((1, 2, 3, 4)).dim_order(ambiguity_check="ILLEGAL") ... except TypeError as e: ... print(e) The ambiguity_check argument must be a bool or a list of memory formats.
警告
dim_order tensor API 處於實驗階段,可能會發生變化。