mirror of https://github.com/Nonannet/copapy.git
auto stripping of equal graph branches added
This commit is contained in:
parent
83e74a8ae9
commit
3c5f01db7f
|
|
@ -105,13 +105,13 @@ class value(Generic[TNum], Net):
|
|||
assert dtype, 'For source type Node a dtype argument is required.'
|
||||
self.dtype = dtype
|
||||
elif isinstance(source, float):
|
||||
self.source = CPConstant(source)
|
||||
self.source = CPConstant(source, False)
|
||||
self.dtype = 'float'
|
||||
elif isinstance(source, bool):
|
||||
self.source = CPConstant(source)
|
||||
self.source = CPConstant(source, False)
|
||||
self.dtype = 'bool'
|
||||
else:
|
||||
self.source = CPConstant(source)
|
||||
self.source = CPConstant(source, False)
|
||||
self.dtype = 'int'
|
||||
self.volatile = volatile
|
||||
|
||||
|
|
@ -332,11 +332,11 @@ class value(Generic[TNum], Net):
|
|||
|
||||
|
||||
class CPConstant(Node):
|
||||
def __init__(self, value: int | float):
|
||||
def __init__(self, value: int | float, constant: bool = True):
|
||||
self.dtype, self.value = _get_data_and_dtype(value)
|
||||
self.name = 'const_' + self.dtype
|
||||
self.args = tuple()
|
||||
self.node_hash = id(self)
|
||||
self.node_hash = hash(value) if constant else id(self)
|
||||
|
||||
|
||||
class Write(Node):
|
||||
|
|
|
|||
|
|
@ -102,16 +102,19 @@ def get_all_dag_edges(nodes: Iterable[Node]) -> Generator[tuple[Node, Node], Non
|
|||
Tuples of (source_node, target_node) representing edges in the DAG
|
||||
"""
|
||||
emitted_edges: set[tuple[Node, Node]] = set()
|
||||
used_nets: set[Net] = set()
|
||||
node_list: list[Node] = [n for n in nodes]
|
||||
|
||||
while(node_list):
|
||||
node = node_list.pop()
|
||||
for net in node.args:
|
||||
edge = (net.source, node)
|
||||
if edge not in emitted_edges:
|
||||
yield edge
|
||||
node_list.append(net.source)
|
||||
emitted_edges.add(edge)
|
||||
if net not in used_nets:
|
||||
used_nets.add(net)
|
||||
edge = (net.source, node)
|
||||
if edge not in emitted_edges:
|
||||
yield edge
|
||||
node_list.append(net.source)
|
||||
emitted_edges.add(edge)
|
||||
|
||||
|
||||
def get_const_nets(nodes: list[Node]) -> list[Net]:
|
||||
|
|
|
|||
Loading…
Reference in New Issue