Commit 8d294b9b authored by Martin Reinecke's avatar Martin Reinecke

performance tweaks

parent afc5daa7
Pipeline #18435 canceled with stage
......@@ -20,7 +20,7 @@ import numpy as np
from ...field import Field
from ...spaces.power_space import PowerSpace
from ..endomorphic_operator import EndomorphicOperator
from ... import sqrt, DomainTuple
from ... import DomainTuple
from ... import nifty_utilities as utilities
......
......@@ -35,15 +35,13 @@ class Random(object):
def normal(dtype, shape, mean=0., std=1.):
if issubclass(dtype, (complex, np.complexfloating)):
x = np.empty(shape, dtype=dtype)
x.real = np.random.normal(loc=0., scale=np.sqrt(0.5), size=shape)
x.imag = np.random.normal(loc=0., scale=np.sqrt(0.5), size=shape)
x.real = np.random.normal(loc=mean.real, scale=std*np.sqrt(0.5),
size=shape)
x.imag = np.random.normal(loc=mean.imag, scale=std*np.sqrt(0.5),
size=shape)
else:
x = np.random.normal(loc=0., scale=1., size=shape)
x = np.random.normal(loc=mean, scale=std, size=shape)
x = x.astype(dtype, copy=False)
if std != 1.:
x *= std
if mean != 0.:
x += mean
return x
@staticmethod
......
......@@ -139,11 +139,19 @@ class LMSpace(Space):
def get_unique_k_lengths(self):
return np.arange(self.lmax+1, dtype=np.float64)
@staticmethod
def _kernel(x, sigma):
res = x+1.
res *= x
res *= -0.5*sigma*sigma
np.exp(res, out=res)
return res
def get_fft_smoothing_kernel_function(self, sigma):
# cf. "All-sky convolution for polarimetry experiments"
# by Challinor et al.
# http://arxiv.org/abs/astro-ph/0008228
return lambda x: np.exp(-0.5 * x * (x + 1) * sigma*sigma)
return lambda x: self._kernel(x, sigma)
@property
def lmax(self):
......
......@@ -164,10 +164,17 @@ class RGSpace(Space):
# rightmost point correctly.
return tmp[np.diff(np.r_[tmp, 2*tmp[-1]]) > tol]
@staticmethod
def _kernel(x, sigma):
tmp = x*x
tmp *= -2.*np.pi*np.pi*sigma*sigma
np.exp(tmp, out=tmp)
return tmp
def get_fft_smoothing_kernel_function(self, sigma):
if (not self.harmonic):
raise NotImplementedError
return lambda x: np.exp(-2. * np.pi*np.pi * x*x * sigma*sigma)
return lambda x: self._kernel(x, sigma)
def get_default_codomain(self):
distances = 1. / (np.array(self.shape)*np.array(self.distances))
......
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