(cls, tensor: torch.Tensor)
| 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 | ) |
nothing calls this directly
no test coverage detected