From 040f2799863f10434797d4c3cdc7479f86b55de3 Mon Sep 17 00:00:00 2001 From: Joseph Weston <joseph.weston08@gmail.com> Date: Sat, 7 Nov 2015 16:41:44 +0100 Subject: [PATCH] clean up residual cruft from 2to3 --- kwant/builder.py | 13 ++++++------- kwant/lattice.py | 1 - kwant/linalg/decomp_lu.py | 12 ++++++------ kwant/linalg/lll.py | 2 +- kwant/linalg/mumps.py | 4 ++-- 5 files changed, 15 insertions(+), 17 deletions(-) diff --git a/kwant/builder.py b/kwant/builder.py index 2bb18572..b8a37d17 100644 --- a/kwant/builder.py +++ b/kwant/builder.py @@ -19,7 +19,6 @@ import tinyarray as ta import numpy as np from . import system, graph, KwantDeprecationWarning from ._common import ensure_isinstance -import collections @@ -795,7 +794,7 @@ class Builder(object): iter_stack = [None] while iter_stack: for key in itr: - while isinstance(key, collections.Callable): + while callable(key): key = key(self) if isinstance(key, tuple): # Site instances are also tuples. @@ -826,7 +825,7 @@ class Builder(object): b, a = sym.to_fd(b, a) assert not sym.in_fd(a) value = self._get_edge(b, a) - if isinstance(value, collections.Callable): + if callable(value): assert not isinstance(value, HermConjOfFunc) value = HermConjOfFunc(value) else: @@ -1385,7 +1384,7 @@ class FiniteSystem(system.FiniteSystem): def hamiltonian(self, i, j, *args): if i == j: value = self.onsite_hamiltonians[i] - if isinstance(value, collections.Callable): + if callable(value): value = value(self.sites[i], *args) else: edge_id = self.graph.first_edge_id(i, j) @@ -1395,7 +1394,7 @@ class FiniteSystem(system.FiniteSystem): i, j = j, i edge_id = self.graph.first_edge_id(i, j) value = self.hoppings[edge_id] - if isinstance(value, collections.Callable): + if callable(value): sites = self.sites value = value(sites[i], sites[j], *args) if conj: @@ -1419,7 +1418,7 @@ class InfiniteSystem(system.InfiniteSystem): if i >= self.cell_size: i -= self.cell_size value = self.onsite_hamiltonians[i] - if isinstance(value, collections.Callable): + if callable(value): value = value(self.symmetry.to_fd(self.sites[i]), *args) else: edge_id = self.graph.first_edge_id(i, j) @@ -1429,7 +1428,7 @@ class InfiniteSystem(system.InfiniteSystem): i, j = j, i edge_id = self.graph.first_edge_id(i, j) value = self.hoppings[edge_id] - if isinstance(value, collections.Callable): + if callable(value): sites = self.sites site_i = sites[i] site_j = sites[j] diff --git a/kwant/lattice.py b/kwant/lattice.py index 1f908473..ff74ecd2 100644 --- a/kwant/lattice.py +++ b/kwant/lattice.py @@ -617,7 +617,6 @@ class TranslationalSymmetry(builder.Symmetry): det_m = int(round(np.linalg.det(m))) if det_m == 0: - print(m) raise RuntimeError('Adding site family failed.') det_x_inv_m = np.array(np.round(det_m * np.linalg.inv(m)), dtype=int) diff --git a/kwant/linalg/decomp_lu.py b/kwant/linalg/decomp_lu.py index 0db3bc4f..79accc25 100644 --- a/kwant/linalg/decomp_lu.py +++ b/kwant/linalg/decomp_lu.py @@ -61,13 +61,13 @@ def lu_factor(a, overwrite_a=False): return lapack.cgetrf(a) -def lu_solve(xxx_todo_changeme, b): +def lu_solve(matrix_factorization, b): """Solve a linear system of equations, a x = b, given the LU factorization of a Parameters ---------- - (lu, piv, singular) + matrix_factorization Factorization of the coefficient matrix a, as given by lu_factor b : array (vector or matrix) Right-hand side @@ -77,7 +77,7 @@ def lu_solve(xxx_todo_changeme, b): x : array (vector or matrix) Solution to the system """ - (lu, ipiv, singular) = xxx_todo_changeme + (lu, ipiv, singular) = matrix_factorization if singular: raise RuntimeWarning("In lu_solve: the flag singular indicates " "a singular matrix. Result of solve step " @@ -102,7 +102,7 @@ def lu_solve(xxx_todo_changeme, b): return lapack.cgetrs(lu, ipiv, b) -def rcond_from_lu(xxx_todo_changeme1, norm_a, norm="1"): +def rcond_from_lu(matrix_factorization, norm_a, norm="1"): """Compute the reciprocal condition number from the LU decomposition as returned from lu_factor(), given additionally the norm of the matrix a in norm_a. @@ -112,7 +112,7 @@ def rcond_from_lu(xxx_todo_changeme1, norm_a, norm="1"): Parameters ---------- - (lu, piv, singular) + matrix_factorization Factorization of the matrix a, as given by lu_factor norm_a : float or complex norm of the original matrix a (type of norm is specified in norm) @@ -126,7 +126,7 @@ def rcond_from_lu(xxx_todo_changeme1, norm_a, norm="1"): reciprocal condition number of a with respect to the type of matrix norm specified in norm """ - (lu, ipiv, singular) = xxx_todo_changeme1 + (lu, ipiv, singular) = matrix_factorization if not norm in ("1", "I"): raise ValueError("norm in rcond_from_lu must be either '1' or 'I'") norm = norm.encode('utf8') # lapack expects bytes diff --git a/kwant/linalg/lll.py b/kwant/linalg/lll.py index 3f170e38..9a29b473 100644 --- a/kwant/linalg/lll.py +++ b/kwant/linalg/lll.py @@ -68,7 +68,7 @@ def lll(basis, c=1.34): m = vecs.shape[0] u = np.identity(m) def ll_reduce(i): - for j in reversed(list(range(i))): + for j in reversed(range(i)): vecs[i] -= np.round(u[i, j]) * vecs[j] u[i] -= np.round(u[i, j]) * u[j] diff --git a/kwant/linalg/mumps.py b/kwant/linalg/mumps.py index 956454e0..cd28860a 100644 --- a/kwant/linalg/mumps.py +++ b/kwant/linalg/mumps.py @@ -219,7 +219,7 @@ class MUMPSContext(object): if a.ndim != 2 or a.shape[0] != a.shape[1]: raise ValueError("Input matrix must be square!") - if not ordering in list(orderings.keys()): + if not ordering in orderings.keys(): raise ValueError("Unknown ordering '"+ordering+"'!") dtype, row, col, data = _make_assembled_from_coo(a, overwrite_a) @@ -470,7 +470,7 @@ def schur_complement(a, indices, ordering='auto', ooc=False, pivot_tol=0.01, if indices.ndim != 1: raise ValueError("Schur indices must be specified in a 1d array!") - if not ordering in list(orderings.keys()): + if not ordering in orderings.keys(): raise ValueError("Unknown ordering '"+ordering+"'!") dtype, row, col, data = _make_assembled_from_coo(a, overwrite_a) -- GitLab