From bb083e18809fd33f67f899d72958b66a2b08484f Mon Sep 17 00:00:00 2001 From: Michael Wimmer <wimmer@lorentz.leidenuniv.nl> Date: Tue, 25 Sep 2012 16:15:51 +0200 Subject: [PATCH] fix the erraneous behavior of numpy.any() --- kwant/physics/selfenergy.py | 12 +++++++++--- kwant/solvers/common.py | 6 +++++- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/kwant/physics/selfenergy.py b/kwant/physics/selfenergy.py index c47888cd..82973596 100644 --- a/kwant/physics/selfenergy.py +++ b/kwant/physics/selfenergy.py @@ -40,7 +40,9 @@ def setup_linsys(h_onslice, h_hop, tol=1e6): # Inter-slice hopping is zero. The current algorithm is not suited to # treat this extremely singular case. - assert np.any(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 + assert np.any(h_hop.real) or np.any(h_hop.imag) eps = np.finfo(np.common_type(h_onslice, h_hop)).eps @@ -524,7 +526,9 @@ def self_energy(h_onslice, h_hop, tol=1e6): m = h_hop.shape[1] - if not np.any(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)): return np.zeros((m, m)) if (h_onslice.shape[0] != h_onslice.shape[1] or @@ -662,7 +666,9 @@ def modes(h_onslice, h_hop, tol=1e6): h_onslice.shape[0] != h_hop.shape[0]): raise ValueError("Incompatible matrix sizes for h_onslice and h_hop.") - if not np.any(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)): n = h_hop.shape[0] svd = (np.empty((n, 0)), np.empty((0, 0)), np.empty((0, m))) return Modes(np.empty((0, 0)), np.empty((0, 0)), 0, svd) diff --git a/kwant/solvers/common.py b/kwant/solvers/common.py index 18d3948f..efcbf164 100644 --- a/kwant/solvers/common.py +++ b/kwant/solvers/common.py @@ -169,7 +169,11 @@ class SparseSolver(object): v = lead.inter_slice_hopping() modes = physics.modes(h, v) lead_info.append(modes) - if not np.any(v): + + # Note: np.any(v) returns (at least from numpy + # 1.6.1 - 1.8-devel) False if v is purely + # imaginary + if not (np.any(v.real) or np.any(v.imag)): # See comment about zero-shaped sparse matrices at the top. rhs.append(np.zeros((lhs.shape[1], 0))) continue -- GitLab