Skip to content

avoid iteration and use boolean indexing - #7591

Merged
dschult merged 2 commits into
networkx:mainfrom
buddih09:similarity-improve-code-runtime
Aug 15, 2024
Merged

dschult merged 2 commits into
networkx:mainfrom
buddih09:similarity-improve-code-runtime

Conversation

@buddih09

@buddih09 buddih09 commented Aug 5, 2024

Copy link
Copy Markdown
Contributor

Removed iteration and instead used efficient boolean masking to improve the code performance

@rossbar rossbar left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm +1 on the approach here. Ultimately, I doubt this will have much of an impact on performance given how many subsequent computations are involved in optimizing edit paths. Nevertheless I think the improvement in readability is a good argument for using boolean masks as opposed to manually filtering indices.

Technically the proposed changes will double the memory footprint (two temporary arrays are created in constructing the masks), but since these are 1D arrays of indices I doubt that will have a practical impact for most use-cases, so I don't think that's a blocker either.

Thanks @buddih09 !

Comment thread networkx/algorithms/similarity.py Resolved

@dschult dschult left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me -- Thanks @buddih09

@dschult
dschult merged commit 9c3b390 into networkx:main Aug 15, 2024
rossbar pushed a commit to Peiffap/networkx that referenced this pull request Sep 6, 2024
* avoid iteration and use boolean indexing

* assert removed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

4 participants