Commit 7af67c94 authored by Martin Reinecke's avatar Martin Reinecke
Browse files

current state of tests

parent 2521c9e2
Pipeline #14351 failed with stage
in 5 minutes and 9 seconds
......@@ -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
......
......@@ -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):
#
......
......@@ -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'])
......
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