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

Function get_memory_format

exir/dim_order_utils.py:34–49  ·  view source on GitHub ↗

Given a dim_order try to map it to torch.memory_format

(dim_order: Optional[List[int]])

Source from the content-addressed store, hash-verified

32
33
34def get_memory_format(dim_order: Optional[List[int]]) -> torch.memory_format:
35 """
36 Given a dim_order try to map it to torch.memory_format
37 """
38 if dim_order is None:
39 return torch.preserve_format
40 elif dim_order == _get_contiguous_dim_order(len(dim_order)):
41 return torch.contiguous_format
42 elif len(dim_order) == 4 and dim_order == _get_channels_last_dim_order(
43 len(dim_order)
44 ):
45 return torch.channels_last
46
47 raise AssertionError(
48 f"Failed to map a given dim_order: {dim_order} to a torch.memory_format"
49 )
50
51
52def get_dim_order(

Callers 6

_op_implFunction · 0.90
call_operatorMethod · 0.90
_to_dim_order_copyFunction · 0.90
_clone_dim_orderFunction · 0.90

Calls 2

Tested by 2