Skip to content
This repository has been archived by the owner on Dec 10, 2024. It is now read-only.

Commit

Permalink
minor optimize, we stop here
Browse files Browse the repository at this point in the history
  • Loading branch information
iopapamanoglou committed Nov 7, 2024
1 parent 412554c commit d51c18c
Showing 1 changed file with 23 additions and 22 deletions.
45 changes: 23 additions & 22 deletions src/faebryk/core/moduleinterface.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,44 +131,37 @@ def __init__(self):
def __preinit__(self) -> None: ...

@staticmethod
def _get_connected(gif: GraphInterface):
def _get_connected(gif: GraphInterface, clss: bool):
assert isinstance(gif.node, ModuleInterface)
connections = gif.edges.items()

# check if ambiguous links between mifs
assert len(connections) == len({c[0] for c in connections})

return {
cast_assert(ModuleInterface, s.node): link
cast_assert(ModuleInterface, s.node): (link if not clss else type(link))
for s, link in connections
if s.node is not gif.node
}

def get_connected(self):
return self._get_connected(self.connected)
def get_connected(self, clss: bool = False):
return self._get_connected(self.connected, clss)

def get_specialized(self):
return self._get_connected(self.specialized)
def get_specialized(self, clss: bool = False):
return self._get_connected(self.specialized, clss)

def get_specializes(self):
return self._get_connected(self.specializes)
def get_specializes(self, clss: bool = False):
return self._get_connected(self.specializes, clss)

@staticmethod
def _cross_connect(
s_group_: dict["ModuleInterface", type[Link] | Link],
d_group_: dict["ModuleInterface", type[Link] | Link],
s_group: dict["ModuleInterface", type[Link]],
d_group: dict["ModuleInterface", type[Link]],
linkcls: type[Link],
hint=None,
):
if logger.isEnabledFor(logging.DEBUG) and hint is not None:
logger.debug(f"Connect {hint} {s_group_} -> {d_group_}")

s_group: dict["ModuleInterface", type[Link]] = {
k: type(v) if not isinstance(v, type) else v for k, v in s_group_.items()
}
d_group: dict["ModuleInterface", type[Link]] = {
k: type(v) if not isinstance(v, type) else v for k, v in d_group_.items()
}
logger.debug(f"Connect {hint} {s_group} -> {d_group}")

for s, slink in s_group.items():
linkclss = {slink, linkcls}
Expand Down Expand Up @@ -203,13 +196,21 @@ def _connect_siblings_and_connections(
logger.debug(f"MIF connection: {self} to {other}")

# Connect to all connections
s_con = self.get_connected() | {self: linkcls}
d_con = other.get_connected() | {other: linkcls}
s_con = self.get_connected(clss=True) | {self: linkcls}
d_con = other.get_connected(clss=True) | {other: linkcls}
ModuleInterface._cross_connect(s_con, d_con, linkcls, "connections")

# Connect to all siblings
s_sib = self.get_specialized() | self.get_specializes() | {self: linkcls}
d_sib = other.get_specialized() | other.get_specializes() | {other: linkcls}
s_sib = (
self.get_specialized(clss=True)
| self.get_specializes(clss=True)
| {self: linkcls}
)
d_sib = (
other.get_specialized(clss=True)
| other.get_specializes(clss=True)
| {other: linkcls}
)
ModuleInterface._cross_connect(s_sib, d_sib, linkcls, "siblings")

return self
Expand Down

0 comments on commit d51c18c

Please sign in to comment.