Skip to content

Commit

Permalink
Bump pinned black version (#268)
Browse files Browse the repository at this point in the history
* Update black version and reformat package source and example scripts
  • Loading branch information
bwohlberg authored Mar 30, 2022
1 parent 70be677 commit dbe1f28
Show file tree
Hide file tree
Showing 21 changed files with 34 additions and 34 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected]
2 changes: 1 addition & 1 deletion dev_requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ pylint
pytest
pytest-runner
pre-commit
black>=21.6b0,<22
black>=22.3,<23
isort
autoflake
2 changes: 1 addition & 1 deletion examples/scripts/deconv_ppp_bm3d_pgm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion examples/scripts/deconv_ppp_bm4d_admm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions examples/scripts/denoise_tv_iso_pgm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -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},
Expand Down
4 changes: 2 additions & 2 deletions scico/blockarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions scico/examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion scico/functional/_norm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__()

Expand Down
2 changes: 1 addition & 1 deletion scico/linop/_linop.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
12 changes: 6 additions & 6 deletions scico/linop/optics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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):
Expand Down Expand Up @@ -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)

Expand All @@ -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)


Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
4 changes: 2 additions & 2 deletions scico/loss.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
2 changes: 1 addition & 1 deletion scico/metric.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down
2 changes: 1 addition & 1 deletion scico/optimize/pgm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
2 changes: 1 addition & 1 deletion scico/test/linop/test_abel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions scico/test/linop/test_optics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
2 changes: 1 addition & 1 deletion scico/test/linop/test_radon_svmbir.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion scico/test/optimize/test_admm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion scico/test/test_metric.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions scico/test/test_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion scico/test/test_ray_tune.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down
6 changes: 3 additions & 3 deletions scico/test/test_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,22 +207,22 @@ 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
x = solver.bisect(f, -2.0 * snp.ones((5, 3)), snp.ones((5, 3)), xtol=1e-5, ftol=1e-5)
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)
Expand Down

0 comments on commit dbe1f28

Please sign in to comment.