Commit 157fc88f authored by Viacheslav Ostroukh's avatar Viacheslav Ostroukh 🚲
Browse files

test conjugation of array-like types

If onsite/hopping value was supplied to the builder as array-like instead of
proper array, Hamiltonian could be generated silently without any Hermitian
conjugation, if required.

To expose this, `` is
parametrized with different types of values to ensure that Numpy arrays,
tinyarrays, lists and tuples are all conjugated properly.

See issue #406.
parent 7f5a7dc0
......@@ -241,11 +241,17 @@ def test_construction_and_indexing():
unknown_hoppings, sym)
def test_hermitian_conjugation():
def f(i, j, arg):
@pytest.mark.parametrize('value', (
ta.array([[1, 2j], [3 + 1j, 4j]]),
np.array([[1, 2j], [3 + 1j, 4j]]),
[[1, 2j], [3 + 1j, 4j]],
((1, 2j), (3 + 1j, 4j)),
def test_hermitian_conjugation(value):
def f(i, j):
i, j = i.tag, j.tag
if j[0] == i[0] + 1:
return arg * ta.array([[1, 2j], [3 + 1j, 4j]])
return value
raise ValueError
......@@ -256,8 +262,13 @@ def test_hermitian_conjugation():
syst[fam(0), fam(1)] = f
assert syst[fam(0), fam(1)] is f
assert isinstance(syst[fam(1), fam(0)], builder.HermConjOfFunc)
assert (syst[fam(1), fam(0)](fam(1), fam(0), 2) ==
syst[fam(0), fam(1)](fam(0), fam(1), 2).conjugate().transpose())
assert np.all(
syst[fam(1), fam(0)](fam(1), fam(0))
) == np.asarray(
syst[fam(0), fam(1)](fam(0), fam(1))
syst[fam(0), fam(1)] = syst[fam(1), fam(0)]
assert isinstance(syst[fam(0), fam(1)], builder.HermConjOfFunc)
assert syst[fam(1), fam(0)] is f
Supports Markdown
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