slight reduction of code doubling
This commit is contained in:
parent
d364808c82
commit
8ba9bb02c7
|
@ -103,8 +103,8 @@ def divergence(size: _FloatSequence,
|
||||||
k_s = _ks(size,f.shape[:3],True)
|
k_s = _ks(size,f.shape[:3],True)
|
||||||
|
|
||||||
f_fourier = _np.fft.rfftn(f,axes=(0,1,2))
|
f_fourier = _np.fft.rfftn(f,axes=(0,1,2))
|
||||||
divergence_ = (_np.einsum('ijkl,ijkl ->ijk', k_s,f_fourier)*2.0j*_np.pi if n == 3 else # vector, 3 -> 1
|
divergence_ = (_np.einsum('ijkl,ijkl ->ijk' if n==3 else
|
||||||
_np.einsum('ijkm,ijklm->ijkl',k_s,f_fourier)*2.0j*_np.pi) # tensor, 3x3 -> 3
|
'ijkm,ijklm->ijkl', k_s,f_fourier)*2.0j*_np.pi) # vector 3 -> 1, tensor 3x3 -> 3
|
||||||
|
|
||||||
return _np.fft.irfftn(divergence_,axes=(0,1,2),s=f.shape[:3])
|
return _np.fft.irfftn(divergence_,axes=(0,1,2),s=f.shape[:3])
|
||||||
|
|
||||||
|
@ -131,8 +131,8 @@ def gradient(size: _FloatSequence,
|
||||||
k_s = _ks(size,f.shape[:3],True)
|
k_s = _ks(size,f.shape[:3],True)
|
||||||
|
|
||||||
f_fourier = _np.fft.rfftn(f,axes=(0,1,2))
|
f_fourier = _np.fft.rfftn(f,axes=(0,1,2))
|
||||||
gradient_ = (_np.einsum('ijkl,ijkm->ijkm', f_fourier,k_s)*2.0j*_np.pi if n == 1 else # scalar, 1 -> 3
|
gradient_ = (_np.einsum('ijkl,ijkm->ijkm' if n==1 else
|
||||||
_np.einsum('ijkl,ijkm->ijklm',f_fourier,k_s)*2.0j*_np.pi) # vector, 3 -> 3x3
|
'ijkl,ijkm->ijklm',f_fourier,k_s)*2.0j*_np.pi) # scalar 1 -> 3, vector 3 -> 3x3
|
||||||
|
|
||||||
return _np.fft.irfftn(gradient_,axes=(0,1,2),s=f.shape[:3])
|
return _np.fft.irfftn(gradient_,axes=(0,1,2),s=f.shape[:3])
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue