Commit de87751b authored by Philipp Arras's avatar Philipp Arras
Browse files

Refactor

parent 19ab4fa3
...@@ -324,20 +324,20 @@ class MultiField(object): ...@@ -324,20 +324,20 @@ class MultiField(object):
val = tuple(f(v1, other) for v1 in self._val) val = tuple(f(v1, other) for v1 in self._val)
return MultiField(self._domain, val) return MultiField(self._domain, val)
def _sinc_withjac(self):
return self._nontrivial_jac_helper('_sinc_withjac') for op in ["sinc", "absolute"]:
ss = f'_{op}_withjac'
def _absolute_withjac(self): def func(ss):
return self._nontrivial_jac_helper('_absolute_withjac') def func2(self):
val = self.to_dict()
def _nontrivial_jac_helper(self, funcname): jac = {}
val = self.to_dict() for kk, vv in val.items():
jac = {} val[kk], jac[kk] = getattr(vv, ss)()
for kk, vv in val.items(): val = MultiField.from_dict(val, self._domain)
val[kk], jac[kk] = getattr(vv, funcname)() jac = MultiField.from_dict(jac, self._domain)
val = MultiField.from_dict(val, self._domain) return val, jac
jac = MultiField.from_dict(jac, self._domain) return func2
return val, jac setattr(MultiField, ss, func(ss))
for op in ["__add__", "__radd__", for op in ["__add__", "__radd__",
......
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