From 900668e6fdf8790485e2412362cb43395812b7ea Mon Sep 17 00:00:00 2001 From: Michael Wimmer <wimmer@lorentz.leidenuniv.nl> Date: Sun, 1 Sep 2013 21:28:37 +0200 Subject: [PATCH] add test for dtype in setup_linsys --- kwant/physics/tests/test_leads.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/kwant/physics/tests/test_leads.py b/kwant/physics/tests/test_leads.py index 399cb62b..21d6f662 100644 --- a/kwant/physics/tests/test_leads.py +++ b/kwant/physics/tests/test_leads.py @@ -297,3 +297,30 @@ def test_for_all_evs_equal(): assert modes.vecs.shape == (1, 2) assert modes.vecslmbdainv.shape == (1, 2) assert modes.nmodes == 1 + + +def test_dtype_linsys(): + """Test that setup_linsys stays in real arithmetics when possible.""" + h_cell = np.array([[2.0, -1.0], [-1.0, 2.0]], dtype=np.float64) + h_hop = np.array([[0.0],[-1.0]], dtype=np.float64) + + lsys = kwant.physics.leads.setup_linsys(h_cell - 0.3*np.eye(2), + h_hop) + assert lsys.eigenproblem[0].dtype == np.float64 + + lsys = kwant.physics.leads.setup_linsys(h_cell.astype(np.complex128) + - 0.3*np.eye(2), + h_hop.astype(np.complex128)) + assert lsys.eigenproblem[0].dtype == np.float64 + + # energy=1 is an eigenstate of the isolated cell Hamiltonian, + # i.e. a complex self-energy stabilization is necessary + lsys = kwant.physics.leads.setup_linsys(h_cell - 1*np.eye(2), + h_hop) + assert lsys.eigenproblem[0].dtype == np.complex128 + + # with complex input, output must be complex, too + h_hop = np.array([[0.0],[-1.0 + 0.1j]], dtype=np.complex128) + lsys = kwant.physics.leads.setup_linsys(h_cell - 0.3*np.eye(2), + h_hop) + assert lsys.eigenproblem[0].dtype == np.complex128 -- GitLab