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

cosmetics

parent 65532b56
Pipeline #21546 passed with stage
in 4 minutes and 16 seconds
...@@ -59,7 +59,7 @@ if __name__ == "__main__": ...@@ -59,7 +59,7 @@ if __name__ == "__main__":
S = ift.create_power_operator(h_space, power_spectrum=p_spec) S = ift.create_power_operator(h_space, power_spectrum=p_spec)
# Draw a sample sh from the prior distribution in harmonic space # Draw a sample sh from the prior distribution in harmonic space
sp = ift.Field(p_space, val=p_spec(p_space.k_lengths)) sp = ift.PS_field(p_space, p_spec)
sh = ift.power_synthesize(sp, real_signal=True) sh = ift.power_synthesize(sp, real_signal=True)
# Choose the measurement instrument # Choose the measurement instrument
......
...@@ -24,7 +24,7 @@ if __name__ == "__main__": ...@@ -24,7 +24,7 @@ if __name__ == "__main__":
# Creating the mock signal |\label{code:wf_mock_signal}| # Creating the mock signal |\label{code:wf_mock_signal}|
S = ift.create_power_operator(harmonic_space, power_spectrum=power_spectrum) S = ift.create_power_operator(harmonic_space, power_spectrum=power_spectrum)
mock_power = ift.Field(power_space, val=power_spectrum(power_space.k_lengths)) mock_power = ift.PS_field(power_space, power_spectrum)
mock_signal = fft(ift.power_synthesize(mock_power, real_signal=True)) mock_signal = fft(ift.power_synthesize(mock_power, real_signal=True))
# Setting up an exemplary response # Setting up an exemplary response
......
...@@ -23,7 +23,7 @@ if __name__ == "__main__": ...@@ -23,7 +23,7 @@ if __name__ == "__main__":
# Creating the mock signal |\label{code:wf_mock_signal}| # Creating the mock signal |\label{code:wf_mock_signal}|
S = ift.create_power_operator(harmonic_space, power_spectrum=power_spectrum) S = ift.create_power_operator(harmonic_space, power_spectrum=power_spectrum)
mock_power = ift.Field(power_space, val=power_spectrum(power_space.k_lengths)) mock_power = ift.PS_field(power_space, power_spectrum)
mock_signal = fft(ift.power_synthesize(mock_power, real_signal=True)) mock_signal = fft(ift.power_synthesize(mock_power, real_signal=True))
# Setting up an exemplary response # Setting up an exemplary response
......
...@@ -4,6 +4,7 @@ import numpy as np ...@@ -4,6 +4,7 @@ import numpy as np
np.random.seed(42) np.random.seed(42)
class DiagonalProber(ift.DiagonalProberMixin, ift.Prober): class DiagonalProber(ift.DiagonalProberMixin, ift.Prober):
pass pass
......
...@@ -23,7 +23,7 @@ def _shareRange(nwork, nshares, myshare): ...@@ -23,7 +23,7 @@ def _shareRange(nwork, nshares, myshare):
nbase = nwork//nshares nbase = nwork//nshares
additional = nwork % nshares additional = nwork % nshares
lo = myshare*nbase + min(myshare, additional) lo = myshare*nbase + min(myshare, additional)
hi = lo + nbase + int(myshare<additional) hi = lo + nbase + int(myshare < additional)
return lo, hi return lo, hi
...@@ -408,15 +408,15 @@ def redistribute(arr, dist=None, nodist=None): ...@@ -408,15 +408,15 @@ def redistribute(arr, dist=None, nodist=None):
ofs = 0 ofs = 0
for i in range(ntask): for i in range(ntask):
lo, hi = _shareRange(arr.shape[dist], ntask, i) lo, hi = _shareRange(arr.shape[dist], ntask, i)
sslice[dist] = slice(lo,hi) sslice[dist] = slice(lo, hi)
ssz[i] = ssz0*(hi-lo) ssz[i] = ssz0*(hi-lo)
sbuf[ofs:ofs+ssz[i]] = arr._data[sslice].flat sbuf[ofs:ofs+ssz[i]] = arr._data[sslice].flat
ofs += ssz[i] ofs += ssz[i]
rsz[i] = rsz0*_shareSize(arr.shape[arr._distaxis], ntask, i) rsz[i] = rsz0*_shareSize(arr.shape[arr._distaxis], ntask, i)
ssz *= arr._data.itemsize ssz *= arr._data.itemsize
rsz *= arr._data.itemsize rsz *= arr._data.itemsize
sdisp = np.append (0, np.cumsum(ssz[:-1])) sdisp = np.append(0, np.cumsum(ssz[:-1]))
rdisp = np.append (0, np.cumsum(rsz[:-1])) rdisp = np.append(0, np.cumsum(rsz[:-1]))
s_msg = [sbuf, (ssz, sdisp), MPI.BYTE] s_msg = [sbuf, (ssz, sdisp), MPI.BYTE]
r_msg = [rbuf, (rsz, rdisp), MPI.BYTE] r_msg = [rbuf, (rsz, rdisp), MPI.BYTE]
_comm.Alltoallv(s_msg, r_msg) _comm.Alltoallv(s_msg, r_msg)
...@@ -430,7 +430,7 @@ def redistribute(arr, dist=None, nodist=None): ...@@ -430,7 +430,7 @@ def redistribute(arr, dist=None, nodist=None):
ofs = 0 ofs = 0
for i in range(ntask): for i in range(ntask):
lo, hi = _shareRange(arr.shape[arr._distaxis], ntask, i) lo, hi = _shareRange(arr.shape[arr._distaxis], ntask, i)
rslice[arr._distaxis] = slice(lo,hi) rslice[arr._distaxis] = slice(lo, hi)
sz = rsz[i]//arr._data.itemsize sz = rsz[i]//arr._data.itemsize
arrnew._data[rslice].flat = rbuf[ofs:ofs+sz] arrnew._data[rslice].flat = rbuf[ofs:ofs+sz]
ofs += sz ofs += sz
......
...@@ -29,7 +29,8 @@ from . import Space,\ ...@@ -29,7 +29,8 @@ from . import Space,\
from . import nifty_utilities as utilities from . import nifty_utilities as utilities
from . import dobj from . import dobj
__all__ = ['power_analyze', __all__ = ['PS_field',
'power_analyze',
'power_synthesize', 'power_synthesize',
'power_synthesize_special', 'power_synthesize_special',
'create_power_field', 'create_power_field',
...@@ -38,6 +39,12 @@ __all__ = ['power_analyze', ...@@ -38,6 +39,12 @@ __all__ = ['power_analyze',
'create_composed_fft_operator'] 'create_composed_fft_operator']
def PS_field(pspace, func, dtype=None):
if not isinstance(pspace, PowerSpace):
raise TypeError
data = dobj.from_global_data(func(pspace.k_lengths))
return Field(pspace, val=data, dtype=dtype)
def _single_power_analyze(field, idx, binbounds): def _single_power_analyze(field, idx, binbounds):
from .operators.power_projection_operator import PowerProjectionOperator from .operators.power_projection_operator import PowerProjectionOperator
power_domain = PowerSpace(field.domain[idx], binbounds) power_domain = PowerSpace(field.domain[idx], binbounds)
...@@ -223,9 +230,7 @@ def create_power_field(domain, power_spectrum, dtype=None): ...@@ -223,9 +230,7 @@ def create_power_field(domain, power_spectrum, dtype=None):
fp = Field(power_domain, val=power_spectrum.val, dtype=dtype) fp = Field(power_domain, val=power_spectrum.val, dtype=dtype)
else: else:
power_domain = PowerSpace(domain) power_domain = PowerSpace(domain)
fp = Field(power_domain, fp = PS_field(power_domain, power_spectrum, dtype)
val=dobj.from_global_data(power_spectrum(power_domain.k_lengths)),
dtype=dtype)
P = PowerProjectionOperator(domain, power_domain) P = PowerProjectionOperator(domain, power_domain)
f = P.adjoint_times(fp) f = P.adjoint_times(fp)
......
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