11
11
Tardos, and V. Vazirani eds., Algorithmic Game Theory, 2007.
12
12
13
13
"""
14
+ from distutils .version import LooseVersion
14
15
import numpy as np
15
16
import numba
16
17
from numba import jit
17
18
18
19
20
+ least_numba_version = LooseVersion ('0.28' )
21
+ is_numba_required_installed = True
22
+ if LooseVersion (numba .__version__ ) < least_numba_version :
23
+ is_numba_required_installed = False
24
+ nopython = is_numba_required_installed
25
+
19
26
EPS = np .finfo (float ).eps
20
27
21
28
@@ -39,6 +46,11 @@ def support_enumeration(g):
39
46
list(tuple(ndarray(float, ndim=1)))
40
47
List containing tuples of Nash equilibrium mixed actions.
41
48
49
+ Notes
50
+ -----
51
+ This routine is jit-complied if Numba version 0.28 or above is
52
+ installed.
53
+
42
54
"""
43
55
return list (support_enumeration_gen (g ))
44
56
@@ -68,7 +80,7 @@ def support_enumeration_gen(g):
68
80
g .players [1 ].payoff_array )
69
81
70
82
71
- @jit (nopython = True ) # cache=True raises _pickle.PicklingError
83
+ @jit (nopython = nopython ) # cache=True raises _pickle.PicklingError
72
84
def _support_enumeration_gen (payoff_matrix0 , payoff_matrix1 ):
73
85
"""
74
86
Main body of `support_enumeration_gen`.
@@ -117,7 +129,7 @@ def _support_enumeration_gen(payoff_matrix0, payoff_matrix1):
117
129
next_k_array (supps [0 ])
118
130
119
131
120
- @jit (nopython = True , cache = True )
132
+ @jit (nopython = nopython , cache = True )
121
133
def _indiff_mixed_action (payoff_matrix , own_supp , opp_supp , A , b , out ):
122
134
"""
123
135
Given a player's payoff matrix `payoff_matrix`, an array `own_supp`
@@ -270,25 +282,37 @@ def next_k_array(a):
270
282
return a
271
283
272
284
273
- @jit (nopython = True , cache = True )
274
- def is_singular (a ):
275
- """
276
- Determine whether matrix `a` is numerically singular, by checking
277
- its singular values.
285
+ if is_numba_required_installed :
286
+ @jit (nopython = True , cache = True )
287
+ def is_singular (a ):
288
+ s = numba .targets .linalg ._compute_singular_values (a )
289
+ if s [- 1 ] <= s [0 ] * EPS :
290
+ return True
291
+ else :
292
+ return False
293
+ else :
294
+ def is_singular (a ):
295
+ s = np .linalg .svd (a , compute_uv = False )
296
+ if s [- 1 ] <= s [0 ] * EPS :
297
+ return True
298
+ else :
299
+ return False
300
+
301
+ _is_singular_docstr = \
302
+ """
303
+ Determine whether matrix `a` is numerically singular, by checking
304
+ its singular values.
278
305
279
- Parameters
280
- ----------
281
- a : ndarray(float, ndim=2)
282
- 2-dimensional array of floats.
306
+ Parameters
307
+ ----------
308
+ a : ndarray(float, ndim=2)
309
+ 2-dimensional array of floats.
283
310
284
- Returns
285
- -------
286
- bool
287
- Whether `a` is numerically singular.
311
+ Returns
312
+ -------
313
+ bool
314
+ Whether `a` is numerically singular.
288
315
289
- """
290
- s = numba .targets .linalg ._compute_singular_values (a )
291
- if s [- 1 ] <= s [0 ] * EPS :
292
- return True
293
- else :
294
- return False
316
+ """
317
+
318
+ is_singular .__doc__ = _is_singular_docstr
0 commit comments