test_simplification.py 1.87 KB
Newer Older
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/>.
#
Martin Reinecke's avatar
Martin Reinecke committed
14
# Copyright(C) 2013-2019 Max-Planck-Society
15
#
Martin Reinecke's avatar
Martin Reinecke committed
16
# NIFTy is being developed at the Max-Planck-Institut fuer Astrophysik.
17

18
from numpy.testing import assert_, assert_allclose
19

Martin Reinecke's avatar
Martin Reinecke committed
20
import nifty7 as ift
21
from nifty7.operators.simplify_for_const import ConstantOperator
22
23


Martin Reinecke's avatar
Martin Reinecke committed
24
def test_simplification():
25
26
27
28
29
    # f1 = ift.Field.full(ift.RGSpace(10), 2.)
    # op = ift.FFTOperator(f1.domain)
    # _, op2 = op.simplify_for_constant_input(f1)
    # assert_(isinstance(op2, ConstantOperator))
    # assert_allclose(op(f1).val, op2.force(f1).val)
30

Martin Reinecke's avatar
Martin Reinecke committed
31
    dom = {"a": ift.RGSpace(10)}
Martin Reinecke's avatar
Martin Reinecke committed
32
    f1 = ift.full(dom, 2.)
Martin Reinecke's avatar
Martin Reinecke committed
33
34
    op = ift.FFTOperator(f1.domain["a"]).ducktape("a")
    _, op2 = op.simplify_for_constant_input(f1)
35
36
    assert_(isinstance(op2, ConstantOperator))
    assert_allclose(op(f1).val, op2.force(f1).val)
37

Martin Reinecke's avatar
Martin Reinecke committed
38
    dom = {"a": ift.RGSpace(10), "b": ift.RGSpace(5)}
Martin Reinecke's avatar
Martin Reinecke committed
39
    f1 = ift.full(dom, 2.)
Martin Reinecke's avatar
Martin Reinecke committed
40
    pdom = {"a": ift.RGSpace(10)}
Martin Reinecke's avatar
Martin Reinecke committed
41
    f2 = ift.full(pdom, 2.)
Martin Reinecke's avatar
Martin Reinecke committed
42
43
44
45
46
    o1 = ift.FFTOperator(f1.domain["a"])
    o2 = ift.FFTOperator(f1.domain["b"])
    op = (o1.ducktape("a").ducktape_left("a") +
          o2.ducktape("b").ducktape_left("b"))
    _, op2 = op.simplify_for_constant_input(f2)
47
48
    assert_allclose(op(f1)["a"].val, op2.force(f1)["a"].val)
    assert_allclose(op(f1)["b"].val, op2.force(f1)["b"].val)