test_adjoint.py 1.65 KB
Newer Older
1
2
3
4
5
6
7
8
9
import unittest
import nifty2go as ift
import numpy as np
from itertools import product
from test.common import expand
from numpy.testing import assert_allclose


def _check_adjointness(op, dtype=np.float64):
Martin Reinecke's avatar
Martin Reinecke committed
10
11
    f1 = ift.Field.from_random("normal", domain=op.domain, dtype=dtype)
    f2 = ift.Field.from_random("normal", domain=op.target, dtype=dtype)
12
13
14
    assert_allclose(f1.vdot(op.adjoint_times(f2)), op.times(f1).vdot(f2),
                    rtol=1e-8)

Martin Reinecke's avatar
Martin Reinecke committed
15
16
17
18
19
20
21
22
_harmonic_spaces = [ift.RGSpace(7, distances=0.2, harmonic=True),
                    ift.RGSpace((12, 46), distances=(0.2, 0.3), harmonic=True),
                    ift.LMSpace(17)]

_position_spaces = [ift.RGSpace(19, distances=0.7),
                    ift.RGSpace((1, 2, 3, 6), distances=(0.2, 0.25, 0.34, .8)),
                    ift.HPSpace(17),
                    ift.GLSpace(8, 13)]
23

Martin Reinecke's avatar
Martin Reinecke committed
24

25
26
27
28
29
class Adjointness_Tests(unittest.TestCase):
    @expand(product(_harmonic_spaces, [np.float64, np.complex128]))
    def testPPO(self, sp, dtype):
        op = ift.PowerProjectionOperator(sp)
        _check_adjointness(op, dtype)
Martin Reinecke's avatar
Martin Reinecke committed
30
31
        ps = ift.PowerSpace(
            sp, ift.PowerSpace.useful_binbounds(sp, logarithmic=False, nbin=3))
32
33
        op = ift.PowerProjectionOperator(sp, ps)
        _check_adjointness(op, dtype)
Martin Reinecke's avatar
Martin Reinecke committed
34
35
        ps = ift.PowerSpace(
            sp, ift.PowerSpace.useful_binbounds(sp, logarithmic=True, nbin=3))
36
37
        op = ift.PowerProjectionOperator(sp, ps)
        _check_adjointness(op, dtype)
Martin Reinecke's avatar
Martin Reinecke committed
38

Martin Reinecke's avatar
Martin Reinecke committed
39
40
    @expand(product(_harmonic_spaces+_position_spaces,
                    [np.float64, np.complex128]))
Martin Reinecke's avatar
Martin Reinecke committed
41
42
43
    def testFFT(self, sp, dtype):
        op = ift.FFTOperator(sp)
        _check_adjointness(op, dtype)