diff --git a/nifty/field.py b/nifty/field.py index fc697139f0d27ab8036385a3c651093602414a8a..36df43152e016adf79918a04fd7ce9dded2c4cb6 100644 --- a/nifty/field.py +++ b/nifty/field.py @@ -667,7 +667,7 @@ class Field(Loggable, Versionable, object): if pindex.distribution_strategy is not local_distribution_strategy: self.logger.warn( - "The distribution_stragey of pindex does not fit the " + "The distribution_strategy of pindex does not fit the " "slice_local distribution strategy of the synthesized field.") # Now use numpy advanced indexing in order to put the entries of the diff --git a/test/test_field.py b/test/test_field.py index 7cf7055620447a4d1861b29d53a1fec8cc50d6d3..590f8ba54ccb1e0bcd8923a7587629e1bc49f074 100644 --- a/test/test_field.py +++ b/test/test_field.py @@ -20,7 +20,8 @@ import unittest import numpy as np from numpy.testing import assert_,\ - assert_equal + assert_equal,\ + assert_almost_equal from itertools import product @@ -55,25 +56,22 @@ class Test_Interface(unittest.TestCase): f = Field(domain=domain) assert_(isinstance(getattr(f, attribute), desired_type)) - def test_hermitian_decomposition2(self): - s1=(25,2) + def test_hermitian_decomposition0(self): + s1=(25,) s2=(16,) - ax1=((0,1,2),) - ax2=((0,1),(2,)) - r2 = RGSpace(s1+s2, harmonic=True) - ra = RGSpace(s1, harmonic=True) - rb = RGSpace(s2, harmonic=True) - v = np.empty(s1+s2,dtype=np.complex128) - v.real = np.random.random(s1+s2) - v.imag = np.random.random(s1+s2) - f1=Field(r2,val=v,copy=True) - f2=Field((ra,rb),val=v,copy=True) - h2,a2 = Field._hermitian_decomposition((RGSpace(s1, harmonic=True), - RGSpace(s2, harmonic=True)),f2.val,(0,1),ax2,False) - h1,a1 = Field._hermitian_decomposition((RGSpace(s1+s2, harmonic=True),), - f1.val,(0,),ax1,False) - assert(np.max(np.abs(h1-h2))<1e-10) - assert(np.max(np.abs(a1-a2))<1e-10) + r1 = RGSpace(s1, harmonic=True) + r2 = RGSpace(s2, harmonic=True) + ra = RGSpace(s1+s2, harmonic=True) + v = np.random.random(s1+s2) + 1j*np.random.random(s1+s2) + f1=Field(ra,val=v,copy=True) + f2=Field((r1,r2),val=v,copy=True) + h1,a1 = Field._hermitian_decomposition((ra,),f1.val,(0,),((0,1,),),False) + h2,a2 = Field._hermitian_decomposition((r1,r2),f2.val,(0,1),((0,),(1,)),False) + h3,a3 = Field._hermitian_decomposition((r1,r2),f2.val,(1,0),((0,),(1,)),False) + assert_almost_equal(h1.get_full_data(),h2.get_full_data()) + assert_almost_equal(a1.get_full_data(),a2.get_full_data()) + assert_almost_equal(h1.get_full_data(),h3.get_full_data()) + assert_almost_equal(a1.get_full_data(),a3.get_full_data()) #class Test_Initialization(unittest.TestCase): # diff --git a/test/test_spaces/test_rg_space.py b/test/test_spaces/test_rg_space.py index 03ee41cb82c148aa17954ebf75ce4b33632a02d3..daab9880d55302126924f46345aa7a74ae321551 100644 --- a/test/test_spaces/test_rg_space.py +++ b/test/test_spaces/test_rg_space.py @@ -162,6 +162,27 @@ class RGSpaceFunctionalityTests(unittest.TestCase): v.imag = np.random.random(shape) h,a = r.hermitian_decomposition(v) # make sure that data == h + a + # NOTE: this is only correct for preserve_gaussian_variance==False, + # but I consider this an intrinsic property of a hermitian decomposition. + assert_almost_equal(v,h+a) + # test hermitianity of h + it = np.nditer (h, flags=['multi_index']) + while not it.finished: + i1 = it.multi_index + i2 = [] + for i in range(len(i1)): + i2.append(h.shape[i]-i1[i] if i1[i]>0 else 0) + i2 = tuple(i2) + assert_almost_equal(h[i1],np.conj(h[i2])) + assert_almost_equal(a[i1],-np.conj(a[i2])) + it.iternext() + @expand(product([(10,),(11,),(1,1),(4,4),(5,7),(8,12),(7,16),(4,6,8), + (17,5,3)],)) + def test_hermitian_decomposition2(self, shape): + r = RGSpace(shape, harmonic=True) + v = np.random.random(shape) + h,a = r.hermitian_decomposition(v) + # make sure that data == h + a assert_almost_equal(v,h+a) # test hermitianity of h it = np.nditer (h, flags=['multi_index'])