Skip to content

TEST: Check non-integral slopes, intercepts in ArrayProxy API #847

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

Merged
merged 6 commits into from
Dec 6, 2019

Conversation

effigies
Copy link
Member

Realized the ArrayProxy API tests are only using integral slopes and intercepts. Added some 5 s.f. parameters.

Currently breaks tests. Will look in detail when I can, but more eyes are always welcome.

This should be resolved and merged into #844, to ensure that the changes to results stay within tolerance.

@codecov
Copy link

codecov bot commented Nov 28, 2019

Codecov Report

Merging #847 into master will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #847      +/-   ##
==========================================
+ Coverage   90.09%   90.09%   +<.01%     
==========================================
  Files          98       98              
  Lines       12450    12452       +2     
  Branches     2188     2190       +2     
==========================================
+ Hits        11217    11219       +2     
  Misses        883      883              
  Partials      350      350
Impacted Files Coverage Δ
nibabel/arrayproxy.py 100% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7527247...b1f6e2c. Read the comment docs.

Copy link
Member Author

@effigies effigies left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A review would be greatly appreciated. I've annotated the major bits. If these are worth turning into comments, let me know.

@matthew-brett @rmarkello @adelavega

if np.can_cast(scl_slope, use_dtype):
scl_slope = scl_slope.astype(use_dtype)
if np.can_cast(scl_inter, use_dtype):
scl_inter = scl_inter.astype(use_dtype)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unconditionally casting to int types would truncate the new parameters.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So if it can't cast, but the user asks to, should this maybe spit a warning out?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a helper method intended to do a best-effort downcast, but not to the detriment of accuracy. If you ask me to return ints but it would change the values (beyond a floating point rounding error), then the expected behavior is to keep floats. Spitting out a warning here would be extremely noisy.

@@ -262,7 +266,7 @@ def sio_func():
dtype=dtype,
dtype_out=dtype_out,
arr=arr.copy(),
arr_out=arr * slope + inter,
arr_out=arr.astype(dtype_out) * slope + inter,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If arr is float32, arr * slope + inter is float32. This hasn't mattered with the simple factors we've been using, but the new parameters produce different rounding errors in float32 (basic numpy coercion) and float64 (nibabel array scaling).

This change ensures that we produce our expected array in the wider dtype.

@effigies effigies force-pushed the fix/slope_inter_guarantees branch from 014d676 to 79a4063 Compare December 2, 2019 16:04
@effigies effigies force-pushed the fix/slope_inter_guarantees branch from 79a4063 to 170365e Compare December 2, 2019 16:35
@effigies effigies force-pushed the fix/slope_inter_guarantees branch from 170365e to 779f27b Compare December 2, 2019 16:45
@effigies effigies changed the title TEST: Check non-integral slopes, intercepts TEST: Check non-integral slopes, intercepts in ArrayProxy API Dec 2, 2019
Copy link

@adelavega adelavega left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but my experience with this is limited.

if np.can_cast(scl_slope, use_dtype):
scl_slope = scl_slope.astype(use_dtype)
if np.can_cast(scl_inter, use_dtype):
scl_inter = scl_inter.astype(use_dtype)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So if it can't cast, but the user asks to, should this maybe spit a warning out?

@effigies
Copy link
Member Author

effigies commented Dec 5, 2019

Pretty happy with these tests (though they do add time... I probably don't need to do all the ints, uints, floats and complexfloats).

These will help with stress-testing #844, so if there are no objections I'll merge tomorrow.

@effigies effigies merged commit fcc5448 into nipy:master Dec 6, 2019
@effigies effigies deleted the fix/slope_inter_guarantees branch December 6, 2019 00:03
@effigies effigies added this to the 3.0.0 milestone Jan 26, 2020
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.

3 participants