Commit 8b267e78 authored by Martin Reinecke's avatar Martin Reinecke
Browse files

Merge branch 'operator_abs' into 'NIFTy_7'

Operator abs

See merge request !568
parents 6c0e4e83 6dc1d9a4
Pipeline #88132 passed with stages
in 33 minutes and 54 seconds
......@@ -140,11 +140,11 @@
h_space = s_space.get_default_codomain()
HT = ift.HarmonicTransformOperator(h_space, target=s_space)
# Operators
Sh = ift.create_power_operator(h_space, power_spectrum=pow_spec)
R = HT #*ift.create_harmonic_smoothing_operator((h_space,), 0, 0.02)
R = HT # @ ift.create_harmonic_smoothing_operator((h_space,), 0, 0.02)
# Fields and data
sh = Sh.draw_sample_with_dtype(dtype=np.float64)
noiseless_data=R(sh)
noise_amplitude = np.sqrt(0.2)
......
......@@ -218,6 +218,9 @@ class Operator(metaclass=NiftyMeta):
return NotImplemented
return _OpSum(self, -x)
def __abs__(self):
return self.ptw("abs")
def __pow__(self, power):
if not (np.isscalar(power) or power.jac is None):
return NotImplemented
......
......@@ -57,7 +57,7 @@ def _reciprocal_helper(v):
def _abs_helper(v):
if np.issubdtype(v.dtype, np.complexfloating):
raise TypeError("Argument must not be complex")
raise TypeError("Argument must not be complex because abs(z) is not holomorphic")
return (np.abs(v), np.where(v == 0, np.nan, np.sign(v)))
......
......@@ -110,6 +110,13 @@ def testAdder(space, seed, neg):
ift.extra.check_operator(op, f, ntries=ntries)
def testAbs(space, seed):
with ift.random.Context(seed):
f = ift.from_random(space, 'normal')
op = abs(ift.ScalingOperator(space, 1.))
ift.extra.check_operator(op, f, ntries=ntries)
@pmp('target', [ift.RGSpace(64, distances=.789, harmonic=True),
ift.RGSpace([10, 10], distances=.789, harmonic=True)])
@pmp('causal', [True, False])
......
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