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

Function require_contiguous_format

backends/mlx/ops.py:266–301  ·  view source on GitHub ↗

Validate that layout/memory_format/dim_order specify contiguous format. MLX only supports contiguous (strided) tensors. Raises ValueError if sparse layouts or non-contiguous memory formats are requested. Args: layout: The torch layout (e.g., torch.strided, torch.sparse_coo

(
    *,
    layout=None,
    memory_format=None,
    dim_order=None,
    op_name: str,
)

Source from the content-addressed store, hash-verified

264
265
266def require_contiguous_format(
267 *,
268 layout=None,
269 memory_format=None,
270 dim_order=None,
271 op_name: str,
272) -> None:
273 """
274 Validate that layout/memory_format/dim_order specify contiguous format.
275
276 MLX only supports contiguous (strided) tensors. Raises ValueError if
277 sparse layouts or non-contiguous memory formats are requested.
278
279 Args:
280 layout: The torch layout (e.g., torch.strided, torch.sparse_coo)
281 memory_format: The torch memory format (e.g., torch.contiguous_format,
282 torch.channels_last)
283 dim_order: The dimension order (list of ints, identity = contiguous)
284 op_name: Name of the operation (for error message)
285 """
286 if layout is not None and layout != torch.strided:
287 raise ValueError(f"{op_name}: only strided layout supported, got {layout}")
288
289 if memory_format is not None and memory_format not in (
290 torch.contiguous_format,
291 torch.preserve_format,
292 ):
293 raise ValueError(
294 f"{op_name}: only contiguous memory format supported, got {memory_format}"
295 )
296
297 if dim_order is not None:
298 if list(dim_order) != list(range(len(dim_order))):
299 raise ValueError(
300 f"{op_name}: only contiguous dim_order supported, got {dim_order}"
301 )
302
303
304def is_static_value(value: Any) -> bool:

Callers 8

handlerFunction · 0.85
_clone_handlerFunction · 0.85
_dim_order_clone_handlerFunction · 0.85
_dim_order_copy_handlerFunction · 0.85
_to_copy_handlerFunction · 0.85
_arange_handlerFunction · 0.85
_scalar_tensor_handlerFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected