-
Notifications
You must be signed in to change notification settings - Fork 824
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
base: develop
Are you sure you want to change the base?
Changes from all commits
d07e964
463a1ec
7724ba3
d62eecd
fa8ad6c
9ae78cb
fd97d19
f56d246
fcb4931
e22709e
97f112c
50ac687
eede57e
e1df729
111da56
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 |
|---|---|---|
|
|
@@ -45,6 +45,9 @@ Fixes | |
| DSSP by porting upstream PyDSSP 0.9.1 fix (Issue #4913) | ||
|
|
||
| Enhancements | ||
| * Improved performance of inverse index mapping in AtomGroup using an optimized | ||
| Cython implementation in lib._cutils.inverse_int_index() | ||
| (Issue #3387, PR #5252) | ||
| * Added `select=None` in `analysis.rms.RMSD` to perform no selection on | ||
| the input `atomgroup` and `reference` (Issue #5300, PR #5296) | ||
| * MOL2Parser now reads unit cell dimensions from @<TRIPOS>CRYSIN records (Issue #3341) | ||
|
|
@@ -3627,4 +3630,4 @@ Testsuite | |
| licenses | ||
|
|
||
| 11/12/07 naveen | ||
| * prepared for release outside lab | ||
| * prepared for release outside lab | ||
|
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. Keep changes minimal – no need to mess with line endings. |
||
| 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) |
||
|
|
||
| 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. |
||
| """ | ||
|
|
||
| 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 | ||
|
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. Did black remove the newline? Otherwise keep it as is. |
||
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.
Keep changes minimal – no need to mess with line endings.