Skip to content
Snippets Groups Projects

Replaceop

Merged Oscar Gustafsson requested to merge replaceop into master
2 files
+ 12
11
Compare changes
  • Side-by-side
  • Inline
Files
2
@@ -505,8 +505,8 @@ class SFG(AbstractOperation):
return input_indexes_required
def copy_component(self, *args, **kwargs) -> GraphComponent:
return super().copy_component(
def copy(self, *args, **kwargs) -> GraphComponent:
return super().copy(
*args,
**kwargs,
inputs=self._input_operations,
@@ -594,17 +594,18 @@ class SFG(AbstractOperation):
keys.append(comp.key(output_index, comp.graph_id))
return keys
def replace_component(self, component: Operation, graph_id: GraphID) -> "SFG":
def replace_operation(self, component: Operation, graph_id: GraphID) -> "SFG":
"""
Find and replace all components matching either on GraphID, Type or both.
Then return a new deepcopy of the sfg with the replaced component.
Find and replace an operation based on GraphID.
Then return a new deepcopy of the SFG with the replaced operation.
Parameters
----------
component : Operation
The new component(s), e.g. Multiplication
The new operation(s), e.g. Multiplication
graph_id : GraphID
The GraphID to match the component to replace.
The GraphID to match the operation to replace.
"""
sfg_copy = self() # Copy to not mess with this SFG.
@@ -1029,7 +1030,7 @@ class SFG(AbstractOperation):
) -> GraphComponent:
if original_component in self._original_components_to_new:
raise ValueError("Tried to add duplicate SFG component")
new_component = original_component.copy_component()
new_component = original_component.copy()
self._original_components_to_new[original_component] = new_component
if not new_component.graph_id or new_component.graph_id in self._used_ids:
new_id = self._graph_id_generator.next_id(
@@ -1396,7 +1397,7 @@ class SFG(AbstractOperation):
# Make `factor` copies of the sfg
new_ops = [
[cast(Operation, op.copy_component()) for op in self.operations]
[cast(Operation, op.copy()) for op in self.operations]
for _ in range(factor)
]
Loading