MCPcopy Create free account
hub / github.com/pytorch/executorch / TensorLayout

Class TensorLayout

exir/tensor_layout.py:21–39  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

19# executorch/extension/flat_tensor/serialize/flat_tensor.fbs
20@dataclass
21class TensorLayout:
22 scalar_type: ScalarType
23 sizes: List[int]
24 dim_order: List[int]
25
26 @classmethod
27 def from_tensor(cls, tensor: torch.Tensor) -> "TensorLayout":
28 if not (
29 tensor.is_contiguous(memory_format=torch.contiguous_format)
30 or tensor.is_contiguous(memory_format=torch.channels_last)
31 ):
32 raise ValueError(
33 "Tensor is not contiguous. Please call .contiguous() before creating the TensorLayout."
34 )
35 return TensorLayout(
36 scalar_type=scalar_type_enum(tensor.dtype),
37 sizes=list(tensor.shape),
38 dim_order=list(dim_order_from_stride(tensor.stride())),
39 )

Calls

no outgoing calls