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

Method from_tensor

exir/tensor_layout.py:27–39  ·  view source on GitHub ↗
(cls, tensor: torch.Tensor)

Source from the content-addressed store, hash-verified

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 )

Callers

nothing calls this directly

Calls 3

scalar_type_enumFunction · 0.90
dim_order_from_strideFunction · 0.90
TensorLayoutClass · 0.85

Tested by

no test coverage detected