test_nifty_field.py 3.78 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# -*- coding: utf-8 -*-

from numpy.testing import assert_equal,\
    assert_almost_equal,\
    assert_raises

from nose_parameterized import parameterized
import unittest
import itertools
import numpy as np

from nifty import space,\
    point_space,\
    rg_space,\
    lm_space,\
    hp_space,\
csongor's avatar
csongor committed
17
18
19
    gl_space

from nifty.nifty_field import field
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59

from nifty.nifty_core import POINT_DISTRIBUTION_STRATEGIES
from nifty.rg.nifty_rg import RG_DISTRIBUTION_STRATEGIES,\
                              gc as RG_GC
from nifty.lm.nifty_lm import LM_DISTRIBUTION_STRATEGIES,\
                              GL_DISTRIBUTION_STRATEGIES,\
                              HP_DISTRIBUTION_STRATEGIES


###############################################################################

def custom_name_func(testcase_func, param_num, param):
    return "%s_%s" % (
        testcase_func.__name__,
        parameterized.to_safe_name("_".join(str(x) for x in param.args)),
    )

###############################################################################
###############################################################################

all_point_datatypes = [np.dtype('bool'),
                       np.dtype('int16'),
                       np.dtype('int32'),
                       np.dtype('int64'),
                       np.dtype('float32'),
                       np.dtype('float64'),
                       np.dtype('complex64'),
                       np.dtype('complex128')]

all_lm_datatypes = [np.dtype('complex64'),
                    np.dtype('complex128')]

all_gl_datatypes = [np.dtype('float64'),
                    np.dtype('float128')]

all_hp_datatypes = [np.dtype('float64')]

###############################################################################

DATAMODELS = {}
60
61
62
63
64
DATAMODELS['point_space'] = POINT_DISTRIBUTION_STRATEGIES
DATAMODELS['rg_space'] = RG_DISTRIBUTION_STRATEGIES
DATAMODELS['lm_space'] = LM_DISTRIBUTION_STRATEGIES
DATAMODELS['gl_space'] = GL_DISTRIBUTION_STRATEGIES
DATAMODELS['hp_space'] = HP_DISTRIBUTION_STRATEGIES
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83

###############################################################################

fft_modules = []
for name in ['gfft', 'gfft_dummy', 'pyfftw']:
    if RG_GC.validQ('fft_module', name):
        fft_modules += [name]

###############################################################################

point_like_spaces = ['point_space', 'rg_space', 'lm_space', 'hp_space',
                     'gl_space']

###############################################################################

space_list = []

# Add point_spaces
for param in itertools.product([1, 10],
csongor's avatar
csongor committed
84
85
                               all_point_datatypes):
    space_list += [[point_space(num=param[0], dtype=param[1])]]
86
87
88
89
90
91

# Add rg_spaces
for param in itertools.product([(1,), (4, 6), (5, 8)],
                               [False, True],
                               [0, 1, 2],
                               [None, 0.3],
csongor's avatar
csongor committed
92
                               [False],
93
94
                               DATAMODELS['rg_space'],
                               fft_modules):
csongor's avatar
csongor committed
95
    space_list += [[(rg_space(shape=param[0],
96
97
98
99
                            zerocenter=param[1],
                            complexity=param[2],
                            distances=param[3],
                            harmonic=param[4],
csongor's avatar
csongor committed
100
                            fft_module=param[6]),param[6])]]
101
102
103
104
105
106
107
108


###############################################################################
###############################################################################

class Test_field_init(unittest.TestCase):

    @parameterized.expand(space_list)
csongor's avatar
csongor committed
109
110
    def test_successfull_init_and_attributes(self, s, datamodel):
        f = field(domain=np.array([s]), dtype=s.dtype, datamodel=datamodel)
111
112
        assert(f.domain[0] is s)
        assert(s.check_codomain(f.codomain[0]))
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153