Commit 32b85405 authored by Martin Reinecke's avatar Martin Reinecke
Browse files

use Hartley transform

parent 5c0c1525
Pipeline #18166 failed with stage
in 5 minutes and 7 seconds
......@@ -38,21 +38,41 @@ class RGRGTransformation(Transformation):
import pyfftw
super(RGRGTransformation, self).__init__(domain, codomain)
self._fwd = self.codomain.harmonic
def unitary(self):
return True
def _transform_helper(self, val, axes):
from pyfftw.interfaces.numpy_fft import fftn, ifftn
def _hartley(a, axes=None):
# Check if the axes provided are valid given the shape
if axes is not None and \
not all(axis in range(len(val.shape)) for axis in axes):
raise ValueError("Provided axes does not match array shape")
return fftn(val, axes=axes) if self._fwd else ifftn(val, axes=axes)
from pyfftw.interfaces.numpy_fft import rfftn
if issubclass(a.dtype.type,np.complexfloating):
raise TypeError ("Hartley tansform works for real-valued arrays only.")
tmp = rfftn(a,axes=axes)
res = np.empty_like(a)
if axes is None:
axes = list(range(a.ndim))
lastaxis = axes[-1]
nlast = a.shape[lastaxis]
ntmplast = tmp.shape[lastaxis]
nrem = nlast - ntmplast
slice1 = [slice(None)]*a.ndim
res[slice1] = tmp.real+tmp.imag
tmp = np.roll(tmp,-1,axes)
slice1 = [slice(None)]*a.ndim
slice2 = [slice(None)]*a.ndim
for i in axes:
slice2[i] = slice(None,None,-1)
res[slice1] = tmp[slice2].real-tmp[slice2].imag
return res
def transform(self, val, axes=None):
......@@ -75,26 +95,14 @@ class RGRGTransformation(Transformation):
if self.codomain.harmonic:
fct = self.domain.weight()
fct = 1./self.codomain.weight()
fct = 1./(self.codomain.weight()*self.domain.dim)
# Perform the transformation
if issubclass(val.dtype.type, np.complexfloating):
Tval1 = self._transform_helper(val.real, axes)
Tval2 = self._transform_helper(val.imag, axes)
if self.codomain.harmonic:
Tval1.real += Tval1.imag
Tval2.real += Tval2.imag
Tval1.real -= Tval1.imag
Tval2.real -= Tval2.imag
Tval1.imag = Tval2.real
Tval = Tval1
Tval = self._hartley(val.real, axes) \
+1j*self._hartley(val.imag, axes)
Tval = self._transform_helper(val, axes)
if self.codomain.harmonic:
Tval = Tval.real + Tval.imag
Tval = Tval.real - Tval.imag
Tval = self._hartley(val, axes)
Tval *= fct
return Tval
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment