test_value_inserter.py 1.39 KB
Newer Older
Philipp Arras's avatar
Philipp Arras 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-2019 Max-Planck-Society
#
# NIFTy is being developed at the Max-Planck-Institut fuer Astrophysik.

import numpy as np
import pytest
20
from numpy.testing import assert_
Philipp Arras's avatar
Philipp Arras committed
21

Martin Reinecke's avatar
5->6    
Martin Reinecke committed
22
import nifty6 as ift
Philipp Arras's avatar
Philipp Arras committed
23
24
25
26
27
28
29
30
31


@pytest.mark.parametrize('sp', [
    ift.RGSpace(4),
    ift.PowerSpace(ift.RGSpace((4, 4), harmonic=True)),
    ift.LMSpace(5),
    ift.HPSpace(4),
    ift.GLSpace(4)
])
Philipp Arras's avatar
Philipp Arras committed
32
33
@pytest.mark.parametrize('seed', [13, 2])
def test_value_inserter(sp, seed):
Martin Reinecke's avatar
Martin Reinecke committed
34
35
    ift.random.push_sseq_from_seed(seed)
    ind = tuple([int(ift.random.current_rng().integers(0, ss - 1)) for ss in sp.shape])
Philipp Arras's avatar
Philipp Arras committed
36
    op = ift.ValueInserter(sp, ind)
Philipp Arras's avatar
Philipp Arras committed
37
    f = ift.from_random('normal', op.domain)
Martin Reinecke's avatar
Martin Reinecke committed
38
    ift.random.pop_sseq()
Martin Reinecke's avatar
stage 3    
Martin Reinecke committed
39
40
    inp = f.val
    ret = op(f).val
41
42
    assert_(ret[ind] == inp)
    assert_(np.sum(ret) == inp)