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

Appearance settings

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

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
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Proper norm'ing of float128 scalars too.
  • Loading branch information
anntzer committed Jul 8, 2016
commit ff78a069bc1ad261ce4001d8347934e3995579b0
23 changes: 7 additions & 16 deletions 23 lib/matplotlib/colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -880,22 +880,13 @@ def process_value(value):
Experimental; we may want to add an option to force the
use of float32.
"""
if cbook.iterable(value):
is_scalar = False
result = np.ma.asarray(value)
if result.dtype.kind == 'f':
# this is overkill for lists of floats, but required
# to support pd.Series as input until we can reliable
# determine if result and value share memory in all cases
# (list, tuple, deque, ndarray, Series, ...)
result = result.copy()
elif result.dtype.itemsize > 2:
result = result.astype(float)
else:
result = result.astype(np.float32)
else:
is_scalar = True
result = np.ma.array([value]).astype(float)
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

def __call__(self, value, clip=None):
Expand Down
7 changes: 6 additions & 1 deletion 7 lib/matplotlib/tests/test_colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,15 @@ def test_Normalize():
_scalar_tester(norm, vals)
_mask_tester(norm, vals)

# Don't lose precision on longdoubles (float128 on Linux).
# Don't lose precision on longdoubles (float128 on Linux):
# for array inputs...
vals = np.array([1.2345678901, 9.8765432109], dtype=np.longdouble)
norm = mcolors.Normalize(vals.min(), vals.max())
assert_array_equal(np.asarray(norm(vals)), [0, 1])
# and for scalar ones.
eps = np.finfo(np.longdouble).resolution
norm = plt.Normalize(1, 1 + 100 * eps)
assert_equal(norm(1 + 50 * eps), .5)


def test_SymLogNorm():
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.