graph
最后更新
luxonis_ml.utils.graph函数
is_acyclic
Python
1def is_acyclic(graph: dict[str, list[str]]) -> bool:示例
Pycon
1>>> is_acyclic({"a": ["b"], "b": []})
2True
3>>> is_acyclic({"a": ["b"], "b": ["a"]})
4False
5>>> is_acyclic({})
6Truegraph(dict[str, list[str]]): 表示为前驱字典的图。
bool: 如果图是无环的,则为True,否则为False。
traverse_graph
Python
1def traverse_graph(graph: dict[str, list[str]], nodes: Mapping[str, T]) -> Iterator[tuple[str, T, list[str], list[str]]]:示例
Pycon
1>>> graph = {"a": ["b"], "b": []}
2>>> nodes = {"a": 1, "b": 2}
3>>> for name, value, preds, rem in traverse_graph(graph, nodes):
4... print(name, value, preds, rem)
5b 2 [] ['a']
6a 1 ['b'] []graph(dict[str, list[str]]): 表示为前驱字典的图。键是节点名称,值是节点前驱。nodes(Mapping[str, T]): 将节点名称映射到值的字典。
Iterator[tuple[str, T, list[str], list[str]]]
- 包含节点名称、节点值、节点前驱和剩余未处理节点的元组。
RuntimeError: 如果图格式不正确。