From 91bdb0b167b34d26420ee337defab5acaf2c75d3 Mon Sep 17 00:00:00 2001 From: Anton Akhmerov <anton.akhmerov@gmail.com> Date: Mon, 7 Jan 2019 16:06:00 +0100 Subject: [PATCH] move a value range check to the place before the value is used --- kwant/kpm.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/kwant/kpm.py b/kwant/kpm.py index b5b1c355..4a24a9ad 100644 --- a/kwant/kpm.py +++ b/kwant/kpm.py @@ -195,6 +195,9 @@ class SpectralDensity: # store this vector for reproducibility self._v0 = np.exp(2j * np.pi * rng.random_sample(hamiltonian.shape[0])) + if eps <= 0: + raise ValueError("'eps' must be positive") + # Hamiltonian rescaled as in Eq. (24) self.hamiltonian, (self._a, self._b) = _rescale(hamiltonian, eps=self.eps, @@ -209,8 +212,6 @@ class SpectralDensity: if num_moments <= 0 or num_moments != int(num_moments): raise ValueError("'num_moments' must be a positive integer") - if eps <= 0: - raise ValueError("'eps' must be positive") if vector_factory is None: self._vector_factory = _VectorFactory( -- GitLab