-
Notifications
You must be signed in to change notification settings - Fork 9
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
Optimize Loop in Unify #185
Conversation
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.
Mostly looks good. Just one issue that needs to be addressed to ensure we don't run into unexpected (and possibly undefined) behavior.
thicket/ensemble.py
Outdated
for cur_id, cur_node in old_to_new.items(): | ||
new_id = id(cur_node) | ||
if new_id in temp_dict: | ||
old_to_new[cur_id] = temp_dict[new_id] |
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.
Never update the thing you are iterating over. You may get lucky, but 9 times out of 10, this is at best undefined behavior.
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.
Good catch I messed up when converting it from a function a1479b3
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.
LGTM
@pearce8 this PR is ready for your review |
304a416
to
f1e0e4e
Compare
* Optimize double for loop * Remove functions * Fix bug * Improve variable names for clarity * Change list to set * Rm space
* Optimize double for loop * Remove functions * Fix bug * Improve variable names for clarity * Change list to set * Rm space
* Optimize double for loop * Remove functions * Fix bug * Improve variable names for clarity * Change list to set * Rm space
This PR:
_merge_dicts
and_replace_graph_df_nodes
by removing the functions and putting the code inline.old_to_new
andtemp_dict
fromO(n^2)
toO(n)
. This was an oversight during original implementation.The performance improvements of this PR are documented in #170. #170 avoids needing to merge dictionaries as it only calls
concat_thickets
with 2 Thickets, however using theconcat_thickets
function with 3 or more Thickets will still benefit from this PR.This PR is better for fewer files with many nodes, while #170 is better for many files since it avoids merging
old_to_new
andtemp_dict
.