symmetrizing_operator.py 1.07 KB
 Philipp Arras committed Jun 27, 2018 1 2 3 ``````from ..domain_tuple import DomainTuple from ..field import Field from .endomorphic_operator import EndomorphicOperator `````` Martin Reinecke committed Jul 02, 2018 4 ``````from .. import dobj `````` Philipp Arras committed Jun 27, 2018 5 6 `````` `````` Martin Reinecke committed Jul 08, 2018 7 ``````# MR FIXME: we should make sure that the domain is a harmonic RGSpace, correct? `````` Philipp Arras committed Jun 27, 2018 8 9 10 11 12 13 14 15 16 17 18 ``````class SymmetrizingOperator(EndomorphicOperator): def __init__(self, domain): self._domain = DomainTuple.make(domain) self._ndim = len(self.domain.shape) @property def domain(self): return self._domain def apply(self, x, mode): self._check_input(x, mode) `````` Martin Reinecke committed Jul 04, 2018 19 `````` tmp = x.val.copy() `````` Martin Reinecke committed Jul 02, 2018 20 21 `````` ax = dobj.distaxis(tmp) globshape = tmp.shape `````` Philipp Arras committed Jun 27, 2018 22 23 `````` for i in range(self._ndim): lead = (slice(None),)*i `````` Martin Reinecke committed Jul 02, 2018 24 25 `````` if i == ax: tmp = dobj.redistribute(tmp, nodist=(ax,)) `````` Martin Reinecke committed Jul 04, 2018 26 27 `````` tmp2 = dobj.local_data(tmp) tmp2[lead+(slice(1, None),)] -= tmp2[lead+(slice(None, 0, -1),)] `````` Martin Reinecke committed Jul 02, 2018 28 29 30 `````` if i == ax: tmp = dobj.redistribute(tmp, dist=ax) return Field(self.target, val=tmp) `````` Philipp Arras committed Jun 27, 2018 31 32 33 34 `````` @property def capability(self): return self.TIMES | self.ADJOINT_TIMES``````