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
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD 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
Joseph Weston
kwant
Commits
6467f81c
Commit
6467f81c
authored
11 years ago
by
Christoph Groth
Browse files
Options
Downloads
Patches
Plain Diff
hamiltonian_submatrix: eliminate zeros in sparse matrices
parent
dc4f9dea
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
kwant/_system.pyx
+32
-20
32 additions, 20 deletions
kwant/_system.pyx
with
32 additions
and
20 deletions
kwant/_system.pyx
+
32
−
20
View file @
6467f81c
...
...
@@ -31,6 +31,7 @@ def make_sparse(ham, args, CGraph gr, diag,
cdef
complex
[:,
:]
h
cdef
gint
[:,
:]
rows_cols
cdef
complex
[:]
data
cdef
complex
value
matrix
=
ta
.
matrix
...
...
@@ -59,10 +60,12 @@ def make_sparse(ham, args, CGraph gr, diag,
raise
ValueError
(
msg
.
format
(
fs
,
fs
))
for
i
in
xrange
(
h
.
shape
[
0
]):
for
j
in
xrange
(
h
.
shape
[
1
]):
data
[
k
]
=
h
[
i
,
j
]
rows_cols
[
0
,
k
]
=
i
+
to_off
[
n_ts
]
rows_cols
[
1
,
k
]
=
j
+
from_off
[
n_fs
]
k
+=
1
value
=
h
[
i
,
j
]
if
value
!=
0
:
data
[
k
]
=
value
rows_cols
[
0
,
k
]
=
i
+
to_off
[
n_ts
]
rows_cols
[
1
,
k
]
=
j
+
from_off
[
n_fs
]
k
+=
1
nbors
=
gr
.
out_neighbors
(
fs
)
for
ts
in
nbors
.
data
[:
nbors
.
size
]:
...
...
@@ -74,12 +77,15 @@ def make_sparse(ham, args, CGraph gr, diag,
raise
ValueError
(
msg
.
format
(
fs
,
ts
))
for
i
in
xrange
(
h
.
shape
[
0
]):
for
j
in
xrange
(
h
.
shape
[
1
]):
data
[
k
]
=
h
[
i
,
j
]
rows_cols
[
0
,
k
]
=
i
+
to_off
[
n_ts
]
rows_cols
[
1
,
k
]
=
j
+
from_off
[
n_fs
]
k
+=
1
value
=
h
[
i
,
j
]
if
value
!=
0
:
data
[
k
]
=
value
rows_cols
[
0
,
k
]
=
i
+
to_off
[
n_ts
]
rows_cols
[
1
,
k
]
=
j
+
from_off
[
n_fs
]
k
+=
1
return
sp
.
coo_matrix
((
data
,
rows_cols
),
shape
=
(
to_off
[
-
1
],
from_off
[
-
1
]))
return
sp
.
coo_matrix
((
data
[:
k
],
rows_cols
[:,
:
k
]),
shape
=
(
to_off
[
-
1
],
from_off
[
-
1
]))
@cython.boundscheck
(
False
)
...
...
@@ -93,6 +99,7 @@ def make_sparse_full(ham, args, CGraph gr, diag,
cdef
complex
[:,
:]
h
cdef
gint
[:,
:]
rows_cols
cdef
complex
[:]
data
cdef
complex
value
matrix
=
ta
.
matrix
n
=
gr
.
num_nodes
...
...
@@ -116,10 +123,12 @@ def make_sparse_full(ham, args, CGraph gr, diag,
raise
ValueError
(
msg
.
format
(
fs
,
fs
))
for
i
in
xrange
(
h
.
shape
[
0
]):
for
j
in
xrange
(
h
.
shape
[
1
]):
data
[
k
]
=
h
[
i
,
j
]
rows_cols
[
0
,
k
]
=
i
+
to_off
[
fs
]
rows_cols
[
1
,
k
]
=
j
+
from_off
[
fs
]
k
+=
1
value
=
h
[
i
,
j
]
if
value
!=
0
:
data
[
k
]
=
value
rows_cols
[
0
,
k
]
=
i
+
to_off
[
fs
]
rows_cols
[
1
,
k
]
=
j
+
from_off
[
fs
]
k
+=
1
nbors
=
gr
.
out_neighbors
(
fs
)
for
ts
in
nbors
.
data
[:
nbors
.
size
]:
...
...
@@ -130,13 +139,16 @@ def make_sparse_full(ham, args, CGraph gr, diag,
raise
ValueError
(
msg
.
format
(
fs
,
ts
))
for
i
in
xrange
(
h
.
shape
[
0
]):
for
j
in
xrange
(
h
.
shape
[
1
]):
data
[
k
]
=
h
[
i
,
j
]
data
[
k
+
1
]
=
h
[
i
,
j
].
conjugate
()
rows_cols
[
1
,
k
+
1
]
=
rows_cols
[
0
,
k
]
=
i
+
to_off
[
ts
]
rows_cols
[
0
,
k
+
1
]
=
rows_cols
[
1
,
k
]
=
j
+
from_off
[
fs
]
k
+=
2
return
sp
.
coo_matrix
((
data
,
rows_cols
),
shape
=
(
to_off
[
-
1
],
from_off
[
-
1
]))
value
=
h
[
i
,
j
]
if
value
!=
0
:
data
[
k
]
=
value
data
[
k
+
1
]
=
h
[
i
,
j
].
conjugate
()
rows_cols
[
1
,
k
+
1
]
=
rows_cols
[
0
,
k
]
=
i
+
to_off
[
ts
]
rows_cols
[
0
,
k
+
1
]
=
rows_cols
[
1
,
k
]
=
j
+
from_off
[
fs
]
k
+=
2
return
sp
.
coo_matrix
((
data
[:
k
],
rows_cols
[:,
:
k
]),
shape
=
(
to_off
[
-
1
],
from_off
[
-
1
]))
@cython.boundscheck
(
False
)
...
...
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