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
Simplified code in lib.distances
a bit
#2048
Simplified code in lib.distances
a bit
#2048
Conversation
* Renamed `_box_check()` -> `_check_box()` to be consistent with naming of other helper functions. * `_check_box()` now also returns the box in the format expected by low-level C functions in `lib.c_distances`. * Removed obsolete box type `'tri_vecs_bad'`. * Renamed `_check_array()` -> `_check_coord_array()` to better reflect its purpose. * Renamed `_check_results_array()` -> `_check_result_array()` since the checked parameter is always named `result`. * `_check_result_array()` now returns a numpy array of correct shape and dtype if `result` is `None`. * Improved docstrings of `transform_RtoS()` and `transform_StoR()` and added input coordinate shape check. Adjusted `test_augment.py` accordingly. * Added shape check for input coordinates of `calc_distance()`, `clac_angle()`, and `calc_dihedral()`.
Codecov Report
@@ Coverage Diff @@
## develop #2048 +/- ##
===========================================
+ Coverage 88.93% 89.24% +0.31%
===========================================
Files 144 159 +15
Lines 17490 18703 +1213
Branches 2693 2682 -11
===========================================
+ Hits 15554 16691 +1137
- Misses 1323 1407 +84
+ Partials 613 605 -8
Continue to review full report at Codecov.
|
Looks like the Mac tests are failing on the last decimal place of precision. I think this is expected with a float32 triclinic box. |
package/MDAnalysis/lib/distances.py
Outdated
_check_coord_array_shape_2d(coords, desc) | ||
if coords.dtype != np.float32: | ||
raise TypeError("{0} must be of type numpy.float32".format(desc)) | ||
# The following two lines would break a lot of tests. WHY?! |
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.
What tests fail here? Is it that some coords arrays are often non C contiguous?
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.
Ignore it, that's just a personal note I forgot to delete. Requiring coordinate arrays to be C-contiguous doesn't really make sense here since all the functions have calls to np.astype(...)
which will return a contiguous copy anyway.
@zemanj these changes look good, thanks! |
@zemanj ok if you get the precision on the macos tests working we can merge this. I'd rather chip away at 2046 in small parts to keep the PRs smaller. I added a WIP tag, remove it once you're happy for us to pull the trigger on this PR. |
@richardjgowers Thanks for taking a look! I'll add some more tests to increase coverage tomorrow and decrease the precision in the tests for |
@orbeckst @richardjgowers I'm still unsure how we should handle the requirements for the box input. There are two proper solutions to this discrepancy:
And two rather ugly "solutions":
My preference is definitely solution 1, since including a proper description of all possible box input formats in the docstrings would quickly get out of hand. Additionally, the overhead caused by If other @MDAnalysis/coredevs have an opinion on that issue, please let me know! |
@zemanj yeah let's tidy box inputs to the first option. If the docs are requesting the |
I'm also in favor of tidy inputs.
If we never documented the weaker requirements then you don't add a versionchanged marker to the docs but we should still have a note in CHANGELOG under changes saying that tidy box input is now consistently enforced.
…--
Oliver Beckstein
email: orbeckst@gmail.com
Am Aug 15, 2018 um 06:04 schrieb Richard Gowers ***@***.***>:
@zemanj yeah let's tidy box inputs to the first option. If the docs are requesting the .dimensions format even better, as it's technically not an API break....
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.
|
Ok so I changed the requirements for boxes to correspond to the docs. This means:
I fixed the tests accordingly. I also fiddled with some decorator tricks to outsource the coordinate array checking. That's what the new decorator The function |
…ib.util.blocks_of()`
…check_coords()` decorator
@richardjgowers Thanks for the merge, CHANGELOG and some additional tests are still missing, though. |
* added missing CHANGELOG entry for PR #2048 * ensured `lib.distances.distance_array()` always returns an array
* fix bug introduced in PR #2048 * allow for empty input coord arrays in lib.distances * tests for empty input coord arrays in lib.distances * fixed _bruteforce_capped() when no pairs are found; fixed _nsgrid_capped() for zero pseudobox size * return type testing for all functions in lib.distances * docs: more precise return type specifications * ensured _nsgrid_capped*() always returns pairs of dtype=np.int64 * added comments and removed unnecessary return type conversion from *capped_distance() * added out-of-box coordinate to TestOutputType tests
Fixes (partially) #2046, this is just the beginning of a series of related PRs.
Changes made in this Pull Request:
_box_check()
->_check_box()
to be consistent with naming of other helper functions._check_box()
now also returns the box in the format expected by low-level C functions inlib.c_distances
, which reduces code duplications.'tri_vecs_bad'
from_check_box()
._check_array()
->_check_coord_array()
to better reflect its purpose._check_results_array()
->_check_result_array()
since the checked parameter is always namedresult
._check_result_array()
now returns a numpy array of correct shape and dtype ifresult
isNone
, which simplifies the code of several functions.transform_RtoS()
andtransform_StoR()
and added input coordinate shape check. Adjustedtest_augment.py
accordingly.calc_distance()
,calc_angle()
, andcalc_dihedral()
.Question:
_check_box()
stricter?PR Checklist
Do we need additional tests?Additional tests needed)