Commit e288f5be authored by Martin Reinecke's avatar Martin Reinecke

cosmetics

parent 9ebbecf5
......@@ -264,7 +264,7 @@ def empty_like(a, dtype=None):
def vdot(a, b):
tmp = np.array(np.vdot(a._data, b._data))
if a._distaxis==-1:
if a._distaxis == -1:
return tmp[()]
res = np.empty((), dtype=tmp.dtype)
_comm.Allreduce(tmp, res, MPI.SUM)
......
......@@ -93,8 +93,8 @@ def check_value_gradient_metric_consistency(op, loc, tol=1e-8, ntries=100):
dgrad2 = (lin2.gradient-lin.gradient)/dirnorm
xtol = tol * dirder.norm() / np.sqrt(dirder.size)
if ((abs(numgrad-dirder) <= xtol).all() and
(abs(dgrad-dgrad2) <= xtol).all()):
break
(abs(dgrad-dgrad2) <= xtol).all()):
break
dir = dir*0.5
dirnorm *= 0.5
loc2 = locmid
......
......@@ -621,6 +621,7 @@ class Field(object):
def positive_tanh(self):
return 0.5*(1.+self.tanh())
for op in ["__add__", "__radd__",
"__sub__", "__rsub__",
"__mul__", "__rmul__",
......
......@@ -100,7 +100,7 @@ class AmplitudeModel(Operator):
im, iv : y-intercept_mean, y-intercept_variance of power_slope
'''
def __init__(self, s_space, Npixdof, ceps_a, ceps_k, sm, sv, im, iv,
keys=['tau', 'phi']):
keys=['tau', 'phi']):
from ..operators.exp_transform import ExpTransform
from ..operators.qht_operator import QHTOperator
from ..operators.slope_operator import SlopeOperator
......@@ -119,9 +119,11 @@ class AmplitudeModel(Operator):
phi_sig = np.array([sv, iv])
self._slope = SlopeOperator(param_space, logk_space, phi_sig)
self._norm_phi_mean = Field.from_global_data(param_space, phi_mean/phi_sig)
self._norm_phi_mean = Field.from_global_data(param_space,
phi_mean/phi_sig)
self._domain = MultiDomain.make({keys[0]: dof_space, keys[1]: param_space})
self._domain = MultiDomain.make({keys[0]: dof_space,
keys[1]: param_space})
kern = lambda k: _ceps_kernel(dof_space, k, ceps_a, ceps_k)
cepstrum = create_cepstrum_amplitude_field(dof_space, kern)
......
......@@ -47,8 +47,9 @@ class Linearization(object):
return Linearization(self._val[name], FieldAdapter(dom, name))
def __neg__(self):
return Linearization(-self._val, self._jac*(-1),
None if self._metric is None else self._metric*(-1))
return Linearization(
-self._val, self._jac*(-1),
None if self._metric is None else self._metric*(-1))
def __add__(self, other):
if isinstance(other, Linearization):
......@@ -77,8 +78,9 @@ class Linearization(object):
if isinstance(other, Linearization):
d1 = makeOp(self._val)
d2 = makeOp(other._val)
return Linearization(self._val*other._val,
RelaxedSumOperator((d2*self._jac, d1*other._jac)))
return Linearization(
self._val*other._val,
RelaxedSumOperator((d2*self._jac, d1*other._jac)))
if isinstance(other, (int, float, complex)):
# if other == 0:
# return ...
......@@ -100,8 +102,8 @@ class Linearization(object):
def sum(self):
from .sugar import full
from .operators.vdot_operator import VdotOperator
return Linearization(full((),self._val.sum()),
VdotOperator(full(self._jac.target,1))*self._jac)
return Linearization(full((), self._val.sum()),
VdotOperator(full(self._jac.target, 1))*self._jac)
def exp(self):
tmp = self._val.exp()
......@@ -132,4 +134,3 @@ class Linearization(object):
def make_const(field):
from .operators.null_operator import NullOperator
return Linearization(field, NullOperator({}, field.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