Skip to content

Commit 33c291d

Browse files
committed
Implemented automatic removal of functionally equivalent restrictions
1 parent 39b5f01 commit 33c291d

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

kernel_tuner/util.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1023,6 +1023,15 @@ def to_equality_constraint(
10231023
return AllDifferentConstraint()
10241024
return ValueError(f"Not possible: comparator should be '==' or '!=', is {comparator}")
10251025
return None
1026+
1027+
# remove functionally duplicate restrictions (preserves order and whitespace)
1028+
if all(isinstance(r, str) for r in restrictions):
1029+
# clean the restriction strings to functional equivalence
1030+
restrictions_cleaned = [r.replace(' ', '') for r in restrictions]
1031+
restrictions_cleaned_unique = list(dict.fromkeys(restrictions_cleaned)) # dict preserves order
1032+
# get the indices of the unique restrictions, use these to build a new list of restrictions
1033+
restrictions_unique_indices = [restrictions_cleaned.index(r) for r in restrictions_cleaned_unique]
1034+
restrictions = [restrictions[i] for i in restrictions_unique_indices]
10261035

10271036
# create the parsed restrictions
10281037
if monolithic is False:

0 commit comments

Comments
 (0)