MCPcopy
hub / github.com/OpenPPL/ppq / insert_op_before

Method insert_op_before

ppq/IR/base/graph.py:416–439  ·  view source on GitHub ↗

Insert an op just before given op. This function will insert given op A to variable B.inputs[input_idx] Args: A (Operation): Inserting Op, should has no input and output variable that links to it. B (Operation): before this op. input_idx

(self, A: Operation, B: Operation, input_idx: int = 0)

Source from the content-addressed store, hash-verified

414 raise Exception('This Function is removed from PPQ Since 0.6.6')
415
416 def insert_op_before(self, A: Operation, B: Operation, input_idx: int = 0):
417 """
418 Insert an op just before given op.
419 This function will insert given op A to variable B.inputs[input_idx]
420
421 Args:
422 A (Operation): Inserting Op, should has no input and output variable that links to it.
423 B (Operation): before this op.
424 input_idx (int, optional): For case that B has more than 1 input variable,
425 user should use parameter input_idx to identify which variable is used.
426 """
427 if input_idx >= B.num_of_input:
428 raise ValueError('Input index out of range.')
429 if A.num_of_input != 0 or A.num_of_output != 0:
430 raise ValueError('Can only insert op that has no input and output variable.')
431 var = B.inputs[input_idx]
432
433 var.dest_ops[var.dest_ops.index(B)] = A
434 B.inputs[input_idx] = self.create_variable()
435 B.inputs[input_idx].source_op = A
436 B.inputs[input_idx].dest_ops.append(B)
437
438 A.inputs.append(var)
439 A.outputs.append(B.inputs[input_idx])
440
441 def insert_op_after(self, A: Operation, B: Operation, output_idx: int = 0):
442 """

Callers 4

insert_quantize_nodeMethod · 0.80
insert_quantize_nodeMethod · 0.80

Calls 2

create_variableMethod · 0.95
appendMethod · 0.45

Tested by

no test coverage detected