Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Allow imshow from float16 data #15436

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

Closed
aaronkrogers wants to merge 4 commits into matplotlib:master from aaronkrogers:float16fix
Closed

Allow imshow from float16 data #15436

aaronkrogers wants to merge 4 commits into matplotlib:master from aaronkrogers:float16fix

Conversation

Copy link

@aaronkrogers aaronkrogers commented Oct 18, 2019
edited by QuLogic
Loading

Removes ValueError "dtype not supported" error when plotting data with dtype float16 ( Fixes #15432 ). This casts everything into dtype float64. Casting is done silently when upscaling precision and with a warning when precision will be decreased.

@aaronkrogers aaronkrogers marked this pull request as ready for review October 18, 2019 05:38
f"'float64' for imshow")
scaled_dtype = np.float64
if A.dtype not in (np.float64, np.float32, np.float16):
# warn if decreasing float precision
Copy link
Member

@tacaswell tacaswell Oct 18, 2019

Choose a reason for hiding this comment

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

If we are casting to higher bit depth isn't it increasing float precision?

Copy link
Author

@aaronkrogers aaronkrogers Oct 18, 2019
edited
Loading

Choose a reason for hiding this comment

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

I could have made that better, but the only casting the warning really covers is float128 -> float64. Everything else is cast automatically. From what I could tell they were already casting float128 down and ints into floats. float16 through float64 were preserved and passed along as is so I'm wondering if it isn't out of scope here to just cast float16 up.

@tacaswell tacaswell added this to the v3.3.0 milestone Oct 18, 2019
Copy link
Member

See my comment on #15432. I do not think this is the correct fix.

If I am wrong, this still needs a test.

Copy link
Author

It looks like we were already casting quadruple floats down into doubles here. The second commit preserves that and casts float16 to it's nearer float32 and warns on any float casting on the python side.

Co-Authored-By: Elliott Sales de Andrade <quantum.analyst@gmail.com>
Copy link
Member

@tacaswell tacaswell left a comment

Choose a reason for hiding this comment

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

Can you please change this so that we don't need to access float128, a series of known cases and returns with a final "if we don't know what this is, cast to float64" is sufficient.

@tacaswell tacaswell modified the milestones: v3.3.0, v3.4.0 Jun 8, 2020
Copy link
Member

@QuLogic QuLogic left a comment

Choose a reason for hiding this comment

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

Can you add a test for this? There's already test_imshow_float128, so something similar for float16 would be good.

@@ -420,13 +420,19 @@ def _make_image(self, A, in_bbox, out_bbox, clip_bbox, magnification=1.0,
a_min, a_max = np.int32(0), np.int32(1)
if inp_dtype.kind == 'f':
scaled_dtype = A.dtype
Copy link
Contributor

@anntzer anntzer Aug 5, 2020
edited
Loading

Choose a reason for hiding this comment

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

perhaps the whole thing can be written as scaled_dtype = np.float64 if A.dtype.itemsize > 4 else np.float32? (this way things will keep working even if numpy adds obscure formats like 8-bit floats)
Also, do we actually want to warn when upcasting float16 to float32 (which doesn't lose precision)? For example we already silently cast ints to floats in many places in the lib.

timhoffm reacted with thumbs up emoji
@QuLogic QuLogic modified the milestones: v3.4.0, v3.5.0 Jan 22, 2021
@jklymak jklymak marked this pull request as draft May 8, 2021 17:41
Copy link
Member

QuLogic commented May 26, 2021

Replaced by #20290.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Reviewers

@anntzer anntzer anntzer left review comments

@tacaswell tacaswell tacaswell requested changes

@QuLogic QuLogic QuLogic approved these changes

Assignees
No one assigned
Projects
None yet
Milestone
v3.5.0
Development

Successfully merging this pull request may close these issues.

Add support in matplotlib.pyplot.imshow for float16

AltStyle によって変換されたページ (->オリジナル) /