Permalink
Browse files

Colormap: ensure native byteorder to avoid obscure putmask bug, #1005

  • Loading branch information...
1 parent 551f11b commit a99651ef7ece40e6146d1f793e520a40fed5ae5f @efiring committed Aug 16, 2012
Showing with 10 additions and 3 deletions.
  1. +10 −3 lib/matplotlib/colors.py
View
@@ -515,10 +515,17 @@ def __call__(self, X, alpha=None, bytes=False):
xa = xma.filled() # Fill to avoid infs, etc.
del xma
- if xa.dtype.char in np.typecodes['Float']:
+ # Calculations with native byteorder are faster, and avoid a
+ # bug that otherwise can occur with putmask when the last
+ # argument is a numpy scalar.
+ if not xa.dtype.isnative:
+ xa = xa.byteswap().newbyteorder()
+
+ if xa.dtype.kind == "f":
# Treat 1.0 as slightly less than 1.
- cbook._putmask(xa, xa==1.0, np.nextafter(xa.dtype.type(1),
- xa.dtype.type(0)))
+ vals = np.array([1, 0], dtype=xa.dtype)
+ almost_one = np.nextafter(*vals)
+ cbook._putmask(xa, xa==1.0, almost_one)
# The following clip is fast, and prevents possible
# conversion of large positive values to negative integers.

0 comments on commit a99651e

Please sign in to comment.