diff --git a/demos/nonlinear_wiener_filter.py b/demos/nonlinear_wiener_filter.py index d19e739ac3d9aa48e377c557c4f71c5aaa26ee4a..170d332d3ca2fa4a5098521ac1ea7ac72810c9de 100644 --- a/demos/nonlinear_wiener_filter.py +++ b/demos/nonlinear_wiener_filter.py @@ -10,8 +10,8 @@ if __name__ == "__main__": p_spec = lambda k: (1. / (k*correlation_length + 1) ** 4) nonlinearity = Tanh() - #nonlinearity = Linear() - #nonlinearity = Exponential() + # nonlinearity = Linear() + # nonlinearity = Exponential() # Set up position space s_space = ift.RGSpace(1024) diff --git a/nifty4/__init__.py b/nifty4/__init__.py index 2f1de367bdd911dec158ce18d0998931a6667c7d..842182d7a06bb5de7dca772bad5d4e97d6f6163c 100644 --- a/nifty4/__init__.py +++ b/nifty4/__init__.py @@ -28,5 +28,5 @@ from .multi import * __all__ = ["__version__", "dobj", "DomainTuple"] + \ domains.__all__ + operators.__all__ + minimization.__all__ + \ - ["DomainTuple", "Field", "sqrt", "exp", "log"] + \ + ["DomainTuple", "Field", "sqrt", "exp", "log", "tanh"] + \ multi.__all__ diff --git a/nifty4/minimization/line_energy.py b/nifty4/minimization/line_energy.py index 962271a9fdc257477f52bb8a12a7d533ebc8f7c0..2ef3518fe66012954f2b8163ea5a05873f9bb8bd 100644 --- a/nifty4/minimization/line_energy.py +++ b/nifty4/minimization/line_energy.py @@ -97,5 +97,5 @@ class LineEnergy(object): if abs(res.imag) / max(abs(res.real), 1.) > 1e-12: from ..logger import logger logger.warning("directional derivative has non-negligible " - "imaginary part:", res) + "imaginary part: {}".format(res)) return res.real diff --git a/nifty4/minimization/scipy_minimizer.py b/nifty4/minimization/scipy_minimizer.py index 7356c3e1cf86728559129dbba7c179caad189891..c876cbc752654f815f576fc74ec8e495d4a5b1d3 100644 --- a/nifty4/minimization/scipy_minimizer.py +++ b/nifty4/minimization/scipy_minimizer.py @@ -98,7 +98,7 @@ class ScipyMinimizer(Minimizer): r = opt.minimize(hlp.fun, x, method=self._method, jac=hlp.jac, hessp=hessp, options=self._options, bounds=bounds) if not r.success: - logger.error("Problem in Scipy minimization:", r.message) + logger.error("Problem in Scipy minimization: {}".format(r.message)) return hlp._energy, IterationController.ERROR return hlp._energy, IterationController.CONVERGED diff --git a/nifty4/operators/linear_operator.py b/nifty4/operators/linear_operator.py index 185c5049bb59da93aa70d651e49f883b10c1ef0d..7799c98a8f25fd92aa0d3567d2c208649afa59a2 100644 --- a/nifty4/operators/linear_operator.py +++ b/nifty4/operators/linear_operator.py @@ -130,16 +130,22 @@ class LinearOperator(NiftyMetaBase()): def __mul__(self, other): from .chain_operator import ChainOperator + if np.isscalar(other) and other == 1.: + return self other = self._toOperator(other, self.domain) return ChainOperator.make([self, other]) def __rmul__(self, other): from .chain_operator import ChainOperator + if np.isscalar(other) and other == 1.: + return self other = self._toOperator(other, self.target) return ChainOperator.make([other, self]) def __add__(self, other): from .sum_operator import SumOperator + if np.isscalar(other) and other == 0.: + return self other = self._toOperator(other, self.domain) return SumOperator.make([self, other], [False, False]) @@ -148,6 +154,8 @@ class LinearOperator(NiftyMetaBase()): def __sub__(self, other): from .sum_operator import SumOperator + if np.isscalar(other) and other == 0.: + return self other = self._toOperator(other, self.domain) return SumOperator.make([self, other], [False, True])