From 7036afd35e69cc2ec56b54c594028d8dde6a3f67 Mon Sep 17 00:00:00 2001
From: Christoph Groth <christoph.groth@cea.fr>
Date: Tue, 25 Apr 2017 18:12:12 +0200
Subject: [PATCH] make neighbors() work for lattices that live in
 higher-dimensional space

Additionally, make sure to test the LLL code accordingly.
---
 kwant/lattice.py               |  2 +-
 kwant/linalg/tests/test_lll.py | 15 ++++++++-------
 kwant/tests/test_lattice.py    |  2 +-
 3 files changed, 10 insertions(+), 9 deletions(-)

diff --git a/kwant/lattice.py b/kwant/lattice.py
index 8bd91dea..7183fb5e 100644
--- a/kwant/lattice.py
+++ b/kwant/lattice.py
@@ -298,7 +298,7 @@ class Polyatomic:
         Site = builder.Site
         sls = self.sublattices
         shortest_hopping = sls[0].n_closest(
-            Site(sls[0], ([0] * sls[0].dim)).pos, 2)[-1]
+            sls[0].pos(([0] * sls[0].lattice_dim)), 2)[-1]
         eps *= np.linalg.norm(self.vec(shortest_hopping))
         nvec = len(self._prim_vecs)
         sublat_pairs = [(i, j) for (i, j) in product(sls, sls)
diff --git a/kwant/linalg/tests/test_lll.py b/kwant/linalg/tests/test_lll.py
index c4d96f30..2d261661 100644
--- a/kwant/linalg/tests/test_lll.py
+++ b/kwant/linalg/tests/test_lll.py
@@ -24,10 +24,11 @@ def test_lll():
 
 def test_cvp():
     rng = ensure_rng(0)
-    for i in range(10):
-        mat = rng.randn(4, 4)
-        mat = lll.lll(mat)[0]
-        for j in range(4):
-            point = 50 * rng.randn(4)
-            assert np.array_equal(lll.cvp(point, mat, 10)[:3],
-                                  lll.cvp(point, mat, 3))
+    for i in range(1, 5):
+        for j in range(i, 5):
+            mat = rng.randn(i, j)
+            mat = lll.lll(mat)[0]
+            for k in range(4):
+                point = 50 * rng.randn(j)
+                assert np.array_equal(lll.cvp(point, mat, 10)[:3],
+                                      lll.cvp(point, mat, 3))
diff --git a/kwant/tests/test_lattice.py b/kwant/tests/test_lattice.py
index 957cf2b6..c3ea78e7 100644
--- a/kwant/tests/test_lattice.py
+++ b/kwant/tests/test_lattice.py
@@ -46,7 +46,7 @@ def test_neighbors():
     lat = lattice.honeycomb(1e-10)
     num_nth_nearest = [len(lat.neighbors(n)) for n in range(5)]
     assert num_nth_nearest == [2, 3, 6, 3, 6]
-    lat = lattice.square(1e8)
+    lat = lattice.general([(0, 1e8, 0, 0), (0, 0, 1e8, 0)])
     num_nth_nearest = [len(lat.neighbors(n)) for n in range(5)]
     assert num_nth_nearest == [1, 2, 2, 2, 4]
     lat = lattice.chain(1e-10)
-- 
GitLab