test_adjoint.py 3.22 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-2018 Max-Planck-Society
Martin Reinecke's avatar
Martin Reinecke committed
15
16
17
18
#
# NIFTy is being developed at the Max-Planck-Institut fuer Astrophysik
# and financially supported by the Studienstiftung des deutschen Volkes.

19
import unittest
Martin Reinecke's avatar
Martin Reinecke committed
20
import nifty4 as ift
21
22
23
24
import numpy as np
from itertools import product
from test.common import expand

25

26
27
28
_h_RG_spaces = [ift.RGSpace(7, distances=0.2, harmonic=True),
                ift.RGSpace((12, 46), distances=(.2, .3), harmonic=True)]
_h_spaces = _h_RG_spaces + [ift.LMSpace(17)]
Martin Reinecke's avatar
Martin Reinecke committed
29

30
31
32
_p_RG_spaces = [ift.RGSpace(19, distances=0.7),
                ift.RGSpace((1, 2, 3, 6), distances=(0.2, 0.25, 0.34, .8))]
_p_spaces = _p_RG_spaces + [ift.HPSpace(17), ift.GLSpace(8, 13)]
33

Martin Reinecke's avatar
Martin Reinecke committed
34
_pow_spaces = [ift.PowerSpace(ift.RGSpace((17,38), harmonic=True))]
Martin Reinecke's avatar
Martin Reinecke committed
35

36
class Consistency_Tests(unittest.TestCase):
37
    @expand(product(_h_spaces, [np.float64, np.complex128]))
38
    def testPPO(self, sp, dtype):
Martin Reinecke's avatar
Martin Reinecke committed
39
        op = ift.PowerDistributor(target=sp)
40
        ift.extra.consistency_check(op, dtype, dtype)
Martin Reinecke's avatar
Martin Reinecke committed
41
42
        ps = ift.PowerSpace(
            sp, ift.PowerSpace.useful_binbounds(sp, logarithmic=False, nbin=3))
Martin Reinecke's avatar
Martin Reinecke committed
43
        op = ift.PowerDistributor(target=sp, power_space=ps)
44
        ift.extra.consistency_check(op, dtype, dtype)
Martin Reinecke's avatar
Martin Reinecke committed
45
46
        ps = ift.PowerSpace(
            sp, ift.PowerSpace.useful_binbounds(sp, logarithmic=True, nbin=3))
Martin Reinecke's avatar
Martin Reinecke committed
47
        op = ift.PowerDistributor(target=sp, power_space=ps)
48
        ift.extra.consistency_check(op, dtype, dtype)
Martin Reinecke's avatar
Martin Reinecke committed
49

50
    @expand(product(_h_RG_spaces+_p_RG_spaces,
Martin Reinecke's avatar
Martin Reinecke committed
51
                    [np.float64, np.complex128]))
Martin Reinecke's avatar
Martin Reinecke committed
52
53
    def testFFT(self, sp, dtype):
        op = ift.FFTOperator(sp)
54
        ift.extra.consistency_check(op, dtype, dtype)
Martin Reinecke's avatar
Martin Reinecke committed
55
        op = ift.FFTOperator(sp.get_default_codomain())
56
        ift.extra.consistency_check(op, dtype, dtype)
57
58
59
60

    @expand(product(_h_spaces, [np.float64, np.complex128]))
    def testHarmonic(self, sp, dtype):
        op = ift.HarmonicTransformOperator(sp)
61
62
63
64
65
66
67
        ift.extra.consistency_check(op, dtype, dtype)

    @expand(product(_h_spaces+_p_spaces, [np.float64, np.complex128]))
    def testDiagonal(self, sp, dtype):
        op = ift.DiagonalOperator(ift.Field.from_random("normal", sp,
                                                        dtype=dtype))
        ift.extra.consistency_check(op, dtype, dtype)
Martin Reinecke's avatar
Martin Reinecke committed
68
69
70
71
72

    @expand(product(_pow_spaces, [np.float64, np.complex128]))
    def testLaplace(self, sp, dtype):
        op = ift.LaplaceOperator(sp)
        ift.extra.consistency_check(op, dtype, dtype)
Martin Reinecke's avatar
Martin Reinecke committed
73
74
75
76
77

    @expand(product(_pow_spaces, [np.float64, np.complex128]))
    def testSmoothness(self, sp, dtype):
        op = ift.SmoothnessOperator(sp)
        ift.extra.consistency_check(op, dtype, dtype)