symmetrizing_operator.py 1019 Bytes
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
7
8
9
10
11
12
13
14
15
16
17


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)
18
        tmp = x.val.copy()
Martin Reinecke's avatar
Martin Reinecke committed
19
20
        ax = dobj.distaxis(tmp)
        globshape = tmp.shape
21
22
        for i in range(self._ndim):
            lead = (slice(None),)*i
Martin Reinecke's avatar
Martin Reinecke committed
23
24
            if i == ax:
                tmp = dobj.redistribute(tmp, nodist=(ax,))
Martin Reinecke's avatar
Martin Reinecke committed
25
26
            tmp2 = dobj.local_data(tmp)
            tmp2[lead+(slice(1, None),)] -= tmp2[lead+(slice(None, 0, -1),)]
Martin Reinecke's avatar
Martin Reinecke committed
27
28
29
            if i == ax:
                tmp = dobj.redistribute(tmp, dist=ax)
            return Field(self.target, val=tmp)
30
31
32
33

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