Commit dba4b443 authored by Theo Steininger's avatar Theo Steininger
Browse files

Fixed RGSpace Tests

parent fd98cba2
Pipeline #16546 canceled with stage
in 18 minutes and 34 seconds
...@@ -23,8 +23,9 @@ import numpy as np ...@@ -23,8 +23,9 @@ import numpy as np
from d2o import distributed_data_object from d2o import distributed_data_object
from numpy.testing import assert_, assert_equal, assert_almost_equal from numpy.testing import assert_, assert_equal, assert_almost_equal, \
from nifty import RGSpace assert_array_equal
from nifty import RGSpace, nifty_configuration
from test.common import expand from test.common import expand
from itertools import product from itertools import product
...@@ -66,23 +67,23 @@ CONSTRUCTOR_CONFIGS = [ ...@@ -66,23 +67,23 @@ CONSTRUCTOR_CONFIGS = [
'dim': 8, 'dim': 8,
'total_volume': 96.0 'total_volume': 96.0
}], }],
[(11, 11), (False, True), None, False, [(11, 11), False, None, False,
{ {
'shape': (11, 11), 'shape': (11, 11),
'zerocenter': (False, True), 'zerocenter': (False, False),
'distances': (1/11, 1/11), 'distances': (1/11, 1/11),
'harmonic': False, 'harmonic': False,
'dim': 121, 'dim': 121,
'total_volume': 1.0 'total_volume': 1.0
}], }],
[(11, 11), True, (1.3, 1.3), True, [(12, 12), True, (1.3, 1.3), True,
{ {
'shape': (11, 11), 'shape': (12, 12),
'zerocenter': (True, True), 'zerocenter': (True, True),
'distances': (1.3, 1.3), 'distances': (1.3, 1.3),
'harmonic': True, 'harmonic': True,
'dim': 121, 'dim': 144,
'total_volume': 204.49 'total_volume': 243.36
}] }]
] ]
...@@ -156,26 +157,32 @@ class RGSpaceFunctionalityTests(unittest.TestCase): ...@@ -156,26 +157,32 @@ class RGSpaceFunctionalityTests(unittest.TestCase):
@expand(product([(10,), (11,), (1, 1), (4, 4), (5, 7), (8, 12), (7, 16), @expand(product([(10,), (11,), (1, 1), (4, 4), (5, 7), (8, 12), (7, 16),
(4, 6, 8), (17, 5, 3)], (4, 6, 8), (17, 5, 3)],
[True, False])) [True, False],
def test_hermitianize_inverter(self, shape, zerocenter): ['real', 'complex']))
def test_hermitianize_inverter(self, shape, zerocenter, base):
r = RGSpace(shape, harmonic=True, zerocenter=zerocenter) r = RGSpace(shape, harmonic=True, zerocenter=zerocenter)
v = distributed_data_object(global_shape=shape, dtype=np.complex128) v = distributed_data_object(global_shape=shape, dtype=np.complex128)
v[:] = np.random.random(shape) + 1j*np.random.random(shape) v[:] = np.random.random(shape) + 1j*np.random.random(shape)
nifty_configuration['harmonic_rg_base'] = base
inverted = r.hermitianize_inverter(v, axes=range(len(shape))) inverted = r.hermitianize_inverter(v, axes=range(len(shape)))
# test hermitian flipping of `inverted` if base == 'complex':
it = np.nditer(v, flags=['multi_index']) # test hermitian flipping of `inverted`
while not it.finished: it = np.nditer(v, flags=['multi_index'])
i1 = it.multi_index while not it.finished:
i2 = [] i1 = it.multi_index
for i in range(len(i1)): i2 = []
if r.zerocenter[i] and r.shape[i] % 2 != 0: for i in range(len(i1)):
i2.append(v.shape[i]-i1[i]-1) if r.zerocenter[i] and r.shape[i] % 2 != 0:
else: i2.append(v.shape[i]-i1[i]-1)
i2.append(v.shape[i]-i1[i] if i1[i] > 0 else 0) else:
i2 = tuple(i2) i2.append(v.shape[i]-i1[i] if i1[i] > 0 else 0)
assert_almost_equal(inverted[i1], v[i2]) i2 = tuple(i2)
it.iternext() assert_almost_equal(inverted[i1], v[i2])
it.iternext()
else:
assert_array_equal(v, inverted)
@expand(get_distance_array_configs()) @expand(get_distance_array_configs())
def test_distance_array(self, shape, distances, zerocenter, expected): def test_distance_array(self, shape, distances, zerocenter, expected):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment