test_smoothing_operator.py 2.15 KB
Newer Older
1
2
3
4
5
6
7
import unittest

from numpy.testing import assert_equal,\
    assert_allclose,\
    assert_approx_equal

from nifty import Field,\
8
9
    RGSpace,\
    PowerSpace,\
10
11
12
13
14
15
    SmoothingOperator

from itertools import product
from test.common import expand

class SmoothingOperator_Tests(unittest.TestCase):
16
    spaces = [RGSpace(100)]
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42

    @expand(product(spaces, [0., .5, 5.], [True, False]))
    def test_property(self, space, sigma, log_distances):
        op = SmoothingOperator(space, sigma=sigma,
                              log_distances=log_distances)
        if op.domain[0] != space:
            raise TypeError
        if op.unitary != False:
            raise ValueError
        if op.self_adjoint != True:
            raise ValueError
        if op.sigma != sigma:
            raise ValueError
        if op.log_distances != log_distances:
            raise ValueError

    @expand(product(spaces, [0., .5, 5.], [True, False]))
    def test_adjoint_times(self, space, sigma, log_distances):
        op = SmoothingOperator(space, sigma=sigma,
                              log_distances=log_distances)
        rand1 = Field.from_random('normal', domain=space)
        rand2 = Field.from_random('normal', domain=space)
        tt1 = rand1.dot(op.times(rand2))
        tt2 = rand2.dot(op.adjoint_times(rand1))
        assert_approx_equal(tt1, tt2)

43
    @expand(product(spaces, [0., .5, 5.], [False]))
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
    def test_times(self, space, sigma, log_distances):
        op = SmoothingOperator(space, sigma=sigma,
                              log_distances=log_distances)
        rand1 = Field(space, val=0.)
        rand1.val[0] = 1.
        tt1 = op.times(rand1)
        assert_approx_equal(1, tt1.sum())

    @expand(product(spaces, [0., .5, 5.], [True, False]))
    def test_inverse_adjoint_times(self, space, sigma, log_distances):
        op = SmoothingOperator(space, sigma=sigma,
                              log_distances=log_distances)
        rand1 = Field.from_random('normal', domain=space)
        rand2 = Field.from_random('normal', domain=space)
        tt1 = rand1.dot(op.inverse_times(rand2))
        tt2 = rand2.dot(op.inverse_adjoint_times(rand1))
        assert_approx_equal(tt1, tt2)