Improve performance of wrap method#5226
Open
hejamu wants to merge 5 commits intoMDAnalysis:developfrom
Open
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #5226 +/- ##
===========================================
- Coverage 93.83% 93.82% -0.01%
===========================================
Files 180 180
Lines 22475 22473 -2
Branches 3190 3189 -1
===========================================
- Hits 21090 21086 -4
- Misses 923 924 +1
- Partials 462 463 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
orbeckst
reviewed
Feb 6, 2026
Member
orbeckst
left a comment
There was a problem hiding this comment.
This looks good but I didn't have time to dive into it. Can you confirm that it produces the same results? I know that the tests covered it but did you look if the tests for it actually likely to find any disagreement?
Contributor
Author
|
The tests are already quite comprehensive. I only noticed that the tests do not check whether it also works with non-contiguous compound indexes. Since the current code and the PR use fancy-indexing, I added such a test. |
Contributor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Changes made in this Pull Request:
The method was significantly slower than expected when wrapping compounds (residues, fragments, molecules, segments). See the corresponding issue on the MAICoS repo.
It just never got the same performance increases as for example
unwrap. I considered using the_split_by_compound_indicesapproach fromunwrap, but that is actually not needed for wrapping. Simply calculating the shifts and applying them in one go yields an enormous speed up. Most the performance penalty actually came from thenp.wheredone in each loop I believe.Here is a scaling plot comparing the speeds:
LLM / AI generated code disclosure
LLMs or other AI-powered tools (beyond simple IDE use cases) were used in this contribution: no
PR Checklist
package/CHANGELOGfile updated?package/AUTHORS? (If it is not, add it!)Developers Certificate of Origin
I certify that I can submit this code contribution as described in the Developer Certificate of Origin, under the MDAnalysis LICENSE.