From 11c0f8d47defc5a496f3d67c798c8d85d9f12957 Mon Sep 17 00:00:00 2001 From: Daisuke Oyama Date: Thu, 20 Oct 2016 17:01:50 +0900 Subject: [PATCH 1/3] Add test_normalformgame_payoff_profile_array_c_contiguous Test should fail --- quantecon/game_theory/tests/test_normal_form_game.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/quantecon/game_theory/tests/test_normal_form_game.py b/quantecon/game_theory/tests/test_normal_form_game.py index 1a3d10a2f..f62d9f29a 100644 --- a/quantecon/game_theory/tests/test_normal_form_game.py +++ b/quantecon/game_theory/tests/test_normal_form_game.py @@ -236,6 +236,16 @@ def test_normalformgame_payoff_profile_array(): assert_array_equal(player_new.payoff_array, payoff_array) +def test_normalformgame_payoff_profile_array_c_contiguous(): + nums_actions = (2, 3, 4) + shape = nums_actions + (len(nums_actions),) + payoff_profile_array = \ + np.arange(np.prod(shape)).reshape(shape) + g = NormalFormGame(payoff_profile_array) + for player in g.players: + ok_(player.payoff_array.flags['C_CONTIGUOUS']) + + # Trivial cases with one player # class TestPlayer_0opponents: From 8ed832a8cb7ee78a75c706c4526fa8057933710d Mon Sep 17 00:00:00 2001 From: Daisuke Oyama Date: Thu, 20 Oct 2016 17:03:37 +0900 Subject: [PATCH 2/3] NormalFormGame: Make `payoff_array`'s C contiguous when payoff_profile_array is passed to NormalFormGame --- quantecon/game_theory/normal_form_game.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/quantecon/game_theory/normal_form_game.py b/quantecon/game_theory/normal_form_game.py index bbbf0f5ba..28dbfabec 100644 --- a/quantecon/game_theory/normal_form_game.py +++ b/quantecon/game_theory/normal_form_game.py @@ -475,11 +475,16 @@ def __init__(self, data, dtype=None): 'size of innermost array must be equal to ' + 'the number of players' ) - self.players = tuple( - Player( + payoff_arrays = tuple( + np.empty(data.shape[i:-1]+data.shape[:i], dtype=data.dtype) + for i in range(N) + ) + for i, payoff_array in enumerate(payoff_arrays): + payoff_array[:] = \ data.take(i, axis=-1).transpose(list(range(i, N)) + list(range(i))) - ) for i in range(N) + self.players = tuple( + Player(payoff_array) for payoff_array in payoff_arrays ) self.dtype = data.dtype From e4c633bb8aeedcb70500511911e043bf289f9080 Mon Sep 17 00:00:00 2001 From: Daisuke Oyama Date: Thu, 27 Oct 2016 23:46:42 +0900 Subject: [PATCH 3/3] Player: Make `payoff_array` C contiguous --- quantecon/game_theory/normal_form_game.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/quantecon/game_theory/normal_form_game.py b/quantecon/game_theory/normal_form_game.py index 28dbfabec..edb208b1f 100644 --- a/quantecon/game_theory/normal_form_game.py +++ b/quantecon/game_theory/normal_form_game.py @@ -163,7 +163,7 @@ class Player(object): """ def __init__(self, payoff_array): - self.payoff_array = np.asarray(payoff_array) + self.payoff_array = np.asarray(payoff_array, order='C') if self.payoff_array.ndim == 0: raise ValueError('payoff_array must be an array_like')