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

Function _arange_handler

backends/mlx/ops.py:2082–2116  ·  view source on GitHub ↗

Handle arange with just stop, or (start, stop) or (start, stop, step). Supports both static (literal int) and dynamic (Slot from item()) values.

(P: MLXProgramBuilder, n: Node)

Source from the content-addressed store, hash-verified

2080
2081@REGISTRY.register(target=[torch.ops.aten.arange.default])
2082def _arange_handler(P: MLXProgramBuilder, n: Node) -> Slot:
2083 """Handle arange with just stop, or (start, stop) or (start, stop, step).
2084
2085 Supports both static (literal int) and dynamic (Slot from item()) values.
2086 """
2087 args = P.args(n)
2088 kwargs = P.kwargs(n)
2089 require_args(args, 1, 3, "aten.arange")
2090 require_kwargs(kwargs, {"dtype", "layout", "device", "pin_memory"}, "aten.arange")
2091 require_contiguous_format(
2092 layout=kwargs.get("layout"),
2093 op_name="aten.arange",
2094 )
2095 if len(args) == 1:
2096 start = 0
2097 stop = args[0]
2098 else:
2099 start, stop = args[0:2]
2100 step = args[2] if len(args) > 2 else 1
2101
2102 # arange defaults to int64 when dtype is not specified (like torch.arange)
2103 dtype = kwargs.get("dtype", torch.int64)
2104 scalar_type_val = torch_dtype_to_scalar_type(dtype)
2105
2106 out = P.make_or_get_slot(n)
2107 P.emit(
2108 ARangeNode(
2109 out=P.slot_to_tid(out),
2110 start=P.to_int_or_vid(start),
2111 stop=P.to_int_or_vid(stop),
2112 step=P.to_int_or_vid(step),
2113 scalar_type=scalar_type_val,
2114 )
2115 )
2116 return out
2117
2118
2119@REGISTRY.register(target=[torch.ops.aten.arange.start_step])

Callers

nothing calls this directly

Calls 11

require_argsFunction · 0.85
require_kwargsFunction · 0.85
argsMethod · 0.80
kwargsMethod · 0.80
emitMethod · 0.80
slot_to_tidMethod · 0.80
to_int_or_vidMethod · 0.80
getMethod · 0.45
make_or_get_slotMethod · 0.45

Tested by

no test coverage detected