Commit fbd91b74 authored by Martin Reinecke's avatar Martin Reinecke
Browse files

cleanup

parent 8eba48d3
Pipeline #18278 failed with stage
in 6 minutes and 15 seconds
......@@ -109,6 +109,7 @@ 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)
......@@ -117,6 +118,7 @@ def domains2shape(domain):
else:
return reduce(lambda x, y: x + y, shape_tuple)
def bincount_axis(obj, minlength=None, weights=None, axis=None):
if minlength is not None:
length = max(np.amax(obj) + 1, minlength)
......@@ -153,23 +155,19 @@ def bincount_axis(obj, minlength=None, weights=None, axis=None):
data = np.ascontiguousarray(data.reshape(flat_shape))
if weights is not None:
weights = np.ascontiguousarray(
weights.reshape(flat_shape))
weights = np.ascontiguousarray(weights.reshape(flat_shape))
# compute the local bincount results
# -> prepare the local result array
result_dtype = np.int if weights is None else np.float
local_counts = np.empty(flat_shape[:-1] + (length, ),
dtype=result_dtype)
local_counts = np.empty(flat_shape[:-1] + (length, ), dtype=result_dtype)
# iterate over all entries in the surviving axes and compute the local
# bincounts
for slice_list in get_slice_list(flat_shape,
axes=(len(flat_shape)-1, )):
for slice_list in get_slice_list(flat_shape, axes=(len(flat_shape)-1,)):
current_weights = None if weights is None else weights[slice_list]
local_counts[slice_list] = np.bincount(
data[slice_list],
weights=current_weights,
minlength=length)
local_counts[slice_list] = np.bincount(data[slice_list],
weights=current_weights,
minlength=length)
# restore the original ordering
# place the bincount stuff at the location of the first `axis` entry
......
......@@ -56,7 +56,7 @@ class RGRGTransformation(Transformation):
slice2[i] = slice(None, 0, -1)
np.subtract(tmp[slice2].real, tmp[slice2].imag, out=res[slice1])
for i, ax in enumerate(axes[:-1]):
dim1 = [slice(None)]*ax + [slice(0,1)]
dim1 = [slice(None)]*ax + [slice(0, 1)]
axes2 = axes[:i] + axes[i+1:]
RGRGTransformation._fill_upper_half(tmp[dim1], res[dim1], axes2)
......@@ -64,7 +64,7 @@ class RGRGTransformation(Transformation):
def _hartley(a, axes=None):
# Check if the axes provided are valid given the shape
if axes is not None and \
not all(axis<len(a.shape) for axis in axes):
not all(axis < len(a.shape) for axis in axes):
raise ValueError("Provided axes does not match array shape")
from pyfftw.interfaces.numpy_fft import rfftn
......@@ -75,9 +75,7 @@ class RGRGTransformation(Transformation):
if axes is None:
axes = range(a.ndim)
lastaxis = axes[-1]
nlast = a.shape[lastaxis]
ntmplast = tmp.shape[lastaxis]
nrem = nlast - ntmplast
slice1 = [slice(None)]*lastaxis + [slice(0, ntmplast)]
np.add(tmp.real, tmp.imag, out=res[slice1])
RGRGTransformation._fill_upper_half(tmp, res, axes)
......@@ -109,7 +107,7 @@ class RGRGTransformation(Transformation):
# Perform the transformation
if issubclass(val.dtype.type, np.complexfloating):
Tval = self._hartley(val.real, axes) \
+1j*self._hartley(val.imag, axes)
+ 1j*self._hartley(val.imag, axes)
else:
Tval = self._hartley(val, axes)
......@@ -131,24 +129,18 @@ class SlicingTransformation(Transformation):
def buildLm(nr, lmax):
new_dtype = np.result_type(nr[0]*1j)
size = (len(nr)-lmax-1)//2+lmax+1
res = np.empty([size], dtype=new_dtype)
res = np.empty((len(nr)+lmax+1)//2, dtype=(nr[0]*1j).dtype)
res[0:lmax+1] = nr[0:lmax+1]
res[lmax+1:] = np.sqrt(0.5)*(nr[lmax+1::2] + 1j*nr[lmax+2::2])
return res
def buildIdx(nr, lmax):
new_dtype = np.result_type(nr[0].real)
size = (lmax+1)*(lmax+1)
final = np.empty(size, dtype=new_dtype)
final[0:lmax+1] = nr[0:lmax+1].real
final[lmax+1::2] = np.sqrt(2)*nr[lmax+1:].real
final[lmax+2::2] = np.sqrt(2)*nr[lmax+1:].imag
return final
res = np.empty((lmax+1)*(lmax+1), dtype=nr[0].real.dtype)
res[0:lmax+1] = nr[0:lmax+1].real
res[lmax+1::2] = np.sqrt(2)*nr[lmax+1:].real
res[lmax+2::2] = np.sqrt(2)*nr[lmax+1:].imag
return res
class HPLMTransformation(SlicingTransformation):
......
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