From baa1561ea650d780f7d08dfa8cbf745446607913 Mon Sep 17 00:00:00 2001
From: Joseph Weston <joseph.weston08@gmail.com>
Date: Fri, 24 Jul 2015 22:27:30 +0200
Subject: [PATCH] initialize numpy arrays to zero

Before this commit, if there was a lead for which
the inter-cell hopping matrix was the zero matrix, then
kwant.physics.modes() returned arrays with uninitialized memory.
---
 kwant/physics/leads.py | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/kwant/physics/leads.py b/kwant/physics/leads.py
index e7335a13..e04db48e 100644
--- a/kwant/physics/leads.py
+++ b/kwant/physics/leads.py
@@ -572,10 +572,10 @@ def modes(h_cell, h_hop, tol=1e6, stabilization=None):
     # 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)):
-        v = np.empty((0, m))
-        return PropagatingModes(np.empty((0, n)), np.empty((0,)),
-                                np.empty((0,))), \
-               StabilizedModes(np.empty((0, 0)), np.empty((0, 0)), 0, v)
+        v = np.zeros((0, m))
+        return (PropagatingModes(np.zeros((0, n)), np.zeros((0,)),
+                                 np.zeros((0,))),
+                StabilizedModes(np.zeros((0, 0)), np.zeros((0, 0)), 0, v))
 
     # Defer most of the calculation to helper routines.
     matrices, v, extract = setup_linsys(h_cell, h_hop, tol, stabilization)
-- 
GitLab