Commit 65a391ac authored by Philipp Arras's avatar Philipp Arras

Merge branch 'issue311' into 'NIFTy_7'

Fix constant support of EnergyAdapter

See merge request !562
parents 46ece3be ebb8bc3e
Pipeline #78838 passed with stages
in 25 minutes and 56 seconds
...@@ -50,12 +50,13 @@ class EnergyAdapter(Energy): ...@@ -50,12 +50,13 @@ class EnergyAdapter(Energy):
def __init__(self, position, op, constants=[], want_metric=False, def __init__(self, position, op, constants=[], want_metric=False,
nanisinf=False): nanisinf=False):
if len(constants) > 0:
cstpos = position.extract_by_keys(constants)
_, op = op.simplify_for_constant_input(cstpos)
varkeys = set(op.domain.keys()) - set(constants)
position = position.extract_by_keys(varkeys)
super(EnergyAdapter, self).__init__(position) super(EnergyAdapter, self).__init__(position)
self._op = op self._op = op
if len(constants) > 0:
dom = makeDomain({kk: vv for kk, vv in position.domain.items()
if kk in constants})
_, self._op = op.simplify_for_constant_input(position.extract(dom))
self._want_metric = want_metric self._want_metric = want_metric
lin = Linearization.make_var(position, want_metric) lin = Linearization.make_var(position, want_metric)
tmp = self._op(lin) tmp = self._op(lin)
......
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