Skip to content

Commit 30f8568

Browse files
committed
Fixed an issue where some restrictions were not recognized by strategies relying on CostFunc
1 parent 0e009fd commit 30f8568

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

kernel_tuner/util.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,20 @@ def check_restrictions(restrictions, params: dict, verbose: bool):
271271
elif callable(restrict) and not restrict(params):
272272
valid = False
273273
break
274+
# if it's a tuple, use only the parameters in the second argument to call the restriction
275+
elif (isinstance(restrict, tuple) and len(restrict) == 2
276+
and callable(restrict[0]) and isinstance(restrict[1], (list, tuple))):
277+
# unpack the tuple
278+
restrict, selected_params = restrict
279+
# look up the selected parameters and their value
280+
selected_params = dict((key, params[key]) for key in selected_params)
281+
# call the restriction
282+
if not restrict(**selected_params):
283+
valid = False
284+
break
285+
# otherwise, raise an error
286+
else:
287+
raise ValueError(f"Unkown restriction type {type(restrict)} ({restrict})")
274288
except ZeroDivisionError:
275289
pass
276290
if not valid and verbose:

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ build-backend = "poetry.core.masonry.api"
66
name = "kernel_tuner"
77
packages = [{ include = "kernel_tuner", from = "." }]
88
description = "An easy to use CUDA/OpenCL kernel tuner in Python"
9-
version = "1.0.0b2" # adhere to PEP440 versioning: https://packaging.python.org/en/latest/guides/distributing-packages-using-setuptools/#id55
9+
version = "1.0.0b3" # adhere to PEP440 versioning: https://packaging.python.org/en/latest/guides/distributing-packages-using-setuptools/#id55
1010
license = "Apache-2.0"
1111
authors = [
1212
"Ben van Werkhoven <b.vanwerkhoven@esciencecenter.nl>",

0 commit comments

Comments
 (0)