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.'
|
assert dtype, 'For source type Node a dtype argument is required.'
|
||||||
self.dtype = dtype
|
self.dtype = dtype
|
||||||
elif isinstance(source, float):
|
elif isinstance(source, float):
|
||||||
self.source = CPConstant(source)
|
self.source = CPConstant(source, False)
|
||||||
self.dtype = 'float'
|
self.dtype = 'float'
|
||||||
elif isinstance(source, bool):
|
elif isinstance(source, bool):
|
||||||
self.source = CPConstant(source)
|
self.source = CPConstant(source, False)
|
||||||
self.dtype = 'bool'
|
self.dtype = 'bool'
|
||||||
else:
|
else:
|
||||||
self.source = CPConstant(source)
|
self.source = CPConstant(source, False)
|
||||||
self.dtype = 'int'
|
self.dtype = 'int'
|
||||||
self.volatile = volatile
|
self.volatile = volatile
|
||||||
|
|
||||||
|
|
@ -332,11 +332,11 @@ class value(Generic[TNum], Net):
|
||||||
|
|
||||||
|
|
||||||
class CPConstant(Node):
|
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.dtype, self.value = _get_data_and_dtype(value)
|
||||||
self.name = 'const_' + self.dtype
|
self.name = 'const_' + self.dtype
|
||||||
self.args = tuple()
|
self.args = tuple()
|
||||||
self.node_hash = id(self)
|
self.node_hash = hash(value) if constant else id(self)
|
||||||
|
|
||||||
|
|
||||||
class Write(Node):
|
class Write(Node):
|
||||||
|
|
|
||||||
|
|
@ -102,11 +102,14 @@ def get_all_dag_edges(nodes: Iterable[Node]) -> Generator[tuple[Node, Node], Non
|
||||||
Tuples of (source_node, target_node) representing edges in the DAG
|
Tuples of (source_node, target_node) representing edges in the DAG
|
||||||
"""
|
"""
|
||||||
emitted_edges: set[tuple[Node, Node]] = set()
|
emitted_edges: set[tuple[Node, Node]] = set()
|
||||||
|
used_nets: set[Net] = set()
|
||||||
node_list: list[Node] = [n for n in nodes]
|
node_list: list[Node] = [n for n in nodes]
|
||||||
|
|
||||||
while(node_list):
|
while(node_list):
|
||||||
node = node_list.pop()
|
node = node_list.pop()
|
||||||
for net in node.args:
|
for net in node.args:
|
||||||
|
if net not in used_nets:
|
||||||
|
used_nets.add(net)
|
||||||
edge = (net.source, node)
|
edge = (net.source, node)
|
||||||
if edge not in emitted_edges:
|
if edge not in emitted_edges:
|
||||||
yield edge
|
yield edge
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue