Skip to content

Commit 3ff0beb

Browse files
committed
Change CostFunc to return +inf when objective_higher_is_better
Previously, `CostFunc` would return `-inf` when `object_higher_is_better==True`. However, all search strategies implicitly assume that lower is better.
1 parent 486eed9 commit 3ff0beb

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

kernel_tuner/strategies/common.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from time import perf_counter
44

55
import numpy as np
6+
import numbers
67

78
from kernel_tuner import util
89
from kernel_tuner.searchspace import Searchspace
@@ -109,8 +110,15 @@ def __call__(self, x, check_restrictions=True):
109110
self.runner.last_strategy_start_time = perf_counter()
110111

111112
# get numerical return value, taking optimization direction into account
112-
return_value = result[self.tuning_options.objective] or sys.float_info.max
113-
return_value = return_value if not self.tuning_options.objective_higher_is_better else -return_value
113+
return_value = result[self.tuning_options.objective]
114+
115+
if isinstance(return_value, numbers.Number):
116+
if self.tuning_options.objective_higher_is_better:
117+
# flip the sign if higher means better
118+
return_value = -return_value
119+
else:
120+
# this is not a valid configuration, just return max
121+
return_value = sys.float_info.max
114122

115123
return return_value
116124

0 commit comments

Comments
 (0)