Skip to content

Commit a23985e

Browse files
authored
RFC: game_theory: Use numba.typed.Dict in _vertex_enumeration_gen (#766)
1 parent 23a8a9b commit a23985e

File tree

1 file changed

+20
-11
lines changed

1 file changed

+20
-11
lines changed

quantecon/game_theory/vertex_enumeration.py

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
"""
1212
import numpy as np
1313
import scipy.spatial
14-
from numba import jit, guvectorize
14+
from numba import jit, guvectorize, types
15+
from numba.typed import Dict
1516

1617

1718
def vertex_enumeration(g, qhull_options=None):
@@ -109,18 +110,26 @@ def _vertex_enumeration_gen(labelings_bits_tup, equations_tup, trans_recips):
109110
ZERO_LABELING0_BITS = (np.uint64(1) << np.uint64(m)) - np.uint64(1)
110111
COMPLETE_LABELING_BITS = (np.uint64(1) << np.uint64(m+n)) - np.uint64(1)
111112

113+
labelings_bits_dict1 = Dict.empty(key_type=types.uint64,
114+
value_type=types.intp)
115+
for j in range(num_vertices1):
116+
labelings_bits_dict1[labelings_bits_tup[1][j]] = j
117+
112118
for i in range(num_vertices0):
113-
if labelings_bits_tup[0][i] == ZERO_LABELING0_BITS:
119+
bits0 = labelings_bits_tup[0][i]
120+
if bits0 == ZERO_LABELING0_BITS:
121+
continue
122+
complement0 = bits0 ^ COMPLETE_LABELING_BITS
123+
try:
124+
j = labelings_bits_dict1[complement0]
125+
except Exception:
114126
continue
115-
for j in range(num_vertices1):
116-
xor = labelings_bits_tup[0][i] ^ labelings_bits_tup[1][j]
117-
if xor == COMPLETE_LABELING_BITS:
118-
yield _get_mixed_actions(
119-
labelings_bits_tup[0][i],
120-
(equations_tup[0][i], equations_tup[1][j]),
121-
trans_recips
122-
)
123-
break
127+
128+
yield _get_mixed_actions(
129+
bits0,
130+
(equations_tup[0][i], equations_tup[1][j]),
131+
trans_recips
132+
)
124133

125134

126135
class _BestResponsePolytope:

0 commit comments

Comments
 (0)