Skip to content
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

Don't convert vmin, vmax to floats. #6700

Merged

Conversation

anntzer
Copy link
Contributor

@anntzer anntzer commented Jul 6, 2016

They may be float128's in which case precision would be lost; this can
result in Normalize returning values (barely) outside of [0, 1].

(The cast to float was introduced in 28e1d2, referring to bug 2997687
on SF; it may be worth checking what it was about.)

See #6698.

@efiring
Copy link
Member

efiring commented Jul 6, 2016

I suspect it would make more sense to just convert the float128 input to float64 at an early stage. The conversion will occur sooner or later anyway; we have no mechanism for maintaining float128 throughout the pipeline, and that level of precision makes no sense for plotting anyway.

@WeatherGod
Copy link
Member

Eventually, everything needs to become float-like. The purpose of casting
to float was most likely to avoid integer division. Unfortunately, the
issue tracker is no longer up on sourceforge, so it is going to be hard to
find out what that particular issue was.

On Wed, Jul 6, 2016 at 3:34 PM, Antony Lee notifications@github.com wrote:

They may be float128's in which case precision would be lost; this can
result in Normalize returning values (barely) outside of [0, 1].

(The cast to float was introduced in 28e1d2, referring to bug 2997687
on SF; it may be worth checking what it was about.)

See #6698 #6698.

You can view, comment on, or merge this pull request online at:

#6700
Commit Summary

  • Don't convert vmin, vmax to floats.

File Changes

Patch Links:


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
#6700, or mute the thread
https://github.com/notifications/unsubscribe/AARy-KbEYAVFrGM6K78a6IvYiNORYcJIks5qTANWgaJpZM4JGbL8
.

@anntzer
Copy link
Contributor Author

anntzer commented Jul 6, 2016

See also #6677 for @efiring's suggestion (which I agree with -- similar bugs with handling float128's probably occur at a bunch of other places). However I'd rather keep this simple solution for now and have a separate discussion for making the switch to float64 (or even float32, which is certainly enough for plotting purposes) everywhere at the same time.

PS: The failure on Travis seems spurious.

@tacaswell
Copy link
Member

There is no float128 on windows?

@tacaswell tacaswell added this to the 2.1 (next point release) milestone Jul 7, 2016
They may be float128's in which case precision would be lost; this can
result in `Normalize` returning values (barely) outside of `[0, 1]`.

(The cast to `float` was introduced in 28e1d2, referring to bug 2997687
on SF; it may be worth checking what it was about.)
@anntzer anntzer force-pushed the dont-cast-normalize-limits-to-float branch from a49ac62 to 16f9778 Compare July 7, 2016 00:54
@anntzer
Copy link
Contributor Author

anntzer commented Jul 7, 2016

Apparently not... https://mail.scipy.org/pipermail/scipy-dev/2008-March/008562.html
A quick test tells me that longdouble is float64 on Windows. Still, that seems good enough for the tests. Updated.

@tacaswell
Copy link
Member

It looks like the single value branch of the process_value method needs the same sort of logic as the array branch. I think it will currently cast a single float128 to a possibly shorter float leading to the same issue.

@anntzer
Copy link
Contributor Author

anntzer commented Jul 7, 2016

Actually both branches probably need it, right?
I think we should cast result to np.promote_types(result.dtype, np.float32) (i.e. at least float32 but not smaller than the actual size).

@tacaswell
Copy link
Member

The array branch only casts to it if it is not a float type, otherwise we just copy.

@anntzer
Copy link
Contributor Author

anntzer commented Jul 7, 2016

I see. I guess the whole process_value method could be simplified to

def process_value(value):
    is_scalar = not cbook.iterable(value)
    if is_scalar:
        value = [value]
    dtype = np.min_scalar_type(value)
    dtype = (np.float32 if dtype.itemsize <= 2
             else np.promote_types(dtype, float))
    result = np.ma.array(value, dtype=dtype, copy=True)
    return result, is_scalar

right?

@tacaswell
Copy link
Member

Yes, I think so.

@anntzer
Copy link
Contributor Author

anntzer commented Jul 8, 2016

done.

@tacaswell
Copy link
Member

👍 LGTM pending appveyor

@anntzer
Copy link
Contributor Author

anntzer commented Jul 9, 2016

Appveyor failure seems spurious?
Also, note that the parent issue (#6698) is milestoned to 2.0 (and this bug was revealed by #6382, which is also in 2.0).

@jenshnielsen
Copy link
Member

Regarding float128 it's not actually 128 bytes but a long double which is padded to 128 bits http://docs.scipy.org/doc/numpy-dev/user/basics.types.html

On Linux and OSX long doubles are normally 80 bits but on windows (MSVC) they are equivalent to doubles. They may have more precision on other less common platforms.

@tacaswell tacaswell modified the milestones: 2.0 (style change major release), 2.1 (next point release) Jul 12, 2016
@tacaswell tacaswell merged commit 0346f1a into matplotlib:master Jul 12, 2016
@anntzer anntzer deleted the dont-cast-normalize-limits-to-float branch July 12, 2016 04:16
tacaswell added a commit that referenced this pull request Jul 12, 2016
…loat

FIX: Don't convert vmin, vmax to floats in norm

Conflicts:
	lib/matplotlib/colors.py
	   Kept version from master.  Conflicts due to maskedarray
	   name normalization.
@tacaswell
Copy link
Member

backported to v2.x as c7d7d19

@anntzer
Copy link
Contributor Author

anntzer commented Jul 25, 2016

@efiring @WeatherGod @tacaswell
Following the discussion in #6825 I will probably need to revert that PR for a more comprehensive solution instead, which is unlikely to be ready by 2.0 (any timeline btw?). However, we still need a fix for #6698 for 2.0. I think we can probably get away with giving a bit of tolerance to the 0-1 range (i.e. clip values between -1e-8 and 0 to 0 and values between 1 and 1+1e-8 to 1). Thoughts?

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.

None yet

6 participants