Skip to content
This repository has been archived by the owner on Dec 29, 2022. It is now read-only.

Commit

Permalink
Fix nondeterminism
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert Grosse committed Jan 7, 2016
1 parent 5e33a9c commit b9879f5
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions enjarify/jvm/optimization/consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ def allocateRequiredConstants(pool, long_irs):
# if we have enough space for all required constants, preferentially allocate
# most commonly used constants to first 255 slots
if pool.space() >= len(narrow_pairs) + 2*len(wide_pairs) and pool.lowspace() > 0:
for key, count in narrow_pairs.most_common(pool.lowspace()):
# We can't use Counter.most_common here because it is nondeterminstic in
# the case of ties.
most_common = sorted(narrow_pairs, key=lambda p:(-narrow_pairs[p], p))
for key in most_common[:pool.lowspace()]:
pool.insertDirectly(key, True)
del narrow_pairs[key]

Expand All @@ -65,7 +68,6 @@ def allocateRequiredConstants(pool, long_irs):
# sort by score
narrowq = sorted(narrow_pairs, key=lambda p:(scores[p], p))
wideq = sorted(wide_pairs, key=lambda p:(scores[p], p))

while pool.space() >= 1 and (narrowq or wideq):
if not narrowq and pool.space() < 2:
break
Expand Down

0 comments on commit b9879f5

Please sign in to comment.