From ab437898bc524cc1e35381922fa9ef3e93a224cb Mon Sep 17 00:00:00 2001 From: Anton Akhmerov <anton.akhmerov@gmail.com> Date: Sun, 26 Jul 2015 20:42:34 +0200 Subject: [PATCH] fix iadd of views (more code may be affected) --- kwant/rmt.py | 2 +- kwant/tests/test_rmt.py | 41 ++++++++++++++++++++--------------------- 2 files changed, 21 insertions(+), 22 deletions(-) diff --git a/kwant/rmt.py b/kwant/rmt.py index 0f66dd62..814a79b7 100644 --- a/kwant/rmt.py +++ b/kwant/rmt.py @@ -128,7 +128,7 @@ def gaussian(n, sym='A', v=1.): h = randn(n, n) + 1j * randn(n, n) # Ensure Hermiticity. - h += h.T.conj() + h = h + h.T.conj() # Ensure Chiral symmetry. if c(sym): diff --git a/kwant/tests/test_rmt.py b/kwant/tests/test_rmt.py index adc7a2bd..d3125923 100644 --- a/kwant/tests/test_rmt.py +++ b/kwant/tests/test_rmt.py @@ -15,27 +15,26 @@ assert_allclose = np.testing.assert_allclose def test_gaussian_symmetries(): np.random.seed(10) - n = 8 - for sym in rmt.sym_list: - if sym not in ('A', 'D', 'AI'): - assert_raises(ValueError, rmt.gaussian, 5, sym) - else: - rmt.gaussian(5, sym) # Check it is allowed. - h = rmt.gaussian(n, sym) - if rmt.t(sym): - t_mat = np.array(rmt.h_t_matrix[sym]) - t_mat = np.kron(np.identity(n / len(t_mat)), t_mat) - assert_allclose(h, np.dot(t_mat, np.dot(h.conj(), t_mat)), - err_msg='TRS broken in ' + sym) - if rmt.p(sym): - p_mat = np.array(rmt.h_p_matrix[sym]) - p_mat = np.kron(np.identity(n / len(p_mat)), p_mat) - assert_allclose(h, -np.dot(p_mat, np.dot(h.conj(), p_mat)), - err_msg='PHS broken in ' + sym) - if rmt.c(sym): - sz = np.kron(np.identity(n / 2), np.diag([1, -1])) - assert_allclose(h, -np.dot(sz, np.dot(h, sz)), - err_msg='SLS broken in ' + sym) + for n in (5, 8, 100, 200): + for sym in rmt.sym_list: + if sym not in ('A', 'D', 'AI') and n % 2: + assert_raises(ValueError, rmt.gaussian, 5, sym) + continue + h = rmt.gaussian(n, sym) + if rmt.t(sym): + t_mat = np.array(rmt.h_t_matrix[sym]) + t_mat = np.kron(np.identity(n / len(t_mat)), t_mat) + assert_allclose(h, np.dot(t_mat, np.dot(h.conj(), t_mat)), + err_msg='TRS broken in ' + sym) + if rmt.p(sym): + p_mat = np.array(rmt.h_p_matrix[sym]) + p_mat = np.kron(np.identity(n / len(p_mat)), p_mat) + assert_allclose(h, -np.dot(p_mat, np.dot(h.conj(), p_mat)), + err_msg='PHS broken in ' + sym) + if rmt.c(sym): + sz = np.kron(np.identity(n / 2), np.diag([1, -1])) + assert_allclose(h, -np.dot(sz, np.dot(h, sz)), + err_msg='SLS broken in ' + sym) def test_gaussian_distributions(): -- GitLab