MCPcopy Create free account
hub / github.com/waleedka/hiddenlayer / apply

Method apply

hiddenlayer/transforms.py:128–143  ·  view source on GitHub ↗
(self, graph)

Source from the content-addressed store, hash-verified

126 self.tag(n, tag, graph, conditional=True)
127
128 def apply(self, graph):
129 # Copy the graph. Don't change the original.
130 graph = copy.deepcopy(graph)
131
132 while True:
133 matches, _ = graph.search(self.pattern)
134 if not matches:
135 break
136 # Tag found nodes and their incoming branches
137 for n in matches:
138 self.tag(n, "delete", graph)
139 # Find all tagged nodes and delete them
140 tagged = [n for n in graph.nodes.values()
141 if hasattr(n, "__tag__") and n.__tag__ == "delete"]
142 graph.remove(tagged)
143 return graph
144
145
146class FoldDuplicates():

Callers 1

test_prune_branchMethod · 0.95

Calls 3

tagMethod · 0.95
searchMethod · 0.80
removeMethod · 0.80

Tested by 1

test_prune_branchMethod · 0.76