symmetrizing_operator.py 1.16 KB
Newer Older
Martin Reinecke's avatar
Martin Reinecke committed
1
2
from __future__ import absolute_import, division, print_function
from ..compat import *
3
4
5
from ..domain_tuple import DomainTuple
from ..field import Field
from .endomorphic_operator import EndomorphicOperator
Martin Reinecke's avatar
Martin Reinecke committed
6
from .. import dobj
7
8


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

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