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

Function _scalar_tensor_handler

backends/mlx/ops.py:3155–3190  ·  view source on GitHub ↗

This is equivalent to torch.full([], scalar, dtype=dtype).

(P: MLXProgramBuilder, n: Node)

Source from the content-addressed store, hash-verified

3153
3154@REGISTRY.register(target=[torch.ops.aten.scalar_tensor.default])
3155def _scalar_tensor_handler(P: MLXProgramBuilder, n: Node) -> Slot:
3156 """This is equivalent to torch.full([], scalar, dtype=dtype)."""
3157 args = P.args(n)
3158 kwargs = P.kwargs(n)
3159 require_args(args, 1, 1, "aten.scalar_tensor")
3160 require_kwargs(
3161 kwargs, {"dtype", "layout", "device", "pin_memory"}, "aten.scalar_tensor"
3162 )
3163 require_contiguous_format(
3164 layout=kwargs.get("layout"),
3165 op_name="aten.scalar_tensor",
3166 )
3167 scalar_value = args[0]
3168
3169 out = P.make_or_get_slot(n)
3170
3171 # Get dtype from kwargs, default to float32
3172 dtype = n.kwargs.get("dtype")
3173 if dtype is None:
3174 # Infer dtype from scalar type
3175 if isinstance(scalar_value, bool):
3176 dtype = torch.bool
3177 elif isinstance(scalar_value, int):
3178 dtype = torch.int64
3179 else:
3180 dtype = torch.float32
3181
3182 P.emit(
3183 FullNode(
3184 out=P.slot_to_tid(out),
3185 shape=[], # 0-D tensor (scalar)
3186 v=P.to_float_or_vid(scalar_value),
3187 scalar_type=torch_dtype_to_scalar_type(dtype),
3188 )
3189 )
3190 return out
3191
3192
3193@REGISTRY.register(target=[torch.ops.aten.tril.default])

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_float_or_vidMethod · 0.80
getMethod · 0.45
make_or_get_slotMethod · 0.45

Tested by

no test coverage detected