Skip to content

Commit ce3f0a4

Browse files
committed
GradientColorMap: Avoid divide by zero
1 parent 5bd648f commit ce3f0a4

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

Orange/widgets/visualize/utils/heatmap.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,16 @@ def apply(self, data) -> np.ndarray:
113113
low, high = self.span
114114
low, high = self.adjust_levels(low, high)
115115
mask = np.isnan(data)
116-
normalized = (data - low) / (high - low)
116+
normalized = data - low
117+
finfo = np.finfo(normalized.dtype)
118+
if high - low <= 1 / finfo.max:
119+
n_fact = finfo.max
120+
else:
121+
n_fact = 1. / (high - low)
122+
# over/underflow to inf are expected and cliped with the rest in the
123+
# next step
124+
with np.errstate(over="ignore", under="ignore"):
125+
normalized *= n_fact
117126
normalized = np.clip(normalized, 0, 1, out=normalized)
118127
table = np.empty_like(normalized, dtype=np.uint8)
119128
ncolors = len(self.colortable)

0 commit comments

Comments
 (0)