qht_operator.py 2.62 KB
Newer Older
Martin Reinecke's avatar
Martin Reinecke committed
1
2
3
4
5
6
7
8
9
10
11
12
13
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
14
# Copyright(C) 2013-2019 Max-Planck-Society
Martin Reinecke's avatar
Martin Reinecke committed
15
#
16
# NIFTy is being developed at the Max-Planck-Institut fuer Astrophysik.
17
18

from .. import dobj
19
from .. import fft
20
21
from ..domain_tuple import DomainTuple
from ..field import Field
22
from ..utilities import infer_space
23
24
25
26
from .linear_operator import LinearOperator


class QHTOperator(LinearOperator):
27
    """Does a Hartley transform on LogRGSpace
Reimar H Leike's avatar
Reimar H Leike committed
28

Martin Reinecke's avatar
Martin Reinecke committed
29
    This operator takes a field on a LogRGSpace and performs a Hartley
Philipp Arras's avatar
Docs  
Philipp Arras committed
30
31
    transform. The zero modes are not transformed because they are infinitely
    far away in LogRGSpaces.
Reimar H Leike's avatar
Reimar H Leike committed
32
33
34

    Parameters
    ----------
Martin Reinecke's avatar
Martin Reinecke committed
35
36
    target : domain, tuple of domains or DomainTuple
        The full output domain
Martin Reinecke's avatar
Martin Reinecke committed
37
38
    space : int
        The index of the domain on which the operator acts.
39
        target[space] must be a non-harmonic LogRGSpace.
Reimar H Leike's avatar
Reimar H Leike committed
40
    """
Philipp Arras's avatar
Philipp Arras committed
41

Martin Reinecke's avatar
Martin Reinecke committed
42
43
44
    def __init__(self, target, space=0):
        self._target = DomainTuple.make(target)
        self._space = infer_space(self._target, space)
45

Martin Reinecke's avatar
fixes  
Martin Reinecke committed
46
        from ..domains.log_rg_space import LogRGSpace
Martin Reinecke's avatar
Martin Reinecke committed
47
48
        if not isinstance(self._target[self._space], LogRGSpace):
            raise ValueError("target[space] has to be a LogRGSpace!")
49

Martin Reinecke's avatar
Martin Reinecke committed
50
        if self._target[self._space].harmonic:
51
            raise TypeError("target[space] must be a nonharmonic space")
Martin Reinecke's avatar
Martin Reinecke committed
52

Martin Reinecke's avatar
Martin Reinecke committed
53
54
55
56
        self._domain = [dom for dom in self._target]
        self._domain[self._space] = \
            self._target[self._space].get_default_codomain()
        self._domain = DomainTuple.make(self._domain)
Martin Reinecke's avatar
Martin Reinecke committed
57
        self._capability = self.TIMES | self.ADJOINT_TIMES
58
59
60

    def apply(self, x, mode):
        self._check_input(x, mode)
Martin Reinecke's avatar
Martin Reinecke committed
61
        dom = self._domain[self._space]
Martin Reinecke's avatar
Martin Reinecke committed
62
        v = x.val * dom.scalar_dvol
Martin Reinecke's avatar
Martin Reinecke committed
63
64
        n = self._domain.axes[self._space]
        rng = n if mode == self.TIMES else reversed(n)
65
66
        for i in rng:
            sl = (slice(None),)*i + (slice(1, None),)
Martin Reinecke's avatar
Martin Reinecke committed
67
            v, tmp = dobj.ensure_not_distributed(v, (i,))
68
            tmp[sl] = fft.hartley(tmp[sl], axes=(i,))
Martin Reinecke's avatar
Martin Reinecke committed
69
        return Field(self._tgt(mode), dobj.ensure_default_distributed(v))