Skip to content

Commit 15c3d91

Browse files
committed
Add fallback for Numba < 0.28
Should be removed once Anaconda is updated to include Naumba >= 0.28
1 parent 7044387 commit 15c3d91

File tree

1 file changed

+45
-21
lines changed

1 file changed

+45
-21
lines changed

quantecon/game_theory/support_enumeration.py

Lines changed: 45 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,18 @@
1111
Tardos, and V. Vazirani eds., Algorithmic Game Theory, 2007.
1212
1313
"""
14+
from distutils.version import LooseVersion
1415
import numpy as np
1516
import numba
1617
from numba import jit
1718

1819

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+
1926
EPS = np.finfo(float).eps
2027

2128

@@ -39,6 +46,11 @@ def support_enumeration(g):
3946
list(tuple(ndarray(float, ndim=1)))
4047
List containing tuples of Nash equilibrium mixed actions.
4148
49+
Notes
50+
-----
51+
This routine is jit-complied if Numba version 0.28 or above is
52+
installed.
53+
4254
"""
4355
return list(support_enumeration_gen(g))
4456

@@ -68,7 +80,7 @@ def support_enumeration_gen(g):
6880
g.players[1].payoff_array)
6981

7082

71-
@jit(nopython=True) # cache=True raises _pickle.PicklingError
83+
@jit(nopython=nopython) # cache=True raises _pickle.PicklingError
7284
def _support_enumeration_gen(payoff_matrix0, payoff_matrix1):
7385
"""
7486
Main body of `support_enumeration_gen`.
@@ -117,7 +129,7 @@ def _support_enumeration_gen(payoff_matrix0, payoff_matrix1):
117129
next_k_array(supps[0])
118130

119131

120-
@jit(nopython=True, cache=True)
132+
@jit(nopython=nopython, cache=True)
121133
def _indiff_mixed_action(payoff_matrix, own_supp, opp_supp, A, b, out):
122134
"""
123135
Given a player's payoff matrix `payoff_matrix`, an array `own_supp`
@@ -270,25 +282,37 @@ def next_k_array(a):
270282
return a
271283

272284

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.
278305
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.
283310
284-
Returns
285-
-------
286-
bool
287-
Whether `a` is numerically singular.
311+
Returns
312+
-------
313+
bool
314+
Whether `a` is numerically singular.
288315
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

Comments
 (0)