Commit 2e77efe1 authored by Martin Reinecke's avatar Martin Reinecke
Browse files

more fixes

parent 9fed8b01
Pipeline #23704 failed with stage
in 4 minutes and 5 seconds
......@@ -332,10 +332,9 @@ class Field(object):
if len(spaces) == ndom:
return dobj.vdot(self.val, x.val)
raise NotImplementedError
# If we arrive here, we have to do a partial dot product.
# For the moment, do this the explicit, non-optimized way
return (self.conjugate()*x).integrate(spaces=spaces)
return (self.conjugate()*x).sum(spaces=spaces)
def norm(self):
""" Computes the L2-norm of the field values.
......
......@@ -85,10 +85,10 @@ class FFTOperator(LinearOperator):
def apply(self, x, mode):
self._check_input(x, mode)
if np.issubdtype(x.dtype, np.complexfloating):
res = (self._trafo.transform(x.real) +
1j * self._trafo.transform(x.imag))
res = (self._trafo.apply(x.real, mode) +
1j * self._trafo.apply(x.imag, mode))
else:
res = self._trafo.transform(x)
res = self._trafo.apply(x, mode)
return res
@property
......
......@@ -22,6 +22,7 @@ from .. import utilities
from .. import dobj
from ..field import Field
from ..spaces.gl_space import GLSpace
from .linear_operator import LinearOperator
class Transformation(object):
......@@ -41,14 +42,14 @@ class RGRGTransformation(Transformation):
# apply effectively a factor of 1/sqrt(N) to the field.
# BUT: the pixel volumes of the domain and codomain are different.
# Hence, in order to produce the same scalar product, power==1.
self.fct_p2h = pdom[space].scalar_dvol()
self.fct_h2p = 1./(pdom[space].scalar_dvol()*hdom[space].dim)
self.fct_noninverse = pdom[space].scalar_dvol()
self.fct_inverse = 1./(pdom[space].scalar_dvol()*hdom[space].dim)
@property
def unitary(self):
return True
def transform(self, x):
def apply(self, x, mode):
"""
RG -> RG transform method.
......@@ -125,7 +126,11 @@ class RGRGTransformation(Transformation):
ldat = ldat.real+ldat.imag
tmp = dobj.from_local_data(tmp.shape, ldat, distaxis=oldax)
Tval = Field(tdom, tmp)
fct = self.fct_p2h if p2h else self.fct_h2p
if (mode == LinearOperator.TIMES or
mode == LinearOperator.ADJOINT_TIMES):
fct = self.fct_noninverse
else:
fct = self.fct_inverse
if fct != 1:
Tval *= fct
......@@ -152,14 +157,14 @@ class SphericalTransformation(Transformation):
return False
def _slice_p2h(self, inp):
rr = self.sjob.map2alm(inp)
rr = self.sjob.alm2map_adjoint(inp)
assert len(rr) == ((self.mmax+1)*(self.mmax+2))//2 + \
(self.mmax+1)*(self.lmax-self.mmax)
res = np.empty(2*len(rr)-self.lmax-1, dtype=rr[0].real.dtype)
res[0:self.lmax+1] = rr[0:self.lmax+1].real
res[self.lmax+1::2] = np.sqrt(2)*rr[self.lmax+1:].real
res[self.lmax+2::2] = np.sqrt(2)*rr[self.lmax+1:].imag
return res
return res*(np.sqrt(4*np.pi)/inp.size)
def _slice_h2p(self, inp):
res = np.empty((len(inp)+self.lmax+1)//2, dtype=(inp[0]*1j).dtype)
......@@ -168,9 +173,10 @@ class SphericalTransformation(Transformation):
res[0:self.lmax+1] = inp[0:self.lmax+1]
res[self.lmax+1:] = np.sqrt(0.5)*(inp[self.lmax+1::2] +
1j*inp[self.lmax+2::2])
return self.sjob.alm2map(res)
res = self.sjob.alm2map(res)
return res*(np.sqrt(4*np.pi)/res.size)
def transform(self, x):
def apply(self, x, mode):
axes = x.domain.axes[self.space]
axis = axes[0]
tval = x.val
......
......@@ -22,4 +22,4 @@ def FFTSmoothingOperator(domain, sigma, space=None):
ddom = list(domain)
ddom[space] = codomain
diag = DiagonalOperator(kernel, ddom, space)
return FFT.adjoint*diag*FFT
return FFT.inverse*diag*FFT
......@@ -135,5 +135,4 @@ class Test_Functionality(unittest.TestCase):
x2 = ift.RGSpace((150,))
m = ift.Field((x1, x2), val=.5)
res = m.vdot(m, spaces=1)
assert_allclose(ift.dobj.to_global_data(res.val),
ift.dobj.to_global_data(ift.Field(x1, val=.25).val))
assert_allclose(ift.dobj.to_global_data(res.val), 37.5)
......@@ -44,7 +44,7 @@ class FFTOperatorTests(unittest.TestCase):
np.random.seed(16)
inp = ift.Field.from_random(domain=a, random_type='normal',
std=7, mean=3, dtype=itp)
out = fft.adjoint_times(fft.times(inp))
out = fft.inverse_times(fft.times(inp))
assert_allclose(ift.dobj.to_global_data(inp.val),
ift.dobj.to_global_data(out.val), rtol=tol, atol=tol)
......@@ -60,7 +60,7 @@ class FFTOperatorTests(unittest.TestCase):
inp = ift.Field.from_random(domain=a, random_type='normal',
std=7, mean=3, dtype=itp)
out = fft.adjoint_times(fft.times(inp))
out = fft.inverse_times(fft.times(inp))
assert_allclose(ift.dobj.to_global_data(inp.val),
ift.dobj.to_global_data(out.val), rtol=tol, atol=tol)
......@@ -74,7 +74,7 @@ class FFTOperatorTests(unittest.TestCase):
inp = ift.Field.from_random(domain=(a1, a2, a3), random_type='normal',
std=7, mean=3, dtype=dtype)
out = fft.adjoint_times(fft.times(inp))
out = fft.inverse_times(fft.times(inp))
assert_allclose(ift.dobj.to_global_data(inp.val),
ift.dobj.to_global_data(out.val), rtol=tol, atol=tol)
......@@ -87,7 +87,7 @@ class FFTOperatorTests(unittest.TestCase):
fft = ift.FFTOperator(domain=a, target=b)
inp = ift.Field.from_random(domain=a, random_type='normal',
std=7, mean=3, dtype=tp)
out = fft.adjoint_times(fft.times(inp))
out = fft.inverse_times(fft.times(inp))
assert_allclose(ift.dobj.to_global_data(inp.val),
ift.dobj.to_global_data(out.val), rtol=tol, atol=tol)
......@@ -99,7 +99,7 @@ class FFTOperatorTests(unittest.TestCase):
fft = ift.FFTOperator(domain=a, target=b)
inp = ift.Field.from_random(domain=a, random_type='normal',
std=1, mean=0, dtype=tp)
out = fft.adjoint_times(fft.times(inp))
out = fft.inverse_times(fft.times(inp))
assert_allclose(ift.dobj.to_global_data(inp.val),
ift.dobj.to_global_data(out.val), rtol=1e-3, atol=1e-1)
......
Markdown is supported
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