-
Notifications
You must be signed in to change notification settings - Fork 27
CycleError: Report all nodes #159
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 5 commits
2bceb52
bf70743
c39afca
1462f72
842c69b
c79b0bd
8823bca
47aa316
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -213,9 +213,17 @@ class CycleError(Exception): | |
| Raised when a topological ordering cannot be computed due to a cycle. | ||
|
|
||
| :attr node: Node in a directed graph that is part of a cycle. | ||
|
|
||
| :attr nodes: List of nodes in a directed graph that are part of a cycle. | ||
| """ | ||
| def __init__(self, node: T) -> None: | ||
| self.node = node | ||
| def __init__(self, nodes: List[T]) -> None: | ||
| self.node = nodes[0] | ||
| self.nodes = nodes | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This breaks backward compatibility.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How can I avoid that - maybe by providing a
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What do you think of c39afca?
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think a better approach would be to make
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Implemented in 8823bca
inducer marked this conversation as resolved.
Outdated
|
||
|
|
||
| def __str__(self) -> str: | ||
| le = len(self.nodes) | ||
| mlen = 10 | ||
| return f"{[n for n in self.nodes[:mlen]] + (['...'] if le > mlen else [])}" | ||
|
|
||
|
|
||
| class HeapEntry: | ||
|
|
@@ -299,8 +307,8 @@ def compute_topological_order(graph: Mapping[T, Collection[T]], | |
|
|
||
| if len(order) != total_num_nodes: | ||
| # any node which has a predecessor left is a part of a cycle | ||
| raise CycleError(next(iter(n for n, num_preds in | ||
| nodes_to_num_predecessors.items() if num_preds != 0))) | ||
| raise CycleError(list(n for n, num_preds in | ||
| nodes_to_num_predecessors.items() if num_preds != 0)) | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be nice to provide this in traversable (rather than arbitrary) order, which is doable at
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure how to do that - how would we provide this in case there are multiple cycles in the graph?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. #167 has some work in this direction |
||
|
|
||
| return order | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe
pathis a better name. Also state that we claim thatnode[i+1]inpathis a successor ofnode[i](and test that!).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed it to
pathsand added comment regarding the successors in 47aa316.Testing this is done in #167 right?