diff --git a/kwant/rmt.py b/kwant/rmt.py index 0f66dd62444331cd9e227b7d0a2db4c0715572b3..814a79b7592dcc4a451e10d7d1c2d78590785d32 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 adc7a2bd99993bfcde5bf57b9bc68251095b0ae6..d31259239887e9074445856923443482064911f6 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():