There is a maintenance of MPCDF Gitlab on Thursday, April 22st 2020, 9:00 am CEST - Expect some service interruptions during this time

Commit 5568170f authored by Martin Reinecke's avatar Martin Reinecke

Merge branch 'new_pointwise_functionality' into 'NIFTy_7'

New pointwise functionality

See merge request !591
parents 56f2c996 c9b584a3
Pipeline #92491 passed with stages
in 24 minutes and 41 seconds
......@@ -110,6 +110,15 @@ def _softplus_helper(v):
return fv, dfv
def exponentiate(v, base):
return np.power(base, v)
def _exponentiate_helper(v, base):
tmp = np.power(base, v)
return (tmp , np.log(base) * tmp)
ptw_dict = {
"sqrt": (np.sqrt, _sqrt_helper),
"sin": (np.sin, lambda v: (np.sin(v), np.cos(v))),
......@@ -131,5 +140,6 @@ ptw_dict = {
"sign": (np.sign, _sign_helper),
"power": (np.power, _power_helper),
"clip": (np.clip, _clip_helper),
"softplus": (softplus, _softplus_helper)
"softplus": (softplus, _softplus_helper),
"exponentiate": (exponentiate, _exponentiate_helper)
}
......@@ -55,7 +55,8 @@ def test_special_gradients():
@pmp('f', [
'log', 'exp', 'sqrt', 'sin', 'cos', 'tan', 'sinc', 'sinh', 'cosh', 'tanh',
'absolute', 'reciprocal', 'sigmoid', 'log10', 'log1p', 'expm1', 'softplus'
'absolute', 'reciprocal', 'sigmoid', 'log10', 'log1p', 'expm1', 'softplus',
('power', 2.), ('exponentiate', 1.1)
])
@pmp('cplxpos', [True, False])
@pmp('cplxdir', [True, False])
......@@ -77,8 +78,10 @@ def test_actual_gradients(f, cplxpos, cplxdir, holomorphic):
eps *= (1+0.78j)
var0 = ift.Linearization.make_var(fld)
var1 = ift.Linearization.make_var(fld + eps)
f0 = var0.ptw(f).val.val
f1 = var1.ptw(f).val.val
if not isinstance(f, tuple):
f = (f,)
f0 = var0.ptw(*f).val.val
f1 = var1.ptw(*f).val.val
df1 = _lin2grad(var0.ptw(*f))
df0 = (f1 - f0)/eps
df1 = _lin2grad(var0.ptw(f))
assert_allclose(df0, df1, rtol=100*np.abs(eps))
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