From 43bb0ba379643b762769be0f18c8ea42e81f704f Mon Sep 17 00:00:00 2001 From: Jan Petykiewicz Date: Mon, 29 Jul 2024 00:31:16 -0700 Subject: [PATCH] use generators where applicable --- meanas/fdfd/bloch.py | 8 ++++---- meanas/fdfd/operators.py | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/meanas/fdfd/bloch.py b/meanas/fdfd/bloch.py index 5ea5e7b..427e1a5 100644 --- a/meanas/fdfd/bloch.py +++ b/meanas/fdfd/bloch.py @@ -232,7 +232,7 @@ def maxwell_operator( Raveled conv(1/mu_k, ik x conv(1/eps_k, ik x h_mn)), returned and overwritten in-place of `h`. """ - hin_m, hin_n = [hi.reshape(shape) for hi in numpy.split(h, 2)] + hin_m, hin_n = (hi.reshape(shape) for hi in numpy.split(h, 2)) #{d,e,h}_xyz fields are complex 3-fields in (1/x, 1/y, 1/z) basis @@ -303,7 +303,7 @@ def hmn_2_exyz( k_mag, m, n = generate_kmn(k0, G_matrix, shape) def operator(h: NDArray[numpy.complex128]) -> cfdfield_t: - hin_m, hin_n = [hi.reshape(shape) for hi in numpy.split(h, 2)] + hin_m, hin_n = (hi.reshape(shape) for hi in numpy.split(h, 2)) d_xyz = (n * hin_m - m * hin_n) * k_mag # noqa: E128 @@ -341,7 +341,7 @@ def hmn_2_hxyz( _k_mag, m, n = generate_kmn(k0, G_matrix, shape) def operator(h: NDArray[numpy.complex128]) -> cfdfield_t: - hin_m, hin_n = [hi.reshape(shape) for hi in numpy.split(h, 2)] + hin_m, hin_n = (hi.reshape(shape) for hi in numpy.split(h, 2)) h_xyz = (m * hin_m + n * hin_n) # noqa: E128 return numpy.array([ifftn(hi) for hi in numpy.moveaxis(h_xyz, 3, 0)]) @@ -394,7 +394,7 @@ def inverse_maxwell_operator_approx( Returns: Raveled ik x conv(eps_k, ik x conv(mu_k, h_mn)) """ - hin_m, hin_n = [hi.reshape(shape) for hi in numpy.split(h, 2)] + hin_m, hin_n = (hi.reshape(shape) for hi in numpy.split(h, 2)) #{d,e,h}_xyz fields are complex 3-fields in (1/x, 1/y, 1/z) basis diff --git a/meanas/fdfd/operators.py b/meanas/fdfd/operators.py index 32e3af0..afa5fbd 100644 --- a/meanas/fdfd/operators.py +++ b/meanas/fdfd/operators.py @@ -321,11 +321,11 @@ def poynting_e_cross(e: vcfdfield_t, dxes: dx_lists_t) -> sparse.spmatrix: """ shape = [len(dx) for dx in dxes[0]] - fx, fy, fz = [shift_circ(i, shape, 1) for i in range(3)] + fx, fy, fz = (shift_circ(i, shape, 1) for i in range(3)) dxag = [dx.ravel(order='C') for dx in numpy.meshgrid(*dxes[0], indexing='ij')] dxbg = [dx.ravel(order='C') for dx in numpy.meshgrid(*dxes[1], indexing='ij')] - Ex, Ey, Ez = [ei * da for ei, da in zip(numpy.split(e, 3), dxag)] + Ex, Ey, Ez = (ei * da for ei, da in zip(numpy.split(e, 3), dxag, strict=True)) block_diags = [[ None, fx @ -Ez, fx @ Ey], [ fy @ Ez, None, fy @ -Ex], @@ -349,11 +349,11 @@ def poynting_h_cross(h: vcfdfield_t, dxes: dx_lists_t) -> sparse.spmatrix: """ shape = [len(dx) for dx in dxes[0]] - fx, fy, fz = [shift_circ(i, shape, 1) for i in range(3)] + fx, fy, fz = (shift_circ(i, shape, 1) for i in range(3)) dxag = [dx.ravel(order='C') for dx in numpy.meshgrid(*dxes[0], indexing='ij')] dxbg = [dx.ravel(order='C') for dx in numpy.meshgrid(*dxes[1], indexing='ij')] - Hx, Hy, Hz = [sparse.diags(hi * db) for hi, db in zip(numpy.split(h, 3), dxbg)] + Hx, Hy, Hz = (sparse.diags(hi * db) for hi, db in zip(numpy.split(h, 3), dxbg, strict=True)) P = (sparse.bmat( [[ None, -Hz @ fx, Hy @ fx],