Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Copying arrays in update field #132

Open
Lun4m opened this issue Nov 17, 2021 · 0 comments
Open

Copying arrays in update field #132

Lun4m opened this issue Nov 17, 2021 · 0 comments
Labels
cleanup ...on aisle seven optimization Make code go brrrr refactor Code rewrite

Comments

@Lun4m
Copy link
Member

Lun4m commented Nov 17, 2021

HyMD/hymd/field.py

Lines 39 to 63 in d3aff97

for t in range(config.n_types):
hamiltonian.v_ext[t](phi).r2c(out=v_ext_fourier[0])
v_ext_fourier[0].apply(hamiltonian.H, out=Ellipsis)
np.copyto(
v_ext_fourier[1].value, v_ext_fourier[0].value, casting="no", where=True
)
np.copyto(
v_ext_fourier[2].value, v_ext_fourier[0].value, casting="no", where=True
)
if compute_potential:
np.copyto(
v_ext_fourier[3].value, v_ext_fourier[0].value, casting="no", where=True
)
# Differentiate the external potential in fourier space
for d in range(3):
def force_transfer_function(k, v, d=d):
return -k[d] * 1j * v
v_ext_fourier[d].apply(force_transfer_function, out=Ellipsis)
v_ext_fourier[d].c2r(out=force_mesh[t][d])
if compute_potential:
v_ext_fourier[3].c2r(out=v_ext[t])

Can this snippet above be simplified with the following? Why do we need to copy arrays?

for t in range(config.n_types):
    hamiltonian.v_ext[t](phi).r2c(out=v_ext_fourier[t])
    v_ext_fourier[t].apply(hamiltonian.H, out=Ellipsis) 

    for d in range(3): 
        def force_transfer_function(k, v, d=d): 
            return -k[d] * 1j * v

        force_mesh_fourier = v_ext_fourier[t].apply(force_transfer_function) 
        force_mesh_fourier.c2r(out=force_mesh[t][d])

    if compute_potential: 
        v_ext_fourier.c2r(out=v_ext[t]) 

where v_ext_fourier is simply

v_ext_fourier = [pm.create("complex", value=0.0) for _ in range(config.n_types)]
@mortele mortele added cleanup ...on aisle seven optimization Make code go brrrr refactor Code rewrite labels Jan 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cleanup ...on aisle seven optimization Make code go brrrr refactor Code rewrite
Projects
None yet
Development

No branches or pull requests

2 participants