test_multi_field.py 2.2 KB
Newer Older
Martin Reinecke's avatar
Martin Reinecke committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# 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/>.
#
# Copyright(C) 2013-2018 Max-Planck-Society
#
# NIFTy is being developed at the Max-Planck-Institut fuer Astrophysik
# and financially supported by the Studienstiftung des deutschen Volkes.

import unittest
20

Philipp Arras's avatar
Philipp Arras committed
21
import nifty5 as ift
22
23
import numpy as np
from numpy.testing import assert_allclose, assert_equal
Martin Reinecke's avatar
Martin Reinecke committed
24
25
26

dom = ift.makeDomain({"d1": ift.RGSpace(10)})

27

Martin Reinecke's avatar
Martin Reinecke committed
28
29
30
31
32
33
class Test_Functionality(unittest.TestCase):
    def test_vdot(self):
        f1 = ift.from_random("normal", domain=dom, dtype=np.complex128)
        f2 = ift.from_random("normal", domain=dom, dtype=np.complex128)
        assert_allclose(f1.vdot(f2), np.conj(f2.vdot(f1)))

Martin Reinecke's avatar
Martin Reinecke committed
34
35
36
37
38
    def test_func(self):
        f1 = ift.from_random("normal", domain=dom, dtype=np.complex128)
        assert_allclose(ift.log(ift.exp((f1)))["d1"].local_data,
                        f1["d1"].local_data)

Martin Reinecke's avatar
Martin Reinecke committed
39
    def test_dataconv(self):
Martin Reinecke's avatar
fixes    
Martin Reinecke committed
40
41
42
43
44
45
        f1 = ift.full(dom, 27)
        f2 = ift.from_global_data(dom, f1.to_global_data())
        for key, val in f1.items():
            assert_equal(val.local_data, f2[key].local_data)

    def test_blockdiagonal(self):
Martin Reinecke's avatar
fixes    
Martin Reinecke committed
46
        op = ift.BlockDiagonalOperator(
Martin Reinecke's avatar
Martin Reinecke committed
47
            dom, (ift.ScalingOperator(20., dom["d1"]),))
Martin Reinecke's avatar
Martin Reinecke committed
48
        op2 = op(op)
Martin Reinecke's avatar
Martin Reinecke committed
49
        ift.extra.consistency_check(op2)
Martin Reinecke's avatar
fixes    
Martin Reinecke committed
50
51
52
53
54
55
56
57
58
        assert_equal(type(op2), ift.BlockDiagonalOperator)
        f1 = op2(ift.full(dom, 1))
        for val in f1.values():
            assert_equal((val == 400).all(), True)
        op2 = op+op
        assert_equal(type(op2), ift.BlockDiagonalOperator)
        f1 = op2(ift.full(dom, 1))
        for val in f1.values():
            assert_equal((val == 40).all(), True)