Skip to content
Snippets Groups Projects
Commit 900668e6 authored by Michael Wimmer's avatar Michael Wimmer Committed by Christoph Groth
Browse files

add test for dtype in setup_linsys

parent 79d994be
No related branches found
No related tags found
No related merge requests found
......@@ -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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment