You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Speed up to_3di() by avoiding masked arrays in partner search - #1018
PartnerIndexEncoder._find_residue_partners() built the O(n²) pairwise distance matrix with numpy.ma operations (ma.dot, masked arithmetic, nan_to_num on a masked array). Those dominated to_3di().
Now the matrix is computed on plain arrays: masked residues are set to NaN (which becomes inf, like the masked entries that argmin() filled with inf before), and nan_to_num(nan=inf) is replaced by an equivalent clip() + NaN assignment. The partner search itself becomes ~3.8x faster (0.54 -> 0.14 ms, 213 residues).
to_3di(), model 1, amino acids only:
Input
Longest chain
Before
After
Speedup
4ZXB (5 chains)
800 res
13.0 ms
5.8 ms
2.2x
5H73
363 res
2.13 ms
0.96 ms
2.2x
5UGO
326 res
1.82 ms
0.89 ms
2.1x
1IGY (4 chains)
434 res
7.67 ms
3.72 ms
2.1x
1DIX
208 res
1.03 ms
0.58 ms
1.8x
1AKI
129 res
0.68 ms
0.45 ms
1.5x
The speedup grows with chain length (the quadratic part); for short chains the remaining per-chain overhead dominates.
Output checked identical to main (codes and PartnerIndexEncoder.encode() results) for all structures in tests/structure/data/pdb, including variants with randomly removed atoms to produce masked residues (also at the first position).
Merging this PR will improve performance by 91.22%
1 warning
⚠️17 benchmarks with a significant change ran on different hardware
Their base and head results were measured on machines with a different CPU, core count or memory, so the changes might not come from the code. Run base and head on the same runner type.
No successful run was found on main (b0d32ca) during the generation of this report, so 81df912 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩
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
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.
PartnerIndexEncoder._find_residue_partners()built the O(n²) pairwise distance matrix withnumpy.maoperations (ma.dot, masked arithmetic,nan_to_numon a masked array). Those dominatedto_3di().Now the matrix is computed on plain arrays: masked residues are set to NaN (which becomes
inf, like the masked entries thatargmin()filled withinfbefore), andnan_to_num(nan=inf)is replaced by an equivalentclip()+ NaN assignment. The partner search itself becomes ~3.8x faster (0.54 -> 0.14 ms, 213 residues).to_3di(), model 1, amino acids only:The speedup grows with chain length (the quadratic part); for short chains the remaining per-chain overhead dominates.
Output checked identical to
main(codes andPartnerIndexEncoder.encode()results) for all structures intests/structure/data/pdb, including variants with randomly removed atoms to produce masked residues (also at the first position).Tests:
tests/structure/alphabetAuthored by Claude