Commit 102c7597 authored by Martin Reinecke's avatar Martin Reinecke
Browse files

more cleanups

parent 3e85f6ff
Pipeline #17950 passed with stage
in 3 minutes and 22 seconds
......@@ -36,70 +36,50 @@ def _math_helper(x, function):
def cos(x):
return _math_helper(x, np.cos)
def sin(x):
return _math_helper(x, np.sin)
def cosh(x):
return _math_helper(x, np.cosh)
def sinh(x):
return _math_helper(x, np.sinh)
def tan(x):
return _math_helper(x, np.tan)
def tanh(x):
return _math_helper(x, np.tanh)
def arccos(x):
return _math_helper(x, np.arccos)
def arcsin(x):
return _math_helper(x, np.arcsin)
def arccosh(x):
return _math_helper(x, np.arccosh)
def arcsinh(x):
return _math_helper(x, np.arcsinh)
def arctan(x):
return _math_helper(x, np.arctan)
def arctanh(x):
return _math_helper(x, np.arctanh)
def sqrt(x):
return _math_helper(x, np.sqrt)
def exp(x):
return _math_helper(x, np.exp)
def log(x, base=None):
result = _math_helper(x, np.log)
if base is not None:
result = result/log(base)
return result
def log(x):
return _math_helper(x, np.log)
def conjugate(x):
return _math_helper(x, np.conjugate)
def conj(x):
return _math_helper(x, np.conjugate)
......@@ -132,17 +132,16 @@ class Field(object):
return tuple(axes_list)
def _infer_dtype(self, dtype, val):
if val is None:
return np.float64 if dtype is None else dtype
if dtype is None:
if isinstance(val, Field):
return val.dtype
return np.result_type(val)
if val is None or dtype is not None:
return np.result_type(dtype, np.float64)
if isinstance(val, Field):
return val.dtype
return np.result_type(val, np.float64)
# ---Factory methods---
def from_random(cls, random_type, domain=None, dtype=None, **kwargs):
def from_random(cls, random_type, domain, dtype=None, **kwargs):
""" Draws a random field with the given parameters.
......@@ -171,10 +170,10 @@ class Field(object):
f = cls(domain=domain, dtype=dtype)
generator_function = getattr(Random, random_type)
f.val = generator_function(dtype=f.dtype, shape=f.shape, **kwargs)
return f
return Field(domain=domain,
shape=utilities.domains2shape(domain), **kwargs))
# ---Powerspectral methods---
......@@ -412,9 +411,9 @@ class Field(object):
spec = self._spec_to_rescaler(spec, power_space_index)
# apply the rescaler to the random fields
result_list[0].val *= spec.real
result_list[0] *= spec.real
if not real_power:
result_list[1].val *= spec.imag
result_list[1] *= spec.imag
if real_signal:
result_list = [Field(i.domain, self._hermitian_decomposition(
......@@ -454,7 +453,8 @@ class Field(object):
# ---Properties---
def set_val(self, new_val=None, copy=False):
# MR FIXME: unused for the moment, remove after some time
def _donotuse_set_val(self, new_val=None, copy=False):
""" Sets the field's data object.
......@@ -529,9 +529,9 @@ class Field(object):
return self._val
def val(self, new_val):
self.set_val(new_val=new_val, copy=False)
#def val(self, new_val):
# self.set_val(new_val=new_val, copy=False)
def dtype(self):
......@@ -109,6 +109,13 @@ def parse_domain(domain):
"instance of DomainObject-class.")
return domain
def domains2shape(domain):
domain = parse_domain(domain)
shape_tuple = tuple(sp.shape for sp in domain)
if len(shape_tuple) == 0:
return ()
return reduce(lambda x, y: x + y, shape_tuple)
def bincount_axis(obj, minlength=None, weights=None, axis=None):
if minlength is not None:
......@@ -66,8 +66,6 @@ class FFTSmoothingOperator(EndomorphicOperator):
reshaper = [transformed_x.shape[i] if i in coaxes else 1
for i in range(len(transformed_x.shape))]
local_transformed_x = transformed_x.val
local_transformed_x *= np.reshape(self._kernel, reshaper)
transformed_x.val = local_transformed_x
transformed_x *= np.reshape(self._kernel, reshaper)
return self._transformator.adjoint_times(transformed_x, spaces=spaces)
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