MCPcopy Create free account
hub / github.com/pytorch/pytorch / insert_arg

Method insert_arg

torch/fx/node.py:370–391  ·  view source on GitHub ↗

Insert an positional argument to the argument list with given index. Args: idx (int): The index of the element in ``self.args`` to be inserted before. arg (Argument): The new argument value to insert into ``args``

(self, idx : int, arg : Argument)

Source from the content-addressed store, hash-verified

368
369 @compatibility(is_backward_compatible=True)
370 def insert_arg(self, idx : int, arg : Argument) -> None:
371 """
372 Insert an positional argument to the argument list with given index.
373
374 Args:
375
376 idx (int): The index of the element in ``self.args`` to be inserted before.
377 arg (Argument): The new argument value to insert into ``args``
378 """
379 assert 0 <= idx <= len(self.args), "insert_args index must be between 0 and len(self.args)"
380 args_left = self.args[:idx]
381 args_right = self.args[idx:]
382
383 self._args = args_left + (arg,) + args_right
384
385 _new_input_nodes = {}
386 map_arg(arg, _new_input_nodes.setdefault)
387
388 for new_use in _new_input_nodes.keys():
389 if new_use not in self._input_nodes:
390 self._input_nodes.setdefault(new_use)
391 new_use.users.setdefault(self)
392
393 @compatibility(is_backward_compatible=True)
394 def update_kwarg(self, key : str, arg : Argument) -> None:

Callers 2

remap_inputMethod · 0.80
test_insert_argMethod · 0.80

Calls 3

map_argFunction · 0.70
keysMethod · 0.45
setdefaultMethod · 0.45

Tested by 1

test_insert_argMethod · 0.64