Skip to content

Commit d6f942f

Browse files
authored
do not compute swap gain if both new mappings are not in candidates (… (#40)
* do not compute swap gain if both new mappings are not in candidates (3x faster on dev) * added a comment explaining code change
1 parent 9f632b7 commit d6f942f

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

smatch.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,10 @@ def get_best_gain(mapping, candidate_mappings, weight_dict, instance_len, cur_ma
536536
for i, m in enumerate(mapping):
537537
for j in range(i + 1, len(mapping)):
538538
m2 = mapping[j]
539+
# no need to compute swap gain if both (i, m2) (j, m) are not in candidate mappings
540+
# such a swap cannot incur any gains
541+
if (m2 not in candidate_mappings[i]) and (m not in candidate_mappings[j]):
542+
continue
539543
# swap operation (i, m) (j, m2) -> (i, m2) (j, m)
540544
# j starts from i+1, to avoid duplicate swap
541545
if veryVerbose:

0 commit comments

Comments
 (0)