Commit 19b88aac authored by Martin Reinecke's avatar Martin Reinecke
Browse files

Merge branch 'default_codomain_sugar' into 'NIFTy_5'

Default codomain sugar

See merge request ift/nifty-dev!115
parents cf99895f 9597e686
......@@ -102,11 +102,13 @@ class LogRGSpace(StructuredDomain):
dist = self.bindistances
for i in range(ndim):
ks = np.zeros(self.shape[i])
ks[1:] = np.minimum(self.shape[i] - 1 - np.arange(self.shape[i]-1), np.arange(self.shape[i]-1)) * dist[i]
ks[1:] = np.minimum(self.shape[i] - 1 - np.arange(self.shape[i]-1),
np.arange(self.shape[i]-1)) * dist[i]
if self.harmonic:
ks[0] = np.nan
ks[0] = -np.inf
ks[1:] += self.t_0[i]
k_array[i] += ks.reshape((1,)*i + (self.shape[i],) + (1,)*(ndim-i-1))
k_array[i] += ks.reshape((1,)*i + (self.shape[i],)
+ (1,)*(ndim-i-1))
return k_array
......@@ -38,7 +38,8 @@ __all__ = ['PS_field', 'power_analyze', 'create_power_operator',
'create_harmonic_smoothing_operator', 'from_random',
'full', 'from_global_data', 'from_local_data',
'makeDomain', 'sqrt', 'exp', 'log', 'tanh', 'positive_tanh',
'conjugate', 'get_signal_variance', 'makeOp', 'domain_union']
'conjugate', 'get_signal_variance', 'makeOp', 'domain_union',
def PS_field(pspace, func):
......@@ -267,3 +268,31 @@ for f in ["sqrt", "exp", "log", "tanh", "positive_tanh", "conjugate"]:
return getattr(np, f)(x)
return func2
setattr(_current_module, f, func(f))
def get_default_codomain(domainoid, space=None):
"""For `RGSpace`, returns the harmonic partner domain.
For `DomainTuple`, returns a copy of the object in which the domain
indexed by `space` is substituted by its harmonic partner domain.
In this case, if `space` is None, it is set to 0 if the `DomainTuple`
contains exactly one domain.
domain: `RGSpace` or `DomainTuple`
Domain for which to constuct the default harmonic partner
space: int
Optional index of the subdomain to be replaced by its default
codomain. `domain[space]` must be of class `RGSpace`.
from .domains.rg_space import RGSpace
if isinstance(domainoid, RGSpace):
return domainoid.get_default_codomain()
if not isinstance(domainoid, DomainTuple):
raise TypeError(
'Works only on RGSpaces and DomainTuples containing those')
space = utilities.infer_space(domainoid, space)
if not isinstance(domainoid[space], RGSpace):
raise TypeError("can only codomain RGSpaces")
ret = [dom for dom in domainoid]
ret[space] = domainoid[space].get_default_codomain()
return DomainTuple.make(ret)
......@@ -122,7 +122,8 @@ def parse_spaces(spaces, nspc):
def infer_space(domain, space):
if space is None:
if len(domain) != 1:
raise ValueError("need a Field with exactly one domain")
raise ValueError("'space' index must be given for objects based on"
" DomainTuples containing more than one domain")
space = 0
space = int(space)
if space < 0 or space >= len(domain):
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