symmetrizing_operator.py 1.07 KB
Newer Older
1
2
3
from ..domain_tuple import DomainTuple
from ..field import Field
from .endomorphic_operator import EndomorphicOperator
Martin Reinecke's avatar
Martin Reinecke committed
4
from .. import dobj
5
6


Martin Reinecke's avatar
Martin Reinecke committed
7
# MR FIXME: we should make sure that the domain is a harmonic RGSpace, correct?
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)
19
        tmp = x.val.copy()
Martin Reinecke's avatar
Martin Reinecke committed
20
21
        ax = dobj.distaxis(tmp)
        globshape = tmp.shape
22
23
        for i in range(self._ndim):
            lead = (slice(None),)*i
Martin Reinecke's avatar
Martin Reinecke committed
24
25
            if i == ax:
                tmp = dobj.redistribute(tmp, nodist=(ax,))
Martin Reinecke's avatar
Martin Reinecke committed
26
27
            tmp2 = dobj.local_data(tmp)
            tmp2[lead+(slice(1, None),)] -= tmp2[lead+(slice(None, 0, -1),)]
Martin Reinecke's avatar
Martin Reinecke committed
28
29
30
            if i == ax:
                tmp = dobj.redistribute(tmp, dist=ax)
            return Field(self.target, val=tmp)
31
32
33
34

    @property
    def capability(self):
        return self.TIMES | self.ADJOINT_TIMES