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
89572421
Commit
89572421
authored
9 years ago
by
Anton Akhmerov
Browse files
Options
Downloads
Patches
Plain Diff
clarify handling of old numpy versions
parent
134a3e82
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/physics/leads.py
+16
-8
16 additions, 8 deletions
kwant/physics/leads.py
with
16 additions
and
8 deletions
kwant/physics/leads.py
+
16
−
8
View file @
89572421
...
...
@@ -20,6 +20,19 @@ dot = np.dot
__all__
=
[
'
selfenergy
'
,
'
modes
'
,
'
PropagatingModes
'
,
'
StabilizedModes
'
]
if
np
.
__version__
>=
'
1.8
'
:
complex_any
=
np
.
any
else
:
def
complex_any
(
array
):
"""
Check if a complex array has nonzero entries.
This function is needed due to a bug in numpy<1.8.
"""
# TODO: Remove separate checking of real and imaginary parts once we depend
# on numpy>=1.8 (it is present due to a bug in earlier versions).
return
np
.
any
(
array
.
real
)
or
np
.
any
(
array
.
imag
)
# Container classes
Linsys
=
namedtuple
(
'
Linsys
'
,
[
'
eigenproblem
'
,
'
v
'
,
'
extract
'
])
...
...
@@ -162,11 +175,9 @@ def setup_linsys(h_cell, h_hop, tol=1e6, stabilization=None):
if
stabilization
is
not
None
:
stabilization
=
list
(
stabilization
)
if
not
(
np
.
any
(
h_hop
.
real
)
or
np
.
any
(
h_hop
.
imag
)
):
if
not
complex_
any
(
h_hop
):
# Inter-cell hopping is zero. The current algorithm is not suited to
# treat this extremely singular case.
# Note: np.any(h_hop) returns (at least from numpy 1.6.*)
# False if h_hop is purely imaginary
raise
ValueError
(
"
Inter-cell hopping is exactly zero.
"
)
# If both h and t are real, it may be possible to use the real eigenproblem.
...
...
@@ -495,8 +506,7 @@ def make_proper_modes(lmbdainv, psi, extract, tol=1e6):
order
=
np
.
lexsort
([
velocities
,
-
np
.
sign
(
velocities
)
*
momenta
,
np
.
sign
(
velocities
)])
# The following is necessary due to wrong numpy handling of zero length
# arrays, which is going to be fixed in numpy 1.8.
# TODO: Remove the check once we depende on numpy>=1.8.
if
not
len
(
order
):
order
=
slice
(
None
)
velocities
=
velocities
[
order
]
...
...
@@ -567,9 +577,7 @@ def modes(h_cell, h_hop, tol=1e6, stabilization=None):
h_cell
.
shape
[
0
]
!=
h_hop
.
shape
[
0
]):
raise
ValueError
(
"
Incompatible matrix sizes for h_cell and h_hop.
"
)
# Note: np.any(h_hop) returns (at least from numpy 1.6.1 - 1.8-devel)
# False if h_hop is purely imaginary
if
not
(
np
.
any
(
h_hop
.
real
)
or
np
.
any
(
h_hop
.
imag
)):
if
not
complex_any
(
h_hop
):
v
=
np
.
empty
((
0
,
m
))
return
(
PropagatingModes
(
np
.
empty
((
0
,
n
)),
np
.
empty
((
0
,)),
np
.
empty
((
0
,))),
...
...
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