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

Function normalize_reduction_dim

backends/mlx/ops.py:326–355  ·  view source on GitHub ↗

Normalize dim argument for reduction operations. Extracts and normalizes the dim argument from handler args, returning a list of axes and the keepdim flag. Handles both list-based dims (e.g., sum.dim_IntList) and single int dims (e.g., prod.dim_int). Args: args: The ha

(
    args: List[Any], start_idx: int = 1
)

Source from the content-addressed store, hash-verified

324
325
326def normalize_reduction_dim(
327 args: List[Any], start_idx: int = 1
328) -> Tuple[Optional[List[int]], bool]:
329 """
330 Normalize dim argument for reduction operations.
331
332 Extracts and normalizes the dim argument from handler args, returning a list of axes
333 and the keepdim flag. Handles both list-based dims (e.g., sum.dim_IntList) and
334 single int dims (e.g., prod.dim_int).
335
336 Args:
337 args: The handler args list
338 start_idx: Index where the dim argument starts (default 1, after self)
339
340 Returns:
341 Tuple of (axes, keepdim) where:
342 - axes: List of dimension indices, or empty list for reduce-all
343 - keepdim: Boolean keepdim flag (default False)
344 """
345 if len(args) > start_idx and isinstance(args[start_idx], (list, tuple)):
346 dim = list(args[start_idx])
347 keepdim = args[start_idx + 1] if len(args) > start_idx + 1 else False
348 elif len(args) > start_idx and isinstance(args[start_idx], int):
349 dim = [args[start_idx]]
350 keepdim = args[start_idx + 1] if len(args) > start_idx + 1 else False
351 else:
352 dim = []
353 keepdim = False
354
355 return dim, keepdim
356
357
358_UNARY_OPS: List[Tuple[Any, Any, str]] = [

Callers 3

handlerFunction · 0.85
_var_handlerFunction · 0.85
_std_handlerFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected