Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
K
kwant
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Michael Wimmer
kwant
Commits
78e59754
Commit
78e59754
authored
12 years ago
by
Michael Wimmer
Committed by
Christoph Groth
12 years ago
Browse files
Options
Downloads
Patches
Plain Diff
make slicer work with overlapping left and right slices (only one slice returned); add test case
parent
e602b032
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
kwant/graph/slicer.pyx
+7
-2
7 additions, 2 deletions
kwant/graph/slicer.pyx
kwant/graph/tests/test_slicer.py
+25
-25
25 additions, 25 deletions
kwant/graph/tests/test_slicer.py
with
32 additions
and
27 deletions
kwant/graph/slicer.pyx
+
7
−
2
View file @
78e59754
...
...
@@ -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
,
...
...
This diff is collapsed.
Click to expand it.
kwant/graph/tests/test_slicer.py
+
25
−
25
View file @
78e59754
...
...
@@ -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
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment