-
-
Notifications
You must be signed in to change notification settings - Fork 206
feat: added simple check to graph_from_literal()
#1981
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?
Conversation
graph_from_literal()
Too risky, let's wait. |
ids <- seq(along.with = v) | ||
names(ids) <- v | ||
res <- make_graph(unname(ids[edges]), n = length(v), directed = directed) | ||
if (simplify) { |
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.
why couldn't the check live inside simplify()
?
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.
i.e., could simplify()
be idempotent? https://en.wikipedia.org/wiki/Idempotence
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.
@maelle It is not idempotent because checking if a graph is simple takes time. Simplify will perform the simplification procedure either way, and this may reorder the edges of the graph, even if the graph is simple. The solution @schochastics uses here, i.e. check whether the graph is simple first, is good, and should be kept. The point is not to mess up the edge order for no good reason, and make it easier for people to add edge attributes when constructing from a literal.
It's good to note again that igraph has a cache for basic graph properties, such as whether the graph is simple. If it was cached that the graph is simple, then: is_simple()
takes O(1) times, and simplify()
does nothing.
I hope this also answers why the check should not be in simplify()
:
- Because it takes time and would slow
simplify()
down - There is already a kind of check in
simplify()
, but not for whether the graph is simple, but for whether the graph is already known to be simple (i.e. whether this is cached).
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.
thank you!! Yes, it makes sense.
Fix #824
The PR implements the suggested additional check if a graph is simple or not.
This required a lot of adjustments in the tests given that this means that the edge order was changed. I could imagine that this might lead to issues downstream so keeping this for after the 2.2 release.
cc @szhorvat is this what you intended?