Commit 1c941d46 authored by Martin Reinecke's avatar Martin Reinecke
Browse files

Merge branch 'master' into python3

parents fe826067 d11f0851
Pipeline #15169 passed with stage
in 8 minutes and 55 seconds
......@@ -470,7 +470,7 @@ class Field(Loggable, Versionable, object):
return result_obj
def power_synthesize(self, spaces=None, real_power=True, real_signal=True,
mean=None, std=None):
mean=None, std=None, distribution_strategy=None):
""" Yields a sampled field with `self`**2 as its power spectrum.
This method draws a Gaussian random field in the harmonic partner
......@@ -545,13 +545,16 @@ class Field(Loggable, Versionable, object):
else:
result_list = [None, None]
if distribution_strategy is None:
distribution_strategy = gc['default_distribution_strategy']
result_list = [self.__class__.from_random(
'normal',
mean=mean,
std=std,
domain=result_domain,
dtype=np.complex,
distribution_strategy=self.distribution_strategy)
distribution_strategy=distribution_strategy)
for x in result_list]
# from now on extract the values from the random fields for further
......
......@@ -53,24 +53,28 @@ class CriticalPowerEnergy(Energy):
default : None
"""
# ---Overwritten properties and methods---
def __init__(self, position, m, D=None, alpha=1.0, q=0.,
smoothness_prior=0., logarithmic=True, samples=3, w=None):
super(CriticalPowerEnergy, self).__init__(position=position)
self.m = m
self.D = D
self.samples = samples
self.smoothness_prior = np.float(smoothness_prior)
self.alpha = Field(self.position.domain, val=alpha)
self.q = Field(self.position.domain, val=q)
self.T = SmoothnessOperator(domain=self.position.domain[0],
strength=self.smoothness_prior,
strength=smoothness_prior,
logarithmic=logarithmic)
self.rho = self.position.domain[0].rho
self._w = w if w is not None else None
# ---Mandatory properties and methods---
def at(self, position):
return self.__class__(position, self.m, D=self.D, alpha=self.alpha,
q=self.q, smoothness_prior=self.smoothness_prior,
logarithmic=self.logarithmic,
w=self.w, samples=self.samples)
@property
......@@ -94,6 +98,16 @@ class CriticalPowerEnergy(Energy):
T=self.T)
return curvature
# ---Added properties and methods---
@property
def logarithmic(self):
return self.T.logarithmic
@property
def smoothness_prior(self):
return self.T.strength
@property
def w(self):
if self._w is None:
......
......@@ -45,9 +45,6 @@ class LineSearch(with_metaclass(abc.ABCMeta, type('NewBase', (Loggable, object),
__metaclass__ = abc.ABCMeta
def __init__(self):
self.line_energy = None
self.f_k_minus_1 = None
self.preferred_initial_step_size = None
......
......@@ -376,6 +376,10 @@ class MPIFFT(Transform):
original_shape = inp.shape
inp = inp.reshape(inp.shape[0], 1)
axes = (0, )
if original_shape[0]%2!=0:
raise AttributeError("MPI-FFTs of onedimensional arrays "
"with odd length are currently not supported due to a "
"bug in FFTW. Please use a grid with even length.")
if current_info is None:
transform_shape = list(inp.shape)
......
......@@ -72,7 +72,8 @@ class InvertibleOperatorMixin(object):
def _times(self, x, spaces, x0=None):
if x0 is None:
x0 = Field(self.target, val=0., dtype=x.dtype)
x0 = Field(self.target, val=0., dtype=x.dtype,
distribution_strategy=x.distribution_strategy)
(result, convergence) = self.__inverter(A=self.inverse_times,
b=x,
......@@ -81,7 +82,8 @@ class InvertibleOperatorMixin(object):
def _adjoint_times(self, x, spaces, x0=None):
if x0 is None:
x0 = Field(self.domain, val=0., dtype=x.dtype)
x0 = Field(self.domain, val=0., dtype=x.dtype,
distribution_strategy=x.distribution_strategy)
(result, convergence) = self.__inverter(A=self.adjoint_inverse_times,
b=x,
......@@ -90,7 +92,8 @@ class InvertibleOperatorMixin(object):
def _inverse_times(self, x, spaces, x0=None):
if x0 is None:
x0 = Field(self.domain, val=0., dtype=x.dtype)
x0 = Field(self.domain, val=0., dtype=x.dtype,
distribution_strategy=x.distribution_strategy)
(result, convergence) = self.__inverter(A=self.times,
b=x,
......@@ -99,7 +102,8 @@ class InvertibleOperatorMixin(object):
def _adjoint_inverse_times(self, x, spaces, x0=None):
if x0 is None:
x0 = Field(self.target, val=0., dtype=x.dtype)
x0 = Field(self.target, val=0., dtype=x.dtype,
distribution_strategy=x.distribution_strategy)
(result, convergence) = self.__inverter(A=self.adjoint_times,
b=x,
......
......@@ -48,7 +48,9 @@ class LaplaceOperator(EndomorphicOperator):
if not isinstance(self.domain[0], PowerSpace):
raise TypeError("The domain must contain exactly one PowerSpace.")
if logarithmic:
self._logarithmic = bool(logarithmic)
if self.logarithmic:
self.positions = self.domain[0].kindex.copy()
self.positions[1:] = np.log(self.positions[1:])
self.positions[0] = -1.
......@@ -78,6 +80,10 @@ class LaplaceOperator(EndomorphicOperator):
def self_adjoint(self):
return False
@property
def logarithmic(self):
return self._logarithmic
def _times(self, x, spaces):
spaces = utilities.cast_axis_to_tuple(spaces, len(x.domain))
if spaces is None:
......
......@@ -20,7 +20,7 @@ class SmoothnessOperator(EndomorphicOperator):
Parameters
----------
sigma: float,
strength: float,
Specifies the strength of the SmoothnessOperator
logarithmic : boolean,
Whether smoothness is calculated on a logarithmic scale or linear scale
......@@ -83,6 +83,10 @@ class SmoothnessOperator(EndomorphicOperator):
# ---Added properties and methods---
@property
def logarithmic(self):
return self._laplace.logarithmic
@property
def strength(self):
return self._strength
......@@ -40,7 +40,8 @@ class Prober(object):
"""
def __init__(self, domain=None, distribution_strategy=None, probe_count=8,
random_type='pm1', compute_variance=False):
random_type='pm1', probe_dtype=np.float,
compute_variance=False):
self._domain = utilities.parse_domain(domain)
self._distribution_strategy = \
......@@ -48,6 +49,7 @@ class Prober(object):
self._probe_count = self._parse_probe_count(probe_count)
self._random_type = self._parse_random_type(random_type)
self.compute_variance = bool(compute_variance)
self.probe_dtype = np.dtype(probe_dtype)
# ---Properties---
......@@ -107,6 +109,7 @@ class Prober(object):
""" a random-probe generator """
f = Field.from_random(random_type=self.random_type,
domain=self.domain,
dtype=self.probe_dtype,
distribution_strategy=self.distribution_strategy)
uid = np.random.randint(1e18)
return (uid, f)
......
......@@ -64,7 +64,7 @@ class FFTOperatorTests(unittest.TestCase):
assert_equal(res[zc1 * (dim1 // 2), zc2 * (dim2 // 2)], 0.)
@expand(product(["numpy", "fftw", "fftw_mpi"],
[10, 11], [False, True], [False, True],
[12, ], [False, True], [False, True],
[0.1, 1, 3.7],
[np.float64, np.complex128, np.float32, np.complex64]))
def test_fft1D(self, module, dim1, zc1, zc2, d, itp):
......@@ -87,7 +87,7 @@ class FFTOperatorTests(unittest.TestCase):
rtol=tol, atol=tol)
@expand(product(["numpy", "fftw", "fftw_mpi"],
[10, 11], [9, 12], [False, True],
[12, 15], [9, 12], [False, True],
[False, True], [False, True], [False, True], [0.1, 1, 3.7],
[0.4, 1, 2.7],
[np.float64, np.complex128, np.float32, np.complex64]))
......
......@@ -43,4 +43,7 @@ class SpaceSerializationTests(unittest.TestCase):
repo.commit()
assert_equal(space, repo.get('space'))
assert_equal(field, repo.get('field'))
os.remove('test.h5')
try:
os.remove('test.h5')
except OSError:
pass
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