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

small efficiency tweaks

parent a2caa9d2
......@@ -90,7 +90,7 @@ The current version of Nifty3 can be obtained by cloning the repository:
It is possible to simply install NIFTy with all its dependencies via the command
pip install --user --process-dependency-links git+https://gitlab.mpcdf.mpg.de/ift/NIFTy.git@nifty2go
pip install --user --process-dependency-links --egg git+https://gitlab.mpcdf.mpg.de/ift/NIFTy.git@nifty2go
### Running the tests
......
......@@ -57,7 +57,7 @@ if __name__ == "__main__":
sm = ift.FFTSmoothingOperator(signal_space, sigma=0.03)
variance = ift.sqrt(sm(proby.diagonal.weight(-1))) #|\label{code:wf_variance_weighting}|
exit()
# Plotting #|\label{code:wf_plotting}|
ift.plotting.plot(variance,name="uncertainty.pdf",xlabel='Pixel index', ylabel='Pixel index')
ift.plotting.plot(mock_signal,name="mock_signal.pdf",xlabel='Pixel index', ylabel='Pixel index')
......
......@@ -226,7 +226,7 @@ class Field(object):
# check if the `spaces` input is valid
spaces = utilities.cast_axis_to_tuple(spaces, len(self.domain))
if spaces is None:
spaces = list(range(len(self.domain)))
spaces = range(len(self.domain))
if len(spaces) == 0:
raise ValueError("No space for analysis specified.")
......@@ -297,8 +297,8 @@ class Field(object):
@staticmethod
def _shape_up_pindex(pindex, target_shape, axes):
semiscaled_local_shape = [1] * len(target_shape)
for i in range(len(axes)):
semiscaled_local_shape[axes[i]] = pindex.shape[i]
for i, ax in enumerate(axes):
semiscaled_local_shape[ax] = pindex.shape[i]
result_obj = np.empty(target_shape, dtype=pindex.dtype)
result_obj[()] = pindex.reshape(semiscaled_local_shape)
return result_obj
......@@ -356,7 +356,7 @@ class Field(object):
# check if the `spaces` input is valid
spaces = utilities.cast_axis_to_tuple(spaces, len(self.domain))
if spaces is None:
spaces = list(range(len(self.domain)))
spaces = range(len(self.domain))
for i in spaces:
if not isinstance(self.domain[i], PowerSpace):
......@@ -536,7 +536,7 @@ class Field(object):
spaces = utilities.cast_axis_to_tuple(spaces, len(self.domain))
if spaces is None:
spaces = list(range(len(self.domain)))
spaces = range(len(self.domain))
fct = 1.
for ind in spaces:
......
......@@ -131,7 +131,7 @@ class ComposedOperator(LinearOperator):
def _times_helper(self, x, spaces, func):
space_index = 0
if spaces is None:
spaces = list(range(len(self.domain)))
spaces = range(len(self.domain))
for op in self._operator_store:
active_spaces = spaces[space_index:space_index+len(op.domain)]
space_index += len(op.domain)
......@@ -142,7 +142,7 @@ class ComposedOperator(LinearOperator):
def _inverse_times_helper(self, x, spaces, func):
space_index = 0
if spaces is None:
spaces = list(range(len(self.target)))
spaces = range(len(self.target))
rev_spaces = spaces[::-1]
for op in reversed(self._operator_store):
active_spaces = rev_spaces[space_index:space_index+len(op.target)]
......
......@@ -208,7 +208,7 @@ class DiagonalOperator(EndomorphicOperator):
return operation(self._diagonal)(x)
if spaces is None:
active_axes = list(range(len(x.shape)))
active_axes = range(len(x.shape))
else:
active_axes = []
for space_index in spaces:
......
......@@ -49,18 +49,14 @@ class RGRGTransformation(Transformation):
nlast = res.shape[lastaxis]
ntmplast = tmp.shape[lastaxis]
nrem = nlast - ntmplast
slice1 = [slice(None)]*res.ndim
slice2 = list(slice1)
for i in axes:
slice1 = [slice(None)]*lastaxis + [slice(ntmplast, None)]
slice2 = [slice(None)]*lastaxis + [slice(nrem, 0, -1)]
for i in axes[:-1]:
slice1[i] = slice(1, None)
slice2[i] = slice(None, 0, -1)
slice1[lastaxis] = slice(ntmplast, None)
slice2[lastaxis] = slice(nrem, 0, -1)
res[slice1] = tmp[slice2].real-tmp[slice2].imag
for i in range(len(axes)-1):
ax = axes[i]
dim1 = [slice(None)]*res.ndim
dim1[ax]=slice(0,1)
for i, ax in enumerate(axes[:-1]):
dim1 = [slice(None)]*ax + [slice(0,1)]
axes2 = axes[:i] + axes[i+1:]
RGRGTransformation._fill_upper_half(tmp[dim1], res[dim1], axes2)
......@@ -68,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 in range(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
......@@ -77,15 +73,14 @@ class RGRGTransformation(Transformation):
tmp = rfftn(a, axes=axes)
res = np.empty_like(a)
if axes is None:
axes = list(range(a.ndim))
axes = range(a.ndim)
lastaxis = axes[-1]
nlast = a.shape[lastaxis]
ntmplast = tmp.shape[lastaxis]
nrem = nlast - ntmplast
slice1 = [slice(None)]*a.ndim
slice1[lastaxis] = slice(0, ntmplast)
slice1 = [slice(None)]*lastaxis + [slice(0, ntmplast)]
res[slice1] = tmp.real+tmp.imag
RGRGTransformation._fill_upper_half (tmp, res, axes)
RGRGTransformation._fill_upper_half(tmp, res, axes)
return res
def transform(self, val, axes=None):
......
......@@ -120,8 +120,7 @@ def create_composed_fft_operator(domain, codomain=None, all_to='other'):
if codomain is None:
codomain = [None]*len(domain)
for i in range(len(domain)):
space = domain[i]
for i, space in enumerate(domain):
cospace = codomain[i]
if not isinstance(space, Space):
continue
......
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