Skip to content

Commit 76bc549

Browse files
avoid division by zero in simulated annealing
1 parent 34aa6ce commit 76bc549

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

kernel_tuner/strategies/simulated_annealing.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def acceptance_prob(old_cost, new_cost, T):
9696
# if start pos is not valid, always move
9797
if isinstance(old_cost, ErrorConfig):
9898
res = 1.0
99-
# if we have found a valid ps before, never move to nonvalid pos
99+
# if we have found a valid pos before, never move to nonvalid pos
100100
elif isinstance(new_cost, ErrorConfig):
101101
res = 0.0
102102
# always move if new cost is better
@@ -108,7 +108,7 @@ def acceptance_prob(old_cost, new_cost, T):
108108
abs_diff = old_cost - new_cost
109109

110110
# relative to abs(old_cost), as the cost might be negative
111-
rel_diff = abs_diff / np.abs(old_cost)
111+
rel_diff = abs_diff / (np.abs(old_cost) if old_cost != 0.0 else 1e-20)
112112

113113
# exponential decay
114114
res = np.exp(rel_diff / T)

0 commit comments

Comments
 (0)