Commit afebb9af authored by Martin Reinecke's avatar Martin Reinecke

cosmetics

parent f960e433
Pipeline #21477 passed with stage
in 4 minutes and 22 seconds
import unittest
from numpy.testing import assert_allclose
from nifty2go import Field, DiagonalOperator, ComposedOperator
import nifty2go as ift
from test.common import generate_spaces
from itertools import product
from test.common import expand
from nifty2go.dobj import to_global_data as to_np
class ComposedOperator_Tests(unittest.TestCase):
......@@ -13,15 +12,15 @@ class ComposedOperator_Tests(unittest.TestCase):
@expand(product(spaces, spaces))
def test_times_adjoint_times(self, space1, space2):
cspace = (space1, space2)
diag1 = Field.from_random('normal', domain=space1)
diag2 = Field.from_random('normal', domain=space2)
op1 = DiagonalOperator(diag1, cspace, spaces=(0,))
op2 = DiagonalOperator(diag2, cspace, spaces=(1,))
diag1 = ift.Field.from_random('normal', domain=space1)
diag2 = ift.Field.from_random('normal', domain=space2)
op1 = ift.DiagonalOperator(diag1, cspace, spaces=(0,))
op2 = ift.DiagonalOperator(diag2, cspace, spaces=(1,))
op = ComposedOperator((op1, op2))
op = ift.ComposedOperator((op1, op2))
rand1 = Field.from_random('normal', domain=(space1, space2))
rand2 = Field.from_random('normal', domain=(space1, space2))
rand1 = ift.Field.from_random('normal', domain=(space1, space2))
rand2 = ift.Field.from_random('normal', domain=(space1, space2))
tt1 = rand2.vdot(op.times(rand1))
tt2 = rand1.vdot(op.adjoint_times(rand2))
......@@ -30,14 +29,15 @@ class ComposedOperator_Tests(unittest.TestCase):
@expand(product(spaces, spaces))
def test_times_inverse_times(self, space1, space2):
cspace = (space1, space2)
diag1 = Field.from_random('normal', domain=space1)
diag2 = Field.from_random('normal', domain=space2)
op1 = DiagonalOperator(diag1, cspace, spaces=(0,))
op2 = DiagonalOperator(diag2, cspace, spaces=(1,))
diag1 = ift.Field.from_random('normal', domain=space1)
diag2 = ift.Field.from_random('normal', domain=space2)
op1 = ift.DiagonalOperator(diag1, cspace, spaces=(0,))
op2 = ift.DiagonalOperator(diag2, cspace, spaces=(1,))
op = ComposedOperator((op1, op2))
op = ift.ComposedOperator((op1, op2))
rand1 = Field.from_random('normal', domain=(space1, space2))
rand1 = ift.Field.from_random('normal', domain=(space1, space2))
tt1 = op.inverse_times(op.times(rand1))
assert_allclose(to_np(tt1.val), to_np(rand1.val))
assert_allclose(ift.dobj.to_global_data(tt1.val),
ift.dobj.to_global_data(rand1.val))
from __future__ import division
import unittest
from numpy.testing import assert_equal, assert_allclose
from nifty2go import Field, DiagonalOperator
import nifty2go as ift
from test.common import generate_spaces
from itertools import product
from test.common import expand
from nifty2go.dobj import to_global_data as to_np
class DiagonalOperator_Tests(unittest.TestCase):
......@@ -13,8 +12,8 @@ class DiagonalOperator_Tests(unittest.TestCase):
@expand(product(spaces))
def test_property(self, space):
diag = Field.from_random('normal', domain=space)
D = DiagonalOperator(diag)
diag = ift.Field.from_random('normal', domain=space)
D = ift.DiagonalOperator(diag)
if D.domain[0] != space:
raise TypeError
if D.unitary:
......@@ -24,57 +23,59 @@ class DiagonalOperator_Tests(unittest.TestCase):
@expand(product(spaces))
def test_times_adjoint(self, space):
rand1 = Field.from_random('normal', domain=space)
rand2 = Field.from_random('normal', domain=space)
diag = Field.from_random('normal', domain=space)
D = DiagonalOperator(diag)
rand1 = ift.Field.from_random('normal', domain=space)
rand2 = ift.Field.from_random('normal', domain=space)
diag = ift.Field.from_random('normal', domain=space)
D = ift.DiagonalOperator(diag)
tt1 = rand1.vdot(D.times(rand2))
tt2 = rand2.vdot(D.times(rand1))
assert_allclose(tt1, tt2)
@expand(product(spaces))
def test_times_inverse(self, space):
rand1 = Field.from_random('normal', domain=space)
diag = Field.from_random('normal', domain=space)
D = DiagonalOperator(diag)
rand1 = ift.Field.from_random('normal', domain=space)
diag = ift.Field.from_random('normal', domain=space)
D = ift.DiagonalOperator(diag)
tt1 = D.times(D.inverse_times(rand1))
assert_allclose(to_np(rand1.val), to_np(tt1.val))
assert_allclose(ift.dobj.to_global_data(rand1.val),
ift.dobj.to_global_data(tt1.val))
@expand(product(spaces))
def test_times(self, space):
rand1 = Field.from_random('normal', domain=space)
diag = Field.from_random('normal', domain=space)
D = DiagonalOperator(diag)
rand1 = ift.Field.from_random('normal', domain=space)
diag = ift.Field.from_random('normal', domain=space)
D = ift.DiagonalOperator(diag)
tt = D.times(rand1)
assert_equal(tt.domain[0], space)
@expand(product(spaces))
def test_adjoint_times(self, space):
rand1 = Field.from_random('normal', domain=space)
diag = Field.from_random('normal', domain=space)
D = DiagonalOperator(diag)
rand1 = ift.Field.from_random('normal', domain=space)
diag = ift.Field.from_random('normal', domain=space)
D = ift.DiagonalOperator(diag)
tt = D.adjoint_times(rand1)
assert_equal(tt.domain[0], space)
@expand(product(spaces))
def test_inverse_times(self, space):
rand1 = Field.from_random('normal', domain=space)
diag = Field.from_random('normal', domain=space)
D = DiagonalOperator(diag)
rand1 = ift.Field.from_random('normal', domain=space)
diag = ift.Field.from_random('normal', domain=space)
D = ift.DiagonalOperator(diag)
tt = D.inverse_times(rand1)
assert_equal(tt.domain[0], space)
@expand(product(spaces))
def test_adjoint_inverse_times(self, space):
rand1 = Field.from_random('normal', domain=space)
diag = Field.from_random('normal', domain=space)
D = DiagonalOperator(diag)
rand1 = ift.Field.from_random('normal', domain=space)
diag = ift.Field.from_random('normal', domain=space)
D = ift.DiagonalOperator(diag)
tt = D.adjoint_inverse_times(rand1)
assert_equal(tt.domain[0], space)
@expand(product(spaces))
def test_diagonal(self, space):
diag = Field.from_random('normal', domain=space)
D = DiagonalOperator(diag)
diag = ift.Field.from_random('normal', domain=space)
D = ift.DiagonalOperator(diag)
diag_op = D.diagonal()
assert_allclose(to_np(diag.val), to_np(diag_op.val))
assert_allclose(ift.dobj.to_global_data(diag.val),
ift.dobj.to_global_data(diag_op.val))
......@@ -20,10 +20,9 @@ from __future__ import division
import unittest
import numpy as np
from numpy.testing import assert_allclose
from nifty2go import Field, RGSpace, LMSpace, HPSpace, GLSpace, FFTOperator
import nifty2go as ift
from itertools import product
from test.common import expand
from nifty2go import dobj
def _get_rtol(tp):
......@@ -38,75 +37,81 @@ class FFTOperatorTests(unittest.TestCase):
[np.float64, np.float32, np.complex64, np.complex128]))
def test_fft1D(self, dim1, d, itp):
tol = _get_rtol(itp)
a = RGSpace(dim1, distances=d)
b = RGSpace(dim1, distances=1./(dim1*d), harmonic=True)
fft = FFTOperator(domain=a, target=b)
a = ift.RGSpace(dim1, distances=d)
b = ift.RGSpace(dim1, distances=1./(dim1*d), harmonic=True)
fft = ift.FFTOperator(domain=a, target=b)
np.random.seed(16)
inp = Field.from_random(domain=a, random_type='normal', std=7, mean=3,
dtype=itp)
inp = ift.Field.from_random(domain=a, random_type='normal',
std=7, mean=3, dtype=itp)
out = fft.adjoint_times(fft.times(inp))
assert_allclose(dobj.to_global_data(inp.val), dobj.to_global_data(out.val), rtol=tol, atol=tol)
assert_allclose(ift.dobj.to_global_data(inp.val),
ift.dobj.to_global_data(out.val), rtol=tol, atol=tol)
@expand(product([12, 15], [9, 12], [0.1, 1, 3.7],
[0.4, 1, 2.7],
[np.float64, np.float32, np.complex64, np.complex128]))
def test_fft2D(self, dim1, dim2, d1, d2, itp):
tol = _get_rtol(itp)
a = RGSpace([dim1, dim2], distances=[d1, d2])
b = RGSpace([dim1, dim2],
distances=[1./(dim1*d1), 1./(dim2*d2)], harmonic=True)
fft = FFTOperator(domain=a, target=b)
a = ift.RGSpace([dim1, dim2], distances=[d1, d2])
b = ift.RGSpace([dim1, dim2],
distances=[1./(dim1*d1), 1./(dim2*d2)], harmonic=True)
fft = ift.FFTOperator(domain=a, target=b)
inp = Field.from_random(domain=a, random_type='normal', std=7, mean=3,
dtype=itp)
inp = ift.Field.from_random(domain=a, random_type='normal',
std=7, mean=3, dtype=itp)
out = fft.adjoint_times(fft.times(inp))
assert_allclose(dobj.to_global_data(inp.val), dobj.to_global_data(out.val), rtol=tol, atol=tol)
assert_allclose(ift.dobj.to_global_data(inp.val),
ift.dobj.to_global_data(out.val), rtol=tol, atol=tol)
@expand(product([0, 1, 2],
[np.float64, np.float32, np.complex64, np.complex128]))
def test_composed_fft(self, index, dtype):
tol = _get_rtol(dtype)
a = [a1, a2, a3] = [RGSpace((32,)), RGSpace((4, 4)), RGSpace((5, 6))]
fft = FFTOperator(domain=a, space=index)
a = [a1, a2, a3] = [ift.RGSpace((32,)), ift.RGSpace((4, 4)),
ift.RGSpace((5, 6))]
fft = ift.FFTOperator(domain=a, space=index)
inp = Field.from_random(domain=(a1, a2, a3), random_type='normal',
std=7, mean=3, dtype=dtype)
inp = ift.Field.from_random(domain=(a1, a2, a3), random_type='normal',
std=7, mean=3, dtype=dtype)
out = fft.adjoint_times(fft.times(inp))
assert_allclose(dobj.to_global_data(inp.val), dobj.to_global_data(out.val), rtol=tol, atol=tol)
assert_allclose(ift.dobj.to_global_data(inp.val),
ift.dobj.to_global_data(out.val), rtol=tol, atol=tol)
@expand(product([0, 3, 6, 11, 30],
[np.float64, np.float32, np.complex64, np.complex128]))
def test_sht(self, lm, tp):
tol = _get_rtol(tp)
a = LMSpace(lmax=lm)
b = GLSpace(nlat=lm+1)
fft = FFTOperator(domain=a, target=b)
inp = Field.from_random(domain=a, random_type='normal', std=7, mean=3,
dtype=tp)
a = ift.LMSpace(lmax=lm)
b = ift.GLSpace(nlat=lm+1)
fft = ift.FFTOperator(domain=a, target=b)
inp = ift.Field.from_random(domain=a, random_type='normal',
std=7, mean=3, dtype=tp)
out = fft.adjoint_times(fft.times(inp))
assert_allclose(dobj.to_global_data(inp.val), dobj.to_global_data(out.val), rtol=tol, atol=tol)
assert_allclose(ift.dobj.to_global_data(inp.val),
ift.dobj.to_global_data(out.val), rtol=tol, atol=tol)
@expand(product([128, 256],
[np.float64, np.float32, np.complex64, np.complex128]))
def test_sht2(self, lm, tp):
a = LMSpace(lmax=lm)
b = HPSpace(nside=lm//2)
fft = FFTOperator(domain=a, target=b)
inp = Field.from_random(domain=a, random_type='normal', std=1, mean=0,
dtype=tp)
a = ift.LMSpace(lmax=lm)
b = ift.HPSpace(nside=lm//2)
fft = ift.FFTOperator(domain=a, target=b)
inp = ift.Field.from_random(domain=a, random_type='normal',
std=1, mean=0, dtype=tp)
out = fft.adjoint_times(fft.times(inp))
assert_allclose(dobj.to_global_data(inp.val), dobj.to_global_data(out.val), rtol=1e-3, atol=1e-1)
assert_allclose(ift.dobj.to_global_data(inp.val),
ift.dobj.to_global_data(out.val), rtol=1e-3, atol=1e-1)
@expand(product([128, 256],
[np.float64, np.float32, np.complex64, np.complex128]))
def test_dotsht(self, lm, tp):
tol = _get_rtol(tp)
a = LMSpace(lmax=lm)
b = GLSpace(nlat=lm+1)
fft = FFTOperator(domain=a, target=b)
inp = Field.from_random(domain=a, random_type='normal', std=1, mean=0,
dtype=tp)
a = ift.LMSpace(lmax=lm)
b = ift.GLSpace(nlat=lm+1)
fft = ift.FFTOperator(domain=a, target=b)
inp = ift.Field.from_random(domain=a, random_type='normal',
std=1, mean=0, dtype=tp)
out = fft.times(inp)
v1 = np.sqrt(out.vdot(out))
v2 = np.sqrt(inp.vdot(fft.adjoint_times(out)))
......@@ -116,11 +121,11 @@ class FFTOperatorTests(unittest.TestCase):
[np.float64, np.float32, np.complex64, np.complex128]))
def test_dotsht2(self, lm, tp):
tol = _get_rtol(tp)
a = LMSpace(lmax=lm)
b = HPSpace(nside=lm//2)
fft = FFTOperator(domain=a, target=b)
inp = Field.from_random(domain=a, random_type='normal', std=1, mean=0,
dtype=tp)
a = ift.LMSpace(lmax=lm)
b = ift.HPSpace(nside=lm//2)
fft = ift.FFTOperator(domain=a, target=b)
inp = ift.Field.from_random(domain=a, random_type='normal',
std=1, mean=0, dtype=tp)
out = fft.times(inp)
v1 = np.sqrt(out.vdot(out))
v2 = np.sqrt(inp.vdot(fft.adjoint_times(out)))
......
......@@ -23,7 +23,6 @@ from numpy.testing import assert_, assert_equal, assert_raises,\
assert_allclose
import nifty2go as ift
from test.common import expand
from nifty2go import dobj
# [lmax, expected]
CONSTRUCTOR_CONFIGS = [
......@@ -93,4 +92,5 @@ class LMSpaceFunctionalityTests(unittest.TestCase):
@expand(get_k_length_array_configs())
def test_k_length_array(self, lmax, expected):
l = ift.LMSpace(lmax)
assert_allclose(dobj.to_global_data(l.get_k_length_array().val), expected)
assert_allclose(ift.dobj.to_global_data(l.get_k_length_array().val),
expected)
......@@ -24,7 +24,6 @@ from numpy.testing import assert_, assert_equal, assert_allclose,\
import nifty2go as ift
from test.common import expand
from itertools import product, chain
from nifty2go import dobj
HARMONIC_SPACES = [ift.RGSpace((8,), harmonic=True),
ift.RGSpace((7, 8), harmonic=True),
......@@ -53,7 +52,8 @@ CONSTRUCTOR_CONFIGS = [
'dim': 5,
'harmonic_partner': ift.RGSpace((8,), harmonic=True),
'binbounds': None,
'pindex': dobj.from_global_data(np.array([0, 1, 2, 3, 4, 3, 2, 1])),
'pindex': ift.dobj.from_global_data(
np.array([0, 1, 2, 3, 4, 3, 2, 1])),
'k_lengths': np.array([0., 1., 2., 3., 4.]),
}],
[ift.RGSpace((8,), harmonic=True), True, None, None, {
......@@ -62,7 +62,8 @@ CONSTRUCTOR_CONFIGS = [
'dim': 4,
'harmonic_partner': ift.RGSpace((8,), harmonic=True),
'binbounds': (0.5, 1.3228756555322954, 3.5),
'pindex': dobj.from_global_data(np.array([0, 1, 2, 2, 3, 2, 2, 1])),
'pindex': ift.dobj.from_global_data(
np.array([0, 1, 2, 2, 3, 2, 2, 1])),
'k_lengths': np.array([0., 1., 2.5, 4.]),
}],
]
......@@ -96,8 +97,8 @@ class PowerSpaceConsistencyCheck(unittest.TestCase):
nbin)
p = ift.PowerSpace(harmonic_partner=harmonic_partner, binbounds=bb)
assert_equal(np.bincount(dobj.to_global_data(p.pindex).ravel()), p.dvol(),
err_msg='rho is not equal to pindex degeneracy')
assert_equal(np.bincount(ift.dobj.to_global_data(p.pindex).ravel()),
p.dvol(), err_msg='rho is not equal to pindex degeneracy')
class PowerSpaceFunctionalityTest(unittest.TestCase):
......
......@@ -22,7 +22,6 @@ import numpy as np
from numpy.testing import assert_, assert_equal, assert_allclose
import nifty2go as ift
from test.common import expand
from nifty2go import dobj
# [shape, distances, harmonic, expected]
CONSTRUCTOR_CONFIGS = [
......@@ -111,7 +110,8 @@ class RGSpaceFunctionalityTests(unittest.TestCase):
@expand(get_k_length_array_configs())
def test_k_length_array(self, shape, distances, expected):
r = ift.RGSpace(shape=shape, distances=distances, harmonic=True)
assert_allclose(dobj.to_global_data(r.get_k_length_array().val), expected)
assert_allclose(ift.dobj.to_global_data(r.get_k_length_array().val),
expected)
@expand(get_dvol_configs())
def test_dvol(self, shape, distances, harmonic, power):
......
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