Commit b719e4ae authored by Martin Reinecke's avatar Martin Reinecke
Browse files

small optimizations

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