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

make slicer work with overlapping left and right slices (only one slice returned); add test case

parent e602b032
Branches
Tags
No related merge requests found
......@@ -17,8 +17,8 @@ def slice(CGraph graph, left, right):
cdef c_slicer.Slicing *slicing
cdef int i, j, slc_size
leftarr = np.array(left, dtype=gint_dtype)
rightarr = np.array(right, dtype=gint_dtype)
leftarr = np.unique(np.array(left, dtype=gint_dtype))
rightarr = np.unique(np.array(right, dtype=gint_dtype))
if leftarr.ndim != 1:
raise ValueError("Left cannot be interpreted as a 1D array.")
......@@ -29,6 +29,11 @@ def slice(CGraph graph, left, right):
if leftarr.size == 0 or rightarr.size == 0:
raise ValueError("Empty boundary arrays are not supported yet.")
# slicing only possible if there is no overlap between
# left and right slices
if np.intersect1d(rightarr, leftarr, assume_unique=True).size:
return (tuple(range(graph.num_nodes)), )
slicing = c_slicer.slice(graph.num_nodes,
graph.heads_idxs,
graph.heads,
......
......@@ -25,30 +25,30 @@ def assert_sanity(graph, slices):
def test_rectangle():
l = 10
w = 5
sys = kwant.Builder()
lead = kwant.Builder(kwant.TranslationalSymmetry([(-1, 0)]))
lat = kwant.lattice.Square()
lead[(lat(0, i) for i in xrange(w))] = 0
sys[(lat(j, i) for j in xrange(l) for i in xrange(w))] = 0
for s in [lead, sys]:
for delta in [(1, 0), (0, 1)]:
s[s.possible_hoppings(delta, lat, lat)] = -1
sys.attach_lead(lead)
sys.attach_lead(lead.reversed())
fsys = sys.finalized()
slices = slicer.slice(fsys.graph,
fsys.lead_neighbor_seqs[0],
fsys.lead_neighbor_seqs[1])
# In the rectangle case, the slicing is very constricted and we know that
# all slices must have the same shape.
assert len(slices) == l
for j in xrange(l):
assert len(slices[j]) == w
assert_sanity(fsys.graph, slices)
for l in [1, 2, 5, 10]:
sys = kwant.Builder()
lead = kwant.Builder(kwant.TranslationalSymmetry([(-1, 0)]))
lat = kwant.lattice.Square()
lead[(lat(0, i) for i in xrange(w))] = 0
sys[(lat(j, i) for j in xrange(l) for i in xrange(w))] = 0
for s in [lead, sys]:
for delta in [(1, 0), (0, 1)]:
s[s.possible_hoppings(delta, lat, lat)] = -1
sys.attach_lead(lead)
sys.attach_lead(lead.reversed())
fsys = sys.finalized()
slices = slicer.slice(fsys.graph,
fsys.lead_neighbor_seqs[0],
fsys.lead_neighbor_seqs[1])
# In the rectangle case, the slicing is very constricted and
# we know that all slices must have the same shape.
assert len(slices) == l
for j in xrange(l):
assert len(slices[j]) == w
assert_sanity(fsys.graph, slices)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment