Skip to content

perf(coordinates): optimize trajectory boolean indexing using flatnonzero (#1982) - #5500

Open
dhrubchatterjee16-lang wants to merge 1 commit into
MDAnalysis:developfrom
dhrubchatterjee16-lang:fast-bool-frames-1982
Open

dhrubchatterjee16-lang wants to merge 1 commit into
MDAnalysis:developfrom
dhrubchatterjee16-lang:fast-bool-frames-1982

Conversation

@dhrubchatterjee16-lang

@dhrubchatterjee16-lang dhrubchatterjee16-lang commented Oct 20, 2026 •

Copy link
Copy Markdown

Fixes #1982

Changes made in this Pull Request:

  • In MDAnalysis.coordinates.base.ProtoReader.__getitem__, replaced np.arange(len(self))[frame] with np.flatnonzero(frame) when indexing with boolean masks, avoiding unnecessary intermediate array memory allocation and speeding up trajectory boolean indexing (7x–20x benchmarked speedup).
  • Added mask dimension and length validation (len(frame) == len(self) and frame.ndim == 1), raising IndexError on mismatch to preserve standard NumPy indexing semantics.
  • Added comprehensive unit tests in MDAnalysisTests.coordinates.test_reader_api covering boolean mask indexing and length mismatch exceptions.
  • Updated package/CHANGELOG under Enhancements.
  • Added my name to package/AUTHORS.

LLM / AI generated code disclosure

LLMs or other AI-powered tools (beyond simple IDE use cases) were used in this contribution: yes

PR Checklist

  • Issue raised/referenced?
  • Tests updated/added?
  • Documentation updated/added?
  • package/CHANGELOG file updated?
  • Is your name in package/AUTHORS? (If it is not, add it!)
  • I have read and understand the current AI Policy
  • LLM/AI disclosure was updated.

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.

@read-the-docs-community

read-the-docs-community Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

@codecov

codecov Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.92%. Comparing base (ae9ff4b) to head (74fa9c2).

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #5500   +/-   ##
========================================
  Coverage    93.92%   93.92%           
========================================
  Files          184      184           
  Lines        22661    22663    +2     
  Branches      3223     3224    +1     
========================================
+ Hits         21284    21286    +2     
  Misses         917      917           
  Partials       460      460           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@IAlibay IAlibay 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.

@dhrubchatterjee16-lang we require PRs to provide the information that is in the PR template before we review them. Please add the information back.

@dhrubchatterjee16-lang

Copy link
Copy Markdown
Author

Hi @IAlibay i have updated the PRs template. Please let me know if you would like me to adjust anything.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Quick function for converting bool array to frame indices

2 participants