Commit 109e145a authored by Anton Akhmerov's avatar Anton Akhmerov
Browse files

fix return value of modes with zero hopping, test it

parent 4d4698f0
Pipeline #343 skipped
......@@ -578,8 +578,8 @@ def modes(h_cell, h_hop, tol=1e6, stabilization=None):
raise ValueError("Incompatible matrix sizes for h_cell and h_hop.")
if not complex_any(h_hop):
v = np.zeros((0, m))
return (PropagatingModes(np.zeros((0, n)), np.zeros((0,)),
v = np.zeros((m, 0))
return (PropagatingModes(np.zeros((n, 0)), np.zeros((0,)),
np.zeros((0,))),
StabilizedModes(np.zeros((0, 0)), np.zeros((0, 0)), 0, v))
......
......@@ -324,3 +324,19 @@ def test_dtype_linsys():
lsys = kwant.physics.leads.setup_linsys(h_cell - 0.3*np.eye(2),
h_hop)
assert lsys.eigenproblem[0].dtype == np.complex128
def test_zero_hopping():
h_cell = np.identity(2)
h_hop = np.zeros((2, 1))
expected = (leads.PropagatingModes(np.zeros((2, 0)), np.zeros((0,)),
np.zeros((0,))),
leads.StabilizedModes(np.zeros((0, 0)), np.zeros((0, 0)), 0,
np.zeros((1, 0))))
actual = leads.modes(h_cell, h_hop)
assert all(np.alltrue(getattr(actual[1], attr) ==
getattr(expected[1], attr)) for attr
in ('vecs', 'vecslmbdainv', 'nmodes', 'sqrt_hop'))
assert all(np.alltrue(getattr(actual[0], attr) ==
getattr(expected[0], attr)) for attr
in ('wave_functions', 'velocities', 'momenta'))
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment