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

Commit b719e4ae authored by Martin Reinecke's avatar Martin Reinecke

small optimizations

parent 85b3b288
......@@ -33,7 +33,7 @@ if __name__ == '__main__':
# Two-dimensional regular grid with inhomogeneous exposure
position_space = ift.RGSpace([512, 512])
# # Sphere with with uniform exposure
# Sphere with uniform exposure
# position_space = ift.HPSpace(128)
# exposure = ift.Field.full(position_space, 1.)
......
......@@ -49,7 +49,7 @@ if __name__ == '__main__':
position_space = ift.RGSpace([512, 512])
exposure = get_2D_exposure()
# # Sphere with with uniform exposure
# Sphere with uniform exposure
# position_space = ift.HPSpace(128)
# exposure = ift.Field.full(position_space, 1.)
......@@ -70,7 +70,7 @@ if __name__ == '__main__':
A = pd(a)
# Set up a sky model
sky = HT.chain(ift.makeOp(A)).exp()
sky = ift.exp(HT.chain(ift.makeOp(A)))
M = ift.DiagonalOperator(exposure)
GR = ift.GeometryRemover(position_space)
......@@ -99,7 +99,6 @@ if __name__ == '__main__':
H, convergence = minimizer(H)
# Plot results
result_sky = sky(H.position)
ift.plot(result_sky)
ift.plot(sky(H.position))
ift.plot_finish()
# FIXME PLOTTING
......@@ -25,8 +25,8 @@ from ..utilities import NiftyMetaBase, memo
class Energy(NiftyMetaBase()):
""" Provides the functional used by minimization schemes.
The Energy object is an implementation of a scalar function including its
gradient and metric at some position.
The Energy object is an implementation of a scalar function including its
gradient and metric at some position.
Parameters
----------
......
......@@ -221,17 +221,16 @@ class MultiField(object):
return MultiField.from_dict({key: self[key] for key in subset})
def unite(self, other):
if self._domain is other._domain:
return self + other
return self.combine((self, other))
@staticmethod
def combine(fields):
res = {}
for f in fields:
for key in f.keys():
if key in res:
res[key] = res[key]+f[key]
else:
res[key] = f[key]
for key, val in f.items():
res[key] = res[key]+val if key in res else val
return MultiField.from_dict(res)
......
......@@ -261,7 +261,8 @@ for f in ["sqrt", "exp", "log", "tanh", "positive_tanh", "conjugate"]:
def func(f):
def func2(x):
from .linearization import Linearization
if isinstance(x, (Field, MultiField, Linearization)):
from .operators.operator import Operator
if isinstance(x, (Field, MultiField, Linearization, Operator)):
return getattr(x, f)()
else:
return getattr(np, f)(x)
......
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