From dbe1f289db5d5af4b7ada7c78d94d33b45fee8c5 Mon Sep 17 00:00:00 2001 From: Brendt Wohlberg Date: Wed, 30 Mar 2022 12:45:25 -0600 Subject: [PATCH] Bump pinned `black` version (#268) * Update black version and reformat package source and example scripts --- .github/workflows/lint.yml | 2 +- dev_requirements.txt | 2 +- examples/scripts/deconv_ppp_bm3d_pgm.py | 2 +- examples/scripts/deconv_ppp_bm4d_admm.py | 2 +- examples/scripts/denoise_tv_iso_pgm.py | 4 ++-- scico/blockarray.py | 4 ++-- scico/examples.py | 4 ++-- scico/functional/_norm.py | 2 +- scico/linop/_linop.py | 2 +- scico/linop/optics.py | 12 ++++++------ scico/loss.py | 4 ++-- scico/metric.py | 2 +- scico/optimize/pgm.py | 2 +- scico/test/linop/test_abel.py | 2 +- scico/test/linop/test_optics.py | 4 ++-- scico/test/linop/test_radon_svmbir.py | 2 +- scico/test/optimize/test_admm.py | 2 +- scico/test/test_metric.py | 2 +- scico/test/test_operator.py | 4 ++-- scico/test/test_ray_tune.py | 2 +- scico/test/test_solver.py | 6 +++--- 21 files changed, 34 insertions(+), 34 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index ddfce4213..9867a8daa 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -28,7 +28,7 @@ jobs: - name: Black Code Formatter uses: psf/black@stable with: - version: "21.6b0" + version: "22.3" - name: isort Import Sorter uses: isort/isort-action@v0.1.0 diff --git a/dev_requirements.txt b/dev_requirements.txt index d25adf170..45b405107 100644 --- a/dev_requirements.txt +++ b/dev_requirements.txt @@ -2,6 +2,6 @@ pylint pytest pytest-runner pre-commit -black>=21.6b0,<22 +black>=22.3,<23 isort autoflake diff --git a/examples/scripts/deconv_ppp_bm3d_pgm.py b/examples/scripts/deconv_ppp_bm3d_pgm.py index 7367dd355..e080b3d75 100644 --- a/examples/scripts/deconv_ppp_bm3d_pgm.py +++ b/examples/scripts/deconv_ppp_bm3d_pgm.py @@ -43,7 +43,7 @@ n = 5 # convolution kernel size σ = 20.0 / 255 # noise level -psf = snp.ones((n, n)) / n ** 2 +psf = snp.ones((n, n)) / n**2 A = linop.Convolve(h=psf, input_shape=x_gt.shape) Ax = A(x_gt) # blurred image diff --git a/examples/scripts/deconv_ppp_bm4d_admm.py b/examples/scripts/deconv_ppp_bm4d_admm.py index 8b188507a..9bb191574 100644 --- a/examples/scripts/deconv_ppp_bm4d_admm.py +++ b/examples/scripts/deconv_ppp_bm4d_admm.py @@ -48,7 +48,7 @@ n = 5 # convolution kernel size σ = 20.0 / 255 # noise level -psf = snp.ones((n, n, n)) / (n ** 3) +psf = snp.ones((n, n, n)) / (n**3) A = linop.Convolve(h=psf, input_shape=x_gt.shape) Ax = A(x_gt) # blurred image diff --git a/examples/scripts/denoise_tv_iso_pgm.py b/examples/scripts/denoise_tv_iso_pgm.py index 86d349ea6..dc0bb39e2 100644 --- a/examples/scripts/denoise_tv_iso_pgm.py +++ b/examples/scripts/denoise_tv_iso_pgm.py @@ -140,7 +140,7 @@ def prox(self, v: JaxArray, lam: float, **kwargs) -> JaxArray: solver_iso = AcceleratedPGM( f=f_iso, g=g_iso, - L0=16.0 * f_iso.lmbda ** 2, + L0=16.0 * f_iso.lmbda**2, x0=x0, maxiter=100, itstat_options={"display": True, "period": 10}, @@ -188,7 +188,7 @@ def prox(self, v: JaxArray, lam: float, **kwargs) -> JaxArray: solver = AcceleratedPGM( f=f, g=g, - L0=16.0 * f.lmbda ** 2, + L0=16.0 * f.lmbda**2, x0=x0, maxiter=100, itstat_options={"display": True, "period": 10}, diff --git a/scico/blockarray.py b/scico/blockarray.py index 4155fbcfd..601d5e4a7 100644 --- a/scico/blockarray.py +++ b/scico/blockarray.py @@ -922,11 +922,11 @@ def __rfloordiv__(a, b): @_block_array_binary_op_wrapper def __pow__(a, b): - return a ** b + return a**b @_block_array_binary_op_wrapper def __rpow__(a, b): - return b ** a + return b**a @_block_array_binary_op_wrapper def __gt__(a, b): diff --git a/scico/examples.py b/scico/examples.py index a65fcea7e..ec68ef9d6 100644 --- a/scico/examples.py +++ b/scico/examples.py @@ -333,9 +333,9 @@ def create_3D_foam_phantom( im = snp.zeros(im_shape) + c_lo for c, r in zip(centers, radii): dist = snp.sum((x - c) ** 2, axis=-1) - if snp.mean(im[dist < r ** 2] - c_lo) < 0.01 * c_hi: + if snp.mean(im[dist < r**2] - c_lo) < 0.01 * c_hi: # In numpy: im[dist < r**2] = c_hi - im = im.at[dist < r ** 2].set(c_hi) + im = im.at[dist < r**2].set(c_hi) return im diff --git a/scico/functional/_norm.py b/scico/functional/_norm.py index f78c5e932..0a39e34e6 100644 --- a/scico/functional/_norm.py +++ b/scico/functional/_norm.py @@ -286,7 +286,7 @@ def __init__(self, delta: float = 1.0): delta: Huber function parameter :math:`\delta`. """ self.delta = delta - self._call_lt_branch = lambda xl2: 0.5 * xl2 ** 2 + self._call_lt_branch = lambda xl2: 0.5 * xl2**2 self._call_gt_branch = lambda xl2: self.delta * xl2 - 0.5 super().__init__() diff --git a/scico/linop/_linop.py b/scico/linop/_linop.py index 031302910..dc03b549c 100644 --- a/scico/linop/_linop.py +++ b/scico/linop/_linop.py @@ -337,7 +337,7 @@ def __init__( __class__ = OpClass # needed for super() to work OpClass.__doc__ = f"Linear operator version of :func:`{f_name}`." - OpClass.__init__.__doc__ = fr""" + OpClass.__init__.__doc__ = rf""" Args: input_shape: Shape of input array. diff --git a/scico/linop/optics.py b/scico/linop/optics.py index 88a0cb607..3e14794ce 100644 --- a/scico/linop/optics.py +++ b/scico/linop/optics.py @@ -235,7 +235,7 @@ def __init__( ) self.phase = jax.device_put( - np.exp(1j * z * sqrt(self.k0 ** 2 - self.kp ** 2)).astype(np.complex64) + np.exp(1j * z * sqrt(self.k0**2 - self.kp**2)).astype(np.complex64) ) self.D = Diagonal(self.phase) self._set_adjoint() @@ -259,7 +259,7 @@ def adequate_sampling(self): """ tmp = [] for d, N in zip(self.dx, self.padded_shape): - tmp.append(d ** 2 > np.pi / (self.k0 * N) * np.sqrt(d ** 2 * N ** 2 + 4 * self.z ** 2)) + tmp.append(d**2 > np.pi / (self.k0 * N) * np.sqrt(d**2 * N**2 + 4 * self.z**2)) return np.all(tmp) def pinv(self, y): @@ -317,7 +317,7 @@ def __init__( ) self.phase = jax.device_put( - np.exp(1j * z * (self.k0 - self.kp ** 2 / (2 * self.k0))).astype(np.complex64) + np.exp(1j * z * (self.k0 - self.kp**2 / (2 * self.k0))).astype(np.complex64) ) self.D = Diagonal(self.phase) @@ -342,7 +342,7 @@ def adequate_sampling(self): """ tmp = [] for d, N in zip(self.dx, self.padded_shape): - tmp.append(d ** 2 > 2 * np.pi * self.z / (self.k0 * N)) + tmp.append(d**2 > 2 * np.pi * self.z / (self.k0 * N)) return np.all(tmp) @@ -464,7 +464,7 @@ def __init__( elif ndim == 2: self.r2 = np.sqrt(x_D[0][:, None] ** 2 + x_D[1][None, :] ** 2) - phase = -1j * snp.exp(1j * k0 * z) * snp.exp(1j * 0.5 * k0 / z * self.r2 ** 2) + phase = -1j * snp.exp(1j * k0 * z) * snp.exp(1j * 0.5 * k0 / z * self.r2**2) phase *= k0 / (2 * np.pi) * np.abs(1 / z) phase *= np.prod(dx) # from approximating continouous FT with DFT phase = phase.astype(np.complex64) @@ -515,5 +515,5 @@ def adequate_sampling(self): """ tmp = [] for d, N in zip(self.dx, self.input_shape): - tmp.append(d ** 2 > 2 * np.pi * self.z / (self.k0 * N)) + tmp.append(d**2 > 2 * np.pi * self.z / (self.k0 * N)) return np.all(tmp) diff --git a/scico/loss.py b/scico/loss.py index 946b2bcd8..def566c13 100644 --- a/scico/loss.py +++ b/scico/loss.py @@ -403,12 +403,12 @@ def _dep_cubic_root(p, q): (see Sec. 3.C of :cite:`soulez-2016-proximity`). """ q2 = q / 2 - Δ = q2 ** 2 + (p / 3) ** 3 + Δ = q2**2 + (p / 3) ** 3 Δrt = snp.sqrt(Δ + 0j) u3, v3 = -q2 + Δrt, -q2 - Δrt u, v = _cbrt(u3), _cbrt(v3) r = (u + v).real - assert snp.allclose(snp.abs(r ** 3 + p * r + q), 0, atol=1e-4) + assert snp.allclose(snp.abs(r**3 + p * r + q), 0, atol=1e-4) return r diff --git a/scico/metric.py b/scico/metric.py index 1f7d40258..94bbe265b 100644 --- a/scico/metric.py +++ b/scico/metric.py @@ -89,7 +89,7 @@ def psnr( if signal_range is None: signal_range = snp.abs(snp.max(reference) - snp.min(reference)) with np.errstate(divide="ignore"): - rt = signal_range ** 2 / mse(reference, comparison) + rt = signal_range**2 / mse(reference, comparison) return 10.0 * snp.log10(rt) diff --git a/scico/optimize/pgm.py b/scico/optimize/pgm.py index fc7049cac..2fe8fcc4d 100644 --- a/scico/optimize/pgm.py +++ b/scico/optimize/pgm.py @@ -619,5 +619,5 @@ def step(self): self.fixed_point_residual = snp.linalg.norm(self.x - self.v) t_old = self.t - self.t = 0.5 * (1 + snp.sqrt(1 + 4 * t_old ** 2)) + self.t = 0.5 * (1 + snp.sqrt(1 + 4 * t_old**2)) self.v = self.x + ((t_old - 1) / self.t) * (self.x - x_old) diff --git a/scico/test/linop/test_abel.py b/scico/test/linop/test_abel.py index 7a2a57d45..8c63019f7 100644 --- a/scico/test/linop/test_abel.py +++ b/scico/test/linop/test_abel.py @@ -15,7 +15,7 @@ def make_im(Nx, Ny): x, y = snp.meshgrid(snp.linspace(-1, 1, Nx), snp.linspace(-1, 1, Ny)) - im = snp.where(x ** 2 + y ** 2 < 0.3, 1.0, 0.0) + im = snp.where(x**2 + y**2 < 0.3, 1.0, 0.0) return im diff --git a/scico/test/linop/test_optics.py b/scico/test/linop/test_optics.py index 020c61b8a..9b4598371 100644 --- a/scico/test/linop/test_optics.py +++ b/scico/test/linop/test_optics.py @@ -76,7 +76,7 @@ def test_fresnel_sampling(ndim): N = 128 dx = 1 k0 = 1 - A = FresnelPropagator(input_shape=(N,) * ndim, dx=dx, k0=k0, z=N ** 2) + A = FresnelPropagator(input_shape=(N,) * ndim, dx=dx, k0=k0, z=N**2) assert not A.adequate_sampling() A = FresnelPropagator(input_shape=(N,) * ndim, dx=dx, k0=k0, z=1) assert A.adequate_sampling() @@ -87,7 +87,7 @@ def test_fraunhofer_sampling(ndim): N = 128 dx = 1 k0 = 1 - A = FraunhoferPropagator(input_shape=(N,) * ndim, dx=dx, k0=k0, z=N ** 2) + A = FraunhoferPropagator(input_shape=(N,) * ndim, dx=dx, k0=k0, z=N**2) assert not A.adequate_sampling() A = FraunhoferPropagator(input_shape=(N,) * ndim, dx=dx, k0=k0, z=1) assert A.adequate_sampling() diff --git a/scico/test/linop/test_radon_svmbir.py b/scico/test/linop/test_radon_svmbir.py index 53bcc8670..b81185ef5 100644 --- a/scico/test/linop/test_radon_svmbir.py +++ b/scico/test/linop/test_radon_svmbir.py @@ -33,7 +33,7 @@ def make_im(Nx, Ny, is_3d=True): x, y = snp.meshgrid(snp.linspace(-1, 1, Nx), snp.linspace(-1, 1, Ny)) - im = snp.where((x - 0.25) ** 2 / 3 + y ** 2 < 0.1, 1.0, 0.0) + im = snp.where((x - 0.25) ** 2 / 3 + y**2 < 0.1, 1.0, 0.0) if is_3d: im = im[snp.newaxis, :, :] im = im.astype(snp.float32) diff --git a/scico/test/optimize/test_admm.py b/scico/test/optimize/test_admm.py index a9a1c7529..e18aa169e 100644 --- a/scico/test/optimize/test_admm.py +++ b/scico/test/optimize/test_admm.py @@ -288,7 +288,7 @@ def setup_method(self, method): Nx = 8 x = np.pad(np.ones((Nx, Nx), dtype=np.float32), Nx) Npsf = 3 - psf = snp.ones((Npsf, Npsf), dtype=np.float32) / (Npsf ** 2) + psf = snp.ones((Npsf, Npsf), dtype=np.float32) / (Npsf**2) self.A = linop.CircularConvolve( h=psf, input_shape=x.shape, diff --git a/scico/test/test_metric.py b/scico/test/test_metric.py index 80973b69d..f041bf5d3 100644 --- a/scico/test/test_metric.py +++ b/scico/test/test_metric.py @@ -17,7 +17,7 @@ def test_mae_mse(self): e1 = metric.mae(x, y) e2 = metric.mse(x, y) assert np.abs(e1 - xe / N) < 1e-12 - assert np.abs(e2 - (xe ** 2) / N) < 1e-12 + assert np.abs(e2 - (xe**2) / N) < 1e-12 def test_snr_nrm(self): N = 16 diff --git a/scico/test/test_operator.py b/scico/test/test_operator.py index ae17e29d6..87ae3049b 100644 --- a/scico/test/test_operator.py +++ b/scico/test/test_operator.py @@ -24,12 +24,12 @@ def _eval(self, x): class SquareOperator(Operator): def _eval(self, x): - return x ** 2 + return x**2 class SumSquareOperator(Operator): def _eval(self, x): - return snp.sum(x ** 2) + return snp.sum(x**2) class OperatorTestObj: diff --git a/scico/test/test_ray_tune.py b/scico/test/test_ray_tune.py index 9bfdf4969..198d1db4e 100644 --- a/scico/test/test_ray_tune.py +++ b/scico/test/test_ray_tune.py @@ -16,7 +16,7 @@ def eval_params(config, reporter): x, y = config["x"], config["y"] - cost = x ** 2 + (y - 0.5) ** 2 + cost = x**2 + (y - 0.5) ** 2 reporter(cost=cost) diff --git a/scico/test/test_solver.py b/scico/test/test_solver.py index 5cedb04fe..b7173f91d 100644 --- a/scico/test/test_solver.py +++ b/scico/test/test_solver.py @@ -207,7 +207,7 @@ def test_split_join_blockarray(): def test_bisect(): - f = lambda x: x ** 3 + f = lambda x: x**3 x, info = solver.bisect(f, -snp.ones((5, 1)), snp.ones((5, 1)), full_output=True) assert snp.sum(snp.abs(x)) == 0.0 assert info["iter"] == 0 @@ -215,14 +215,14 @@ def test_bisect(): assert snp.max(snp.abs(x)) <= 1e-5 assert snp.max(snp.abs(f(x))) <= 1e-5 c, key = random.randn((5, 1), dtype=np.float32) - f = lambda x, c: x ** 3 - c ** 3 + f = lambda x, c: x**3 - c**3 x = solver.bisect(f, -snp.abs(c) - 1, snp.abs(c) + 1, args=(c,), xtol=1e-5, ftol=1e-5) assert snp.max(snp.abs(x - c)) <= 1e-5 assert snp.max(snp.abs(f(x, c))) <= 1e-5 def test_golden(): - f = lambda x: x ** 2 + f = lambda x: x**2 x, info = solver.golden(f, -snp.ones((5, 1)), snp.ones((5, 1)), full_output=True) assert snp.max(snp.abs(x)) <= 1e-7 x = solver.golden(f, -2.0 * snp.ones((5, 3)), snp.ones((5, 3)), xtol=1e-5)