Commit 7fffbfc5 authored by Martin Reinecke's avatar Martin Reinecke
Browse files

more

parent 7929bc67
......@@ -2,5 +2,7 @@
git clone https://gitlab.mpcdf.mpg.de/ift/pyHealpix.git
(cd pyHealpix && autoreconf -i && ./configure --enable-openmp && make -j4 install)
rm -rf pyHealpix
git clone https://gitlab.mpcdf.mpg.de/ift/pyHealpix.git
(cd pyHealpix && autoreconf -i && PYTHON=python3 PYTHON_CONFIG=python3-config ./configure --enable-openmp && make -j4 install)
rm -rf pyHealpix
......@@ -27,12 +27,6 @@ __all__ = ['nifty_configuration']
# Initialize the variables
variable_harmonic_rg_base = keepers.Variable(
'harmonic_rg_base',
['real', 'complex'],
lambda z: z in ['real', 'complex'],
genus='str')
variable_loglevel = keepers.Variable(
'loglevel',
[10],
......@@ -41,8 +35,7 @@ variable_loglevel = keepers.Variable(
nifty_configuration = keepers.get_Configuration(
name='NIFTy',
variables=[variable_harmonic_rg_base,
variable_loglevel],
variables=[variable_loglevel],
file_name='NIFTy.conf',
search_paths=[os.path.expanduser('~') + "/.config/nifty/",
os.path.expanduser('~') + "/.config/",
......
......@@ -61,12 +61,6 @@ class FFTOperator(LinearOperator):
For GLSpace, HPSpace, and LMSpace, a sensible (but not unique)
co-domain is chosen that should work satisfactorily in most situations,
but for full control, the user should explicitly specify a codomain.
domain_dtype: data type (optional)
Data type of the fields that go into "times" and come out of
"adjoint_times". Default is "numpy.complex".
target_dtype: data type (optional)
Data type of the fields that go into "adjoint_times" and come out of
"times". Default is "numpy.complex".
Attributes
----------
......@@ -104,8 +98,7 @@ class FFTOperator(LinearOperator):
# ---Overwritten properties and methods---
def __init__(self, domain, target=None,
domain_dtype=None, target_dtype=None, default_spaces=None):
def __init__(self, domain, target=None, default_spaces=None):
super(FFTOperator, self).__init__(default_spaces)
# Initialize domain and target
......@@ -133,20 +126,11 @@ class FFTOperator(LinearOperator):
self._backward_transformation = TransformationCache.create(
backward_class, self.target[0], self.domain[0])
# Store the dtype information
self.domain_dtype = \
None if domain_dtype is None else np.dtype(domain_dtype)
self.target_dtype = \
None if target_dtype is None else np.dtype(target_dtype)
def _add_attributes_to_copy(self, copy, **kwargs):
copy._domain = self._domain
copy._target = self._target
copy._forward_transformation = self._forward_transformation
copy._backward_transformation = self._backward_transformation
copy.domain_dtype = self.domain_dtype
copy.target_dtype = self.target_dtype
copy = super(FFTOperator, self)._add_attributes_to_copy(copy,
**kwargs)
return copy
......@@ -169,8 +153,7 @@ class FFTOperator(LinearOperator):
result_domain = list(x.domain)
result_domain[spaces[0]] = self.target[0]
result_dtype = \
new_val.dtype if self.target_dtype is None else self.target_dtype
result_dtype = new_val.dtype
result_field = x.copy_empty(domain=result_domain,
dtype=result_dtype)
result_field.set_val(new_val=new_val, copy=True)
......@@ -195,8 +178,7 @@ class FFTOperator(LinearOperator):
result_domain = list(x.domain)
result_domain[spaces[0]] = self.domain[0]
result_dtype = \
new_val.dtype if self.domain_dtype is None else self.domain_dtype
result_dtype = new_val.dtype
result_field = x.copy_empty(domain=result_domain,
dtype=result_dtype)
......
......@@ -20,8 +20,7 @@ from __future__ import division
import numpy as np
from .transformation import Transformation
from .rg_transforms import SerialFFT
from .... import RGSpace, nifty_configuration
from .... import RGSpace
class RGRGTransformation(Transformation):
......@@ -31,8 +30,6 @@ class RGRGTransformation(Transformation):
super(RGRGTransformation, self).__init__(domain, codomain)
self._transform = SerialFFT(self.domain, self.codomain)
self.harmonic_base = nifty_configuration['harmonic_rg_base']
# ---Mandatory properties and methods---
@property
......@@ -134,31 +131,28 @@ class RGRGTransformation(Transformation):
val = self._transform.domain.weight(val, power=1, axes=axes)
# Perform the transformation
if self.harmonic_base == 'complex':
Tval = self._transform.transform(val, axes, **kwargs)
if issubclass(val.dtype.type, np.complexfloating):
Tval_real = self._transform.transform(val.real, axes,
**kwargs)
Tval_imag = self._transform.transform(val.imag, axes,
**kwargs)
if self.codomain.harmonic:
Tval_real.real += Tval_real.imag
Tval_real.imag = \
Tval_imag.real + Tval_imag.imag
else:
Tval_real.real -= Tval_real.imag
Tval_real.imag = \
Tval_imag.real - Tval_imag.imag
Tval = Tval_real
else:
if issubclass(val.dtype.type, np.complexfloating):
Tval_real = self._transform.transform(val.real, axes,
**kwargs)
Tval_imag = self._transform.transform(val.imag, axes,
**kwargs)
if self.codomain.harmonic:
Tval_real.real += Tval_real.imag
Tval_real.imag = \
Tval_imag.real + Tval_imag.imag
else:
Tval_real.real -= Tval_real.imag
Tval_real.imag = \
Tval_imag.real - Tval_imag.imag
Tval = Tval_real
Tval = self._transform.transform(val, axes, **kwargs)
if self.codomain.harmonic:
Tval.real += Tval.imag
else:
Tval = self._transform.transform(val, axes, **kwargs)
if self.codomain.harmonic:
Tval.real += Tval.imag
else:
Tval.real -= Tval.imag
Tval = Tval.real
Tval.real -= Tval.imag
Tval = Tval.real
if not self._transform.codomain.harmonic:
# correct for inverse fft.
......
......@@ -74,8 +74,5 @@ class FFTSmoothingOperator(SmoothingOperator):
def _get_transformator(self, dtype):
if dtype not in self._transformator_cache:
self._transformator_cache[dtype] = FFTOperator(
self.domain,
domain_dtype=dtype,
target_dtype=np.complex)
self._transformator_cache[dtype] = FFTOperator(self.domain)
return self._transformator_cache[dtype]
......@@ -35,7 +35,6 @@ from functools import reduce
import numpy as np
from ..space import Space
from ...config import nifty_configuration
class RGSpace(Space):
......@@ -122,36 +121,7 @@ class RGSpace(Space):
# return fixed_points
def hermitianize_inverter(self, x, axes):
if nifty_configuration['harmonic_rg_base'] == 'real':
return x
else:
# calculate the number of dimensions the input array has
dimensions = len(x.shape)
# prepare the slicing object which will be used for mirroring
slice_primitive = [slice(None), ] * dimensions
# copy the input data
y = x.copy()
# flip in the desired directions
for k in range(len(axes)):
i = axes[k]
slice_picker = slice_primitive[:]
slice_inverter = slice_primitive[:]
if (not self.zerocenter[k]) or self.shape[k] % 2 == 0:
slice_picker[i] = slice(1, None, None)
slice_inverter[i] = slice(None, 0, -1)
else:
slice_picker[i] = slice(None)
slice_inverter[i] = slice(None, None, -1)
slice_picker = tuple(slice_picker)
slice_inverter = tuple(slice_inverter)
try:
y.set_data(to_key=slice_picker, data=y,
from_key=slice_inverter)
except(AttributeError):
y[slice_picker] = y[slice_inverter]
return y
return x
# ---Mandatory properties and methods---
......
......@@ -93,11 +93,8 @@ class Test_Functionality(unittest.TestCase):
zerocenter=True)],
[RGSpace((8,), harmonic=True,
zerocenter=False),
LMSpace(12)],
['real', 'complex']))
def test_power_synthesize_analyze(self, space1, space2, base):
nifty_configuration['harmonic_rg_base'] = base
LMSpace(12)]))
def test_power_synthesize_analyze(self, space1, space2):
np.random.seed(11)
p1 = PowerSpace(space1)
......
......@@ -156,9 +156,8 @@ class RGSpaceFunctionalityTests(unittest.TestCase):
@expand(product([(10,), (11,), (1, 1), (4, 4), (5, 7), (8, 12), (7, 16),
(4, 6, 8), (17, 5, 3)],
[True, False],
['real', 'complex']))
def test_hermitianize_inverter(self, shape, zerocenter, base):
[True, False]))
def test_hermitianize_inverter(self, shape, zerocenter):
try:
r = RGSpace(shape, harmonic=True, zerocenter=zerocenter)
except ValueError:
......@@ -166,25 +165,9 @@ class RGSpaceFunctionalityTests(unittest.TestCase):
v = np.empty(shape, dtype=np.complex128)
v[:] = np.random.random(shape) + 1j*np.random.random(shape)
nifty_configuration['harmonic_rg_base'] = base
inverted = r.hermitianize_inverter(v, axes=range(len(shape)))
if base == 'complex':
# test hermitian flipping of `inverted`
it = np.nditer(v, flags=['multi_index'])
while not it.finished:
i1 = it.multi_index
i2 = []
for i in range(len(i1)):
if r.zerocenter[i] and r.shape[i] % 2 != 0:
i2.append(v.shape[i]-i1[i]-1)
else:
i2.append(v.shape[i]-i1[i] if i1[i] > 0 else 0)
i2 = tuple(i2)
assert_almost_equal(inverted[i1], v[i2])
it.iternext()
else:
assert_array_equal(v, inverted)
assert_array_equal(v, inverted)
@expand(get_distance_array_configs())
def test_distance_array(self, shape, distances, zerocenter, expected):
......
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