-
Notifications
You must be signed in to change notification settings - Fork 829
Optimize inverse index mapping in groups.py (Fixes Issue #3387) #5252
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
Changes from 3 commits
d07e964
463a1ec
7724ba3
d62eecd
fa8ad6c
9ae78cb
fd97d19
f56d246
fcb4931
e22709e
97f112c
50ac687
eede57e
e1df729
111da56
fc3f507
c1c39a3
e697b56
fd67b0f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -42,6 +42,9 @@ Enhancements | |
| * Adds support for parsing `.tpr` files produced by GROMACS 2026.0 | ||
| * Enables parallelization for analysis.diffusionmap.DistanceMatrix | ||
| (Issue #4679, PR #4745) | ||
| * Improve performance of inverse index mapping in AtomGroup by | ||
| replacing O(n^2) logic with optimized Cython implementation. | ||
| (Issue #3387, PR #5252) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add at the top of each section — that's just how we've done things historically. One of the little things you learn in PRs...
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. mention the new function |
||
|
|
||
| Changes | ||
| * The msd.py inside analysis is changed, and ProgressBar is implemented inside | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -37,7 +37,7 @@ from cython.operator cimport dereference as deref | |
|
|
||
| cnp.import_array() | ||
|
|
||
| __all__ = ['unique_int_1d', 'make_whole', 'find_fragments', | ||
| __all__ = ['unique_int_1d', 'inverse_int_index', 'make_whole', 'find_fragments', | ||
| '_sarrus_det_single', '_sarrus_det_multiple'] | ||
|
|
||
| cdef extern from "calc_distances.h": | ||
|
|
@@ -91,6 +91,42 @@ def unique_int_1d(cnp.intp_t[:] values): | |
|
|
||
| return np.array(result) | ||
|
|
||
| @cython.boundscheck(False) | ||
| @cython.wraparound(False) | ||
| def inverse_int_index(cnp.intp_t[:] values, | ||
| cnp.intp_t[:] unique_vals): | ||
| """ | ||
| Construct inverse index map such that: | ||
|
|
||
| unique_vals[mask] == values | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Add a simple example in the docs below (look at https://userguide.mdanalysis.org/stable/contributing_code.html#working-with-the-code-documentation for how to structure doc strings using the numpy docstring standard)
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've now added a proper docstring for this function which includes the description of the function, the parameters, the return value and an example. |
||
|
|
||
| Parameters | ||
| ---------- | ||
| values : numpy.ndarray | ||
| 1D array of integers. | ||
| unique_vals : numpy.ndarray | ||
| 1D array of unique integers (unsorted). | ||
|
|
||
| Returns | ||
| ------- | ||
| numpy.ndarray | ||
| Integer mask mapping values -> index in unique_vals. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add a .. versionadded:: 2.11.0Make sure that there are TWO blank lines separating this line from the rest.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've added a |
||
| """ | ||
|
|
||
| cdef Py_ssize_t n = values.shape[0] | ||
| cdef Py_ssize_t m = unique_vals.shape[0] | ||
| cdef Py_ssize_t i | ||
|
|
||
| cdef dict lookup = {} | ||
| cdef cnp.intp_t[:] mask = np.empty(n, dtype=np.intp) | ||
|
|
||
| for i in range(m): | ||
| lookup[unique_vals[i]] = i | ||
|
|
||
| for i in range(n): | ||
| mask[i] = lookup[values[i]] | ||
|
|
||
| return np.array(mask) | ||
|
|
||
| @cython.boundscheck(False) | ||
| def _in2d(cnp.intp_t[:, :] arr1, cnp.intp_t[:, :] arr2): | ||
|
|
@@ -515,4 +551,4 @@ def find_fragments(atoms, bondlist): | |
| # Add fragment to output | ||
| frags.append(np.asarray(this_frag)) | ||
|
|
||
| return frags | ||
| return frags | ||
|
orbeckst marked this conversation as resolved.
|
||
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.
Please add yourself at the end (although I believe you already contributed another PR so you might just have to ensure that you're not showing up twice).