From 0b51b433024776dd8d05a8c1ebef4a5cf12fa51e Mon Sep 17 00:00:00 2001 From: Anton Akhmerov <anton.akhmerov@gmail.com> Date: Mon, 31 Dec 2018 02:10:06 +0100 Subject: [PATCH] use an own implementation of summing sparse matrix columns This silences a deprecation warning on scipy < 1.2 and numpy > 1.15. --- kwant/physics/symmetry.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/kwant/physics/symmetry.py b/kwant/physics/symmetry.py index 9bcfee7e..9420f52d 100644 --- a/kwant/physics/symmetry.py +++ b/kwant/physics/symmetry.py @@ -16,6 +16,18 @@ def almost_identity(mat): return np.all(abs(mat - identity(mat.shape[0])).data < 1e-10) +def _column_sum(matrix): + """Sum the columns of a sparse matrix. + + This is fully analogous to ``matrix.sum(0)``, and uses an implementation + similar to that in scipy v1.1.0, however it avoids using ``numpy.matrix`` + interface and therefore does not raise a ``PendingDeprecationWarning``. + This should be removed once we depend on scipy v1.2.0, where the warning is + silenced. + """ + return matrix.T @ np.ones(matrix.shape[0]) + + def cond_conj(op, conj): return op.conj() if conj else op @@ -106,8 +118,9 @@ class DiscreteSymmetry: symms[i] = symm if projectors is not None: - projectors = [p[:, np.asarray(abs(p).sum(0)).flatten() > 1e-10] - for p in projectors] + projectors = [ + p[:, _column_sum(abs(p)) > 1e-10] for p in projectors + ] if not almost_identity(sum(projector.dot(projector.conj().T) for projector in projectors)): raise ValueError("Projectors should stack to a unitary matrix.") -- GitLab