From 2e751262b8fca2ecc32b519e4a0016ee72c6e35b Mon Sep 17 00:00:00 2001 From: Manuel Date: Tue, 17 May 2022 23:11:09 +0200 Subject: [PATCH 01/12] quick and dirty fix --- hypertiling/kernelmanu.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hypertiling/kernelmanu.py b/hypertiling/kernelmanu.py index ae75e65..b70bc0b 100644 --- a/hypertiling/kernelmanu.py +++ b/hypertiling/kernelmanu.py @@ -90,7 +90,7 @@ class KernelManu(KernelCommon): # cut away cells outside the fundamental sector # allow some tolerance at the upper boundary - if self.mangle <= cangle < sect_angle_deg+self.degtol+self.mangle: + if self.mangle-1e-14 <= cangle < sect_angle_deg+self.degtol+self.mangle: # try adding to centerlist; it is a set() and takes care of duplicates center = np.round(center, self.dgts) @@ -111,7 +111,7 @@ class KernelManu(KernelCommon): self.polygons.append(adj_pgon) # if angle is in slice, add to centerset_extra - if self.mangle <= cangle <= self.degtol+self.mangle: + if self.mangle-1e-14 <= cangle <= self.degtol+self.mangle: centerset_extra.add(center) startpgon = endpgon -- GitLab From 4503c47a72a4551b1070a874ebaf29ff6c6b26ab Mon Sep 17 00:00:00 2001 From: Manuel Date: Fri, 20 May 2022 00:08:27 +0200 Subject: [PATCH 02/12] that's a start --- hypertiling/neighbours.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/hypertiling/neighbours.py b/hypertiling/neighbours.py index 03c6cb2..92f870e 100644 --- a/hypertiling/neighbours.py +++ b/hypertiling/neighbours.py @@ -186,9 +186,14 @@ def find_nn_optimized_slice(tiling, nn_dist, eps=1e-5): pgons = [] for pgon in tiling.polygons: # pick those polygons that are in sector 0, 1 or last (3 adjacent sectors) pgon.find_angle() - pgon.find_sector() - if pgon.sector in [0, 1, tiling.polygons[0].p-1]: - pgons.append(pgon) + if tiling.center == "cell": + pgon.find_sector(tiling.p) + if pgon.sector in [0, 1, tiling.p-1]: + pgons.append(pgon) + elif tiling.center == "vertex": + pgon.find_sector(tiling.q) + if pgon.sector in [0, 1, tiling.q-1]: + pgons.append(pgon) # prepare matrix containing all center coordiantes v = np.zeros((len(pgons), 3)) @@ -216,7 +221,7 @@ def find_nn_optimized_slice(tiling, nn_dist, eps=1e-5): pps = int((len(pgons)-1)/3) # polygons per sector, excl. center polygon - p = pgons[0].p # number of edges of each polygon + p = tiling.p # number of edges of each polygon total_num = p*pps+1 # total number of polygons lst = np.zeros((pps+1, p+1), dtype=np.int32) # fundamental nn-data of sector 0 -- GitLab From c91b35e4baf11b4ec37380b0f7bb4b5a8dc75808 Mon Sep 17 00:00:00 2001 From: Manuel Date: Fri, 20 May 2022 00:39:48 +0200 Subject: [PATCH 03/12] simplify things --- hypertiling/neighbours.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/hypertiling/neighbours.py b/hypertiling/neighbours.py index 92f870e..c448088 100644 --- a/hypertiling/neighbours.py +++ b/hypertiling/neighbours.py @@ -187,11 +187,11 @@ def find_nn_optimized_slice(tiling, nn_dist, eps=1e-5): for pgon in tiling.polygons: # pick those polygons that are in sector 0, 1 or last (3 adjacent sectors) pgon.find_angle() if tiling.center == "cell": - pgon.find_sector(tiling.p) + pgon.find_sector(tiling.p, tiling.mangle) if pgon.sector in [0, 1, tiling.p-1]: pgons.append(pgon) elif tiling.center == "vertex": - pgon.find_sector(tiling.q) + pgon.find_sector(tiling.q, tiling.mangle) if pgon.sector in [0, 1, tiling.q-1]: pgons.append(pgon) @@ -207,6 +207,7 @@ def find_nn_optimized_slice(tiling, nn_dist, eps=1e-5): # prepare list retlist = [] + indlist = [] # loop over polygons for i, poly in enumerate(pgons): if poly.sector == 0: @@ -218,11 +219,14 @@ def find_nn_optimized_slice(tiling, nn_dist, eps=1e-5): indxs = np.delete(indxs, self) # delete self nums = [pgons[ind].idx for ind in indxs] # replacing indices by actual polygon number retlist.append(nums) + indlist.append(i) + print(i, nums) + + total_num = len(tiling) # total number of polygons + p = tiling.p # number of edges of each polygon + pps = int((total_num-1)/p) # polygons per sector (excluding center) - pps = int((len(pgons)-1)/3) # polygons per sector, excl. center polygon - p = tiling.p # number of edges of each polygon - total_num = p*pps+1 # total number of polygons lst = np.zeros((pps+1, p+1), dtype=np.int32) # fundamental nn-data of sector 0 lst[:, 0] = np.linspace(1, pps+1, pps+1) # writing no. of each polygon in the first column -- GitLab From 854aff7130240e67b4772527b9fb6282ff9165fa Mon Sep 17 00:00:00 2001 From: Manuel Date: Fri, 20 May 2022 02:53:21 +0200 Subject: [PATCH 04/12] overhauled sliced nn search algorithm entirely --- hypertiling/hyperpolygon.py | 4 +- hypertiling/kernelbase.py | 9 ++- hypertiling/neighbours.py | 143 +++++++++++++++++------------------- 3 files changed, 77 insertions(+), 79 deletions(-) diff --git a/hypertiling/hyperpolygon.py b/hypertiling/hyperpolygon.py index 2a46eec..d7ed006 100644 --- a/hypertiling/hyperpolygon.py +++ b/hypertiling/hyperpolygon.py @@ -185,8 +185,8 @@ class HyperPolygon: self.angle += 360 if self.angle < 0 else 0 # compute in which sector out of k sectors the polygon resides - def find_sector(self, k): - self.sector = floor(self.angle/(360/k)) + def find_sector(self, k, offset=0): + self.sector = floor((self.angle-offset)/(360/k)) # mirror on the x-axis def mirror(self): diff --git a/hypertiling/kernelbase.py b/hypertiling/kernelbase.py index 27f20f4..9fe1ef8 100644 --- a/hypertiling/kernelbase.py +++ b/hypertiling/kernelbase.py @@ -48,8 +48,13 @@ class HyperbolicTilingBase: # technical parameters # do not change, unless you know what you are doing!) - self.degtol = 1 # sector boundary tolerance during construction - self.mangle = self.degphi/math.sqrt(5) # angular offset, rotates the entire construction; must not be larger than 360-360/p!!!, math.sqrt(5) : magic fraction... + self.degtol = 1 # sector boundary tolerance + + # angular offset, rotates the entire construction by a bit during construction + if center == "cell": + self.mangle = self.degphi/math.sqrt(5) + elif center == "vertex": + self.mangle = self.degqhi/math.sqrt(5) # fundamental polygon of the tiling diff --git a/hypertiling/neighbours.py b/hypertiling/neighbours.py index c448088..a7b0ed6 100644 --- a/hypertiling/neighbours.py +++ b/hypertiling/neighbours.py @@ -183,82 +183,75 @@ def find_nn_optimized(tiling, nn_dist, eps=1e-5): # applying the neighbour search only to a p-sector of the tiling (done in "find_nn_slice") # currently this is our fastest algorithm for large tessellations def find_nn_optimized_slice(tiling, nn_dist, eps=1e-5): - pgons = [] - for pgon in tiling.polygons: # pick those polygons that are in sector 0, 1 or last (3 adjacent sectors) - pgon.find_angle() - if tiling.center == "cell": - pgon.find_sector(tiling.p, tiling.mangle) - if pgon.sector in [0, 1, tiling.p-1]: - pgons.append(pgon) - elif tiling.center == "vertex": - pgon.find_sector(tiling.q, tiling.mangle) - if pgon.sector in [0, 1, tiling.q-1]: - pgons.append(pgon) - - # prepare matrix containing all center coordiantes - v = np.zeros((len(pgons), 3)) - for i, poly in enumerate(pgons): - v[i] = poly.centerW() - - # add something to nn_dist to avoid rounding problems - # does not need to be particularly small - searchdist = nn_dist + eps - searchdist = np.cosh(searchdist) - - # prepare list - retlist = [] - indlist = [] - # loop over polygons - for i, poly in enumerate(pgons): - if poly.sector == 0: - w = poly.centerW() - dists = lorentzian_distance(v, w) - dists[(dists < 1)] = 1 # this costs some %, but reduces warnings - indxs = np.where(dists < searchdist)[0] # radius search - self = np.argwhere(indxs == i) # find self - indxs = np.delete(indxs, self) # delete self - nums = [pgons[ind].idx for ind in indxs] # replacing indices by actual polygon number - retlist.append(nums) - indlist.append(i) - - print(i, nums) - - total_num = len(tiling) # total number of polygons - p = tiling.p # number of edges of each polygon - pps = int((total_num-1)/p) # polygons per sector (excluding center) - - - lst = np.zeros((pps+1, p+1), dtype=np.int32) # fundamental nn-data of sector 0 - lst[:, 0] = np.linspace(1, pps+1, pps+1) # writing no. of each polygon in the first column - for ind, line in enumerate(retlist): # padding retlist with zeros such that each array has the same length - lst[ind, 1:len(line)+1] = line - - neighbors = np.zeros(shape=(total_num, p + 1), dtype=np.int32) # this array stores nn-data of the whole tiling - neighbors[:pps+1] = lst - nn_of_first = [2] # the first polygon has to be treated seperately - for n in range(1, p): - # the crucial steps of this function follow: increase both the number of the polygon and of its neighbors by the - # number of polygons in this sector to obtain the result for the adjacent sector. Done, p-1 times, this returns - # the neighbors of the whole tiling - lst[(lst > 0)] += pps # increase each entry by pps if its non-zero - nn_of_first.append(nn_of_first[-1] + pps) # increase last nn of first polygon by pps - for ind, row in enumerate(lst[1:]): # iterate over every - row[1] = 1 if ind == 0 else row[1] # taking care of second layer, special treatment for center polygon - row[:] = [elem % total_num+1 if elem > total_num else elem for elem in row] - neighbors[1+ind+n*pps] = row # fill the corresponding row in the neighbors matrix - - neighbors[0, 1:] = nn_of_first # finally store the neighbors of center polygon - - # transform to list and remove self - nbrs = [] - for i, nb in enumerate(neighbors): - arr = np.array(nb) - arr = list(arr[(arr>0)]) - arr.remove(i+1) - nbrs.append(arr) - - return nbrs + totalnum = len(tiling) # total number of polygons + p = tiling.p # number of edges of each polygon + pps = int((totalnum-1)/p) # polygons per sector (excluding center) + + def shift(lst,times): + lst = sorted(lst) + haszero = (0 in lst) + + if haszero: + lsta = np.array(lst[1:]) + times*pps + lsta[lsta>totalnum-1] -= (totalnum-1) + lsta[lsta<1] += (totalnum-1) + return sorted([0]+list(lsta)) + else: + lsta = np.array(lst) + times*pps + lsta[lsta>totalnum-1] -= (totalnum-1) + lsta[lsta<1] += (totalnum-1) + return sorted(list(lsta)) + + def increment(lst): + return list(np.array(lst)+1) + + pgons = tiling[:1+3*pps] + + v = np.zeros((len(pgons), 3)) + for i, poly in enumerate(pgons): + v[i] = poly.centerW() + + searchdist = nn_dist + eps + searchdist = np.cosh(searchdist) + + # prepare list + nbrlst = [] + # loop over polygons + for i, poly in enumerate(pgons[1+pps:1+2*pps]): + w = poly.centerW() + dists = lorentzian_distance(v, w) + dists[(dists < 1)] = 1 # this costs some %, but reduces warnings + indxs = np.where(dists < searchdist)[0] # radius search + self = np.argwhere(indxs == poly.idx-1) # find self + indxs = np.delete(indxs, self) # delete self + nums = [pgons[ind].idx-1 for ind in indxs] # replacing indices by actual polygon number + nbrlst.append(nums) + + + # prepare full list + retlist = [] + + # fundamental cell + lstzero = [] + for ps in range(0,p): + lstzero.append(ps*pps+1) + retlist.append((increment(lstzero))) + + # first sector + for lst in nbrlst: + retlist.append(increment(shift(lst, -1))) + + # second sector + for lst in nbrlst: + retlist.append(increment(lst)) + + # remaining sectors + for ps in range(2,p): + for lst in nbrlst: + retlist.append(increment(shift(lst, ps-1))) + + return retlist # finds nearest neighbors by exploiting the discrete rotational symmetry of the lattice -- GitLab From b43e0a024ad43461b5b0785d1a3b89ffa7366193 Mon Sep 17 00:00:00 2001 From: Manuel Date: Fri, 20 May 2022 03:45:56 +0200 Subject: [PATCH 05/12] attempt to get the v-centered version of the new algorithm working; unsuccesful so far ... --- hypertiling/neighbours.py | 168 +++++++++++++++++++++++--------------- 1 file changed, 101 insertions(+), 67 deletions(-) diff --git a/hypertiling/neighbours.py b/hypertiling/neighbours.py index a7b0ed6..cedbe93 100644 --- a/hypertiling/neighbours.py +++ b/hypertiling/neighbours.py @@ -184,74 +184,108 @@ def find_nn_optimized(tiling, nn_dist, eps=1e-5): # currently this is our fastest algorithm for large tessellations def find_nn_optimized_slice(tiling, nn_dist, eps=1e-5): - totalnum = len(tiling) # total number of polygons - p = tiling.p # number of edges of each polygon - pps = int((totalnum-1)/p) # polygons per sector (excluding center) - - def shift(lst,times): - lst = sorted(lst) - haszero = (0 in lst) - - if haszero: - lsta = np.array(lst[1:]) + times*pps - lsta[lsta>totalnum-1] -= (totalnum-1) - lsta[lsta<1] += (totalnum-1) - return sorted([0]+list(lsta)) - else: - lsta = np.array(lst) + times*pps - lsta[lsta>totalnum-1] -= (totalnum-1) - lsta[lsta<1] += (totalnum-1) - return sorted(list(lsta)) + + if tiling.center == "vertex": + print("algorithm >optimized_slice< currently not available for vertex-centered tilings!") + print("falling back to >optimized<") + return find_nn_optimized(tiling, nn_dist) + + totalnum = len(tiling) # total number of polygons + p = tiling.p # number of edges of each polygon + q = tiling.q + if tiling.center == "cell": + pps = int((totalnum-1)/p) # polygons per sector (excluding center) + inc = 1 + elif tiling.center == "vertex": + pps = int(totalnum/q) + inc = 0 + + + # shifts local neighbour list to another sector + def shift(lst,times): + lst = sorted(lst) + haszero = (0 in lst) + + # fundamental cell requires a little extra care + if haszero: + lsta = np.array(lst[1:]) + times*pps + lsta[lsta>totalnum-1] -= (totalnum-1) + lsta[lsta<1] += (totalnum-1) + return sorted([0]+list(lsta)) + else: + lsta = np.array(lst) + times*pps + lsta[lsta>totalnum-1] -= (totalnum-1) + lsta[lsta<1] += (totalnum-1) + return sorted(list(lsta)) + + # increment indices by one + def increment(lst): + return list(np.array(lst)+1) + + + + # slice the first three sectors + # we are gonna look for neighbours of polygons in the second sector + pgons = tiling[:3*pps+inc] + # this is a place where the algorithm can be further improved, performance-wise + # we do not need the entire 1st and 3rd sectors, but only those cells close to + # the boundary of the 2nd sector + + + v = np.zeros((len(pgons), 3)) + for i, poly in enumerate(pgons): + v[i] = poly.centerW() + + searchdist = nn_dist + eps + searchdist = np.cosh(searchdist) - def increment(lst): - return list(np.array(lst)+1) - - pgons = tiling[:1+3*pps] - - v = np.zeros((len(pgons), 3)) - for i, poly in enumerate(pgons): - v[i] = poly.centerW() - - searchdist = nn_dist + eps - searchdist = np.cosh(searchdist) - - # prepare list - nbrlst = [] - # loop over polygons - for i, poly in enumerate(pgons[1+pps:1+2*pps]): - w = poly.centerW() - dists = lorentzian_distance(v, w) - dists[(dists < 1)] = 1 # this costs some %, but reduces warnings - indxs = np.where(dists < searchdist)[0] # radius search - self = np.argwhere(indxs == poly.idx-1) # find self - indxs = np.delete(indxs, self) # delete self - nums = [pgons[ind].idx-1 for ind in indxs] # replacing indices by actual polygon number - nbrlst.append(nums) - - - # prepare full list - retlist = [] - - # fundamental cell - lstzero = [] - for ps in range(0,p): - lstzero.append(ps*pps+1) - retlist.append((increment(lstzero))) - - # first sector - for lst in nbrlst: - retlist.append(increment(shift(lst, -1))) - - # second sector - for lst in nbrlst: - retlist.append(increment(lst)) - - # remaining sectors - for ps in range(2,p): - for lst in nbrlst: - retlist.append(increment(shift(lst, ps-1))) - - return retlist + # prepare list + nbrlst = [] + # loop over polygons + for i, poly in enumerate(pgons[pps+inc:2*pps+inc]): + w = poly.centerW() + dists = lorentzian_distance(v, w) + dists[(dists < 1)] = 1 # this costs some %, but reduces warnings + indxs = np.where(dists < searchdist)[0] # radius search + self = np.argwhere(indxs == poly.idx-1) # find self + indxs = np.delete(indxs, self) # delete self + nums = [pgons[ind].idx-1 for ind in indxs] # replacing indices by actual polygon number + nbrlst.append(nums) + + + # prepare full list + retlist = [] + + + if tiling.center == "cell": + k = p + elif tiling.center == "vertex": + k = q + + + if tiling.center == "cell": + # fundamental cell + lstzero = [] + for ps in range(0,k): + lstzero.append(ps*pps+1) + retlist.append((increment(lstzero))) + + # first sector + for lst in nbrlst: + retlist.append(increment(shift(lst, -1))) + + # second sector + for lst in nbrlst: + retlist.append(increment(lst)) + + # remaining sectors + for ps in range(2,k): + for lst in nbrlst: + retlist.append(increment(shift(lst, ps-1))) + + return retlist + + # finds nearest neighbors by exploiting the discrete rotational symmetry of the lattice -- GitLab From a974f1b87ce01a2be893467bf120789de8432be8 Mon Sep 17 00:00:00 2001 From: Manuel Date: Fri, 20 May 2022 07:56:33 +0200 Subject: [PATCH 06/12] new test compares output of different neighbour algorithms --- .gitlab-ci.yml | 2 ++ tests/test_compare_neighbours.py | 27 +++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 tests/test_compare_neighbours.py diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index ee54269..51da963 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -64,6 +64,7 @@ unit-test-plain: - echo "Testing without fancy packages..." - python3 -m tests.test_core - python3 -m tests.test_neighbours + - python3 -m tests.test_comp_nbrs unit-test-fancy: image: git.physik.uni-wuerzburg.de:25812/z03/pdi/debian:bullseye-gfortran-blas-lapack-fftw-hdf5-scipy3 @@ -74,6 +75,7 @@ unit-test-fancy: - echo "Testing with numba and sortedcontainers..." - python3 -m tests.test_core - python3 -m tests.test_neighbours + - python3 -m tests.test_comp_nbrs sphinx-doc: image: git.physik.uni-wuerzburg.de:25812/z03/pdi/debian:bullseye-gfortran-blas-lapack-fftw-hdf5-scipy3 diff --git a/tests/test_compare_neighbours.py b/tests/test_compare_neighbours.py new file mode 100644 index 0000000..4e04293 --- /dev/null +++ b/tests/test_compare_neighbours.py @@ -0,0 +1,27 @@ +import unittest +from hypertiling import HyperbolicTiling +from hypertiling.neighbours import find + + +kernel = "flo" + +lattices = [(3,7,7,), (7,3,7), (5,4,6), (4,5,6), (9,3,4), (4,10,3), (3,8,4), (6,4,4)] + +print("Testing different neighbour search algorithms against each other") + +class TestCompareNeighbours(unittest.TestCase): + def test_comp_nbrs(self): + + for p, q, nlayer in lattices: + print("Constructing", p, q, nlayer, "lattice") + T = HyperbolicTiling(p, q, nlayer, kernel=kernel, center="cell") + T.generate() + + nbrs1 = find(T, which="optimized") + nbrs2 = find(T, which="optimized_slice") + + self.assertTrue(nbrs1 == nbrs2) + + +if __name__ == '__main__': + unittest.main() -- GitLab From cb077a237ed1a95057b924d832e512c11dd6f9d3 Mon Sep 17 00:00:00 2001 From: Manuel Date: Fri, 20 May 2022 08:01:51 +0200 Subject: [PATCH 07/12] expand test to include brute force algorithm --- tests/test_compare_neighbours.py | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/tests/test_compare_neighbours.py b/tests/test_compare_neighbours.py index 4e04293..2fd5ea5 100644 --- a/tests/test_compare_neighbours.py +++ b/tests/test_compare_neighbours.py @@ -3,15 +3,15 @@ from hypertiling import HyperbolicTiling from hypertiling.neighbours import find -kernel = "flo" - -lattices = [(3,7,7,), (7,3,7), (5,4,6), (4,5,6), (9,3,4), (4,10,3), (3,8,4), (6,4,4)] - print("Testing different neighbour search algorithms against each other") class TestCompareNeighbours(unittest.TestCase): def test_comp_nbrs(self): + kernel = "flo" + + lattices = [(3,7,7,), (7,3,7), (5,4,6), (4,5,6), (9,3,4), (4,10,3), (3,8,4), (6,4,4)] + for p, q, nlayer in lattices: print("Constructing", p, q, nlayer, "lattice") T = HyperbolicTiling(p, q, nlayer, kernel=kernel, center="cell") @@ -22,6 +22,19 @@ class TestCompareNeighbours(unittest.TestCase): self.assertTrue(nbrs1 == nbrs2) + kernel = "flo" + + lattices = [(3,7,4), (7,3,4), (5,4,4), (4,5,4), (9,3,4), (4,10,3), (3,8,4), (6,4,4)] + + for p, q, nlayer in lattices: + print("Constructing", p, q, nlayer, "lattice") + T = HyperbolicTiling(p, q, nlayer, kernel=kernel, center="cell") + T.generate() + + nbrs1 = find(T, which="optimized") + nbrs2 = find(T, which="brute_force") + + self.assertTrue(nbrs1 == nbrs2) if __name__ == '__main__': unittest.main() -- GitLab From eefc1bcda21a9dbf0c55c21e94c6fe0f3289899f Mon Sep 17 00:00:00 2001 From: Manuel Date: Fri, 20 May 2022 08:09:28 +0200 Subject: [PATCH 08/12] add docstring --- hypertiling/neighbours.py | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/hypertiling/neighbours.py b/hypertiling/neighbours.py index cedbe93..3dab24b 100644 --- a/hypertiling/neighbours.py +++ b/hypertiling/neighbours.py @@ -179,10 +179,30 @@ def find_nn_optimized(tiling, nn_dist, eps=1e-5): return retlist -# combines both the benefits of of numpy vectorization (used in "find_nn_optimized") and -# applying the neighbour search only to a p-sector of the tiling (done in "find_nn_slice") -# currently this is our fastest algorithm for large tessellations def find_nn_optimized_slice(tiling, nn_dist, eps=1e-5): + """ + combines both the benefits of of numpy vectorization (used in "find_nn_optimized") and + applying the neighbour search only to a p-sector of the tiling (as done in "find_nn_slice") + currently this is our fastest algorithm for large tessellations + + currently only working for cell-centered tilings (to do!) + + Attributes + ---------- + + tiling : HyperbolicTiling + the tiling object in which adjacent cell are to be searched for + nn_dist : float + the expected distance between neighbours + eps : float + increase nn_dist a little in order to make it more stable + + Returns + ------- + + List of lists, where sublist i contains the indices of the neighbour of vertex i in the tiling + + """ if tiling.center == "vertex": @@ -232,10 +252,12 @@ def find_nn_optimized_slice(tiling, nn_dist, eps=1e-5): # the boundary of the 2nd sector + # store center coordinates in array for faster access v = np.zeros((len(pgons), 3)) for i, poly in enumerate(pgons): v[i] = poly.centerW() + # the search distance (we are doing a radius search) searchdist = nn_dist + eps searchdist = np.cosh(searchdist) @@ -253,7 +275,7 @@ def find_nn_optimized_slice(tiling, nn_dist, eps=1e-5): nbrlst.append(nums) - # prepare full list + # prepare full output list retlist = [] -- GitLab From 17fd6667e1bd432a22a9bc0c74ee4059c9a88417 Mon Sep 17 00:00:00 2001 From: Manuel Date: Fri, 20 May 2022 08:23:37 +0200 Subject: [PATCH 09/12] fix tests --- tests/test_compare_neighbours.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_compare_neighbours.py b/tests/test_compare_neighbours.py index 2fd5ea5..4faf043 100644 --- a/tests/test_compare_neighbours.py +++ b/tests/test_compare_neighbours.py @@ -5,7 +5,7 @@ from hypertiling.neighbours import find print("Testing different neighbour search algorithms against each other") -class TestCompareNeighbours(unittest.TestCase): +class TestCore(unittest.TestCase): def test_comp_nbrs(self): kernel = "flo" -- GitLab From 7284d59bfd59ec55a92b17a4b4ae017f3559ee11 Mon Sep 17 00:00:00 2001 From: Manuel Date: Fri, 20 May 2022 08:36:57 +0200 Subject: [PATCH 10/12] fix tests (again) --- .gitlab-ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 51da963..23fe0af 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -64,7 +64,7 @@ unit-test-plain: - echo "Testing without fancy packages..." - python3 -m tests.test_core - python3 -m tests.test_neighbours - - python3 -m tests.test_comp_nbrs + - python3 -m tests.test_compare_neighbours unit-test-fancy: image: git.physik.uni-wuerzburg.de:25812/z03/pdi/debian:bullseye-gfortran-blas-lapack-fftw-hdf5-scipy3 @@ -75,7 +75,7 @@ unit-test-fancy: - echo "Testing with numba and sortedcontainers..." - python3 -m tests.test_core - python3 -m tests.test_neighbours - - python3 -m tests.test_comp_nbrs + - python3 -m tests.test_compare_neighbours sphinx-doc: image: git.physik.uni-wuerzburg.de:25812/z03/pdi/debian:bullseye-gfortran-blas-lapack-fftw-hdf5-scipy3 -- GitLab From cbe09cbda24fb30ff27ec2aeec89f2a32c6784be Mon Sep 17 00:00:00 2001 From: Manuel Date: Fri, 20 May 2022 13:55:19 +0200 Subject: [PATCH 11/12] add docstring --- hypertiling/hyperpolygon.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/hypertiling/hyperpolygon.py b/hypertiling/hyperpolygon.py index d7ed006..b83ed88 100644 --- a/hypertiling/hyperpolygon.py +++ b/hypertiling/hyperpolygon.py @@ -184,8 +184,19 @@ class HyperPolygon: self.angle = math.degrees(math.atan2(self.centerP().imag, self.centerP().real)) self.angle += 360 if self.angle < 0 else 0 - # compute in which sector out of k sectors the polygon resides + def find_sector(self, k, offset=0): + """ + compute in which sector out of k sectors the polygon resides + + Arguments + --------- + k : int + number of equal-sized sectors + offset : float, optional + rotate sectors by an angle + """ + self.sector = floor((self.angle-offset)/(360/k)) # mirror on the x-axis -- GitLab From e6952888e638040637d332e5f7b95ddaaa752793 Mon Sep 17 00:00:00 2001 From: Manuel Date: Fri, 20 May 2022 13:56:00 +0200 Subject: [PATCH 12/12] replace np by math function --- hypertiling/neighbours.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/hypertiling/neighbours.py b/hypertiling/neighbours.py index 3dab24b..1609c26 100644 --- a/hypertiling/neighbours.py +++ b/hypertiling/neighbours.py @@ -1,4 +1,5 @@ import numpy as np +import math from .distance import weierstrass_distance, lorentzian_distance # wrapper to provide a nicer interface @@ -161,7 +162,7 @@ def find_nn_optimized(tiling, nn_dist, eps=1e-5): # add something to nn_dist to avoid rounding problems # does not need to be particularly small searchdist = nn_dist + eps - searchdist = np.cosh(searchdist) + searchdist = math.cosh(searchdist) # prepare list retlist = [] -- GitLab