Skip to content

Commit

Permalink
GradientColorMap: Avoid divide by zero
Browse files Browse the repository at this point in the history
  • Loading branch information
ales-erjavec committed Apr 17, 2020
1 parent 0eaf397 commit 505995f
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion Orange/widgets/visualize/utils/heatmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,16 @@ def apply(self, data) -> np.ndarray:
low, high = self.span
low, high = self.adjust_levels(low, high)
mask = np.isnan(data)
normalized = (data - low) / (high - low)
normalized = data - low
finfo = np.finfo(normalized.dtype)
if high - low <= 1 / finfo.max:
n_fact = finfo.max
else:
n_fact = 1. / (high - low)
# over/underflow to inf are expected and cliped with the rest in the
# next step
with np.errstate(over="ignore", under="ignore"):
normalized *= n_fact
normalized = np.clip(normalized, 0, 1, out=normalized)
table = np.empty_like(normalized, dtype=np.uint8)
ncolors = len(self.colortable)
Expand Down

0 comments on commit 505995f

Please sign in to comment.