Commit af46206a authored by Martin Reinecke's avatar Martin Reinecke
Browse files

domain -> target, round 1

parent d19a916d
Pipeline #72562 failed with stages
in 44 seconds
......@@ -268,11 +268,11 @@ def _plot1D(f, ax, **kwargs):
if not isinstance(fld, Field):
raise TypeError("incorrect data type")
if i == 0:
dom = fld.domain
dom = fld.target
if (len(dom) != 1):
raise ValueError("input field must have exactly one domain")
else:
if fld.domain != dom:
if fld.target != dom:
raise ValueError("domain mismatch")
dom = dom[0]
......@@ -324,7 +324,7 @@ def _plot1D(f, ax, **kwargs):
def _plot2D(f, ax, **kwargs):
import matplotlib.pyplot as plt
dom = f.domain
dom = f.target
if len(dom) > 2:
raise ValueError("DomainTuple can have at most two entries.")
......@@ -336,7 +336,7 @@ def _plot2D(f, ax, **kwargs):
raise TypeError("need 1D RGSpace as second domain")
if dom[1].shape[0] == 1:
from .sugar import makeField
f = makeField(f.domain[0], f.val[..., 0])
f = makeField(f.target[0], f.val[..., 0])
else:
rgb = _rgb_data(f.val)
have_rgb = True
......@@ -416,7 +416,7 @@ def _plot(f, ax, **kwargs):
raise ValueError("need something to plot")
if not isinstance(f[0], Field):
raise TypeError("incorrect data type")
dom1 = f[0].domain
dom1 = f[0].target
if (len(dom1) == 1 and
(isinstance(dom1[0], PowerSpace) or
(isinstance(dom1[0], RGSpace) and
......@@ -470,7 +470,7 @@ class Plot(object):
"""
from .multi_field import MultiField
if isinstance(f, MultiField):
for kk in f.domain.keys():
for kk in f.target.keys():
self._plots.append(f[kk])
mykwargs = kwargs.copy()
if 'title' in kwargs:
......
......@@ -95,8 +95,8 @@ def get_signal_variance(spec, space):
def _single_power_analyze(field, idx, binbounds):
power_domain = PowerSpace(field.domain[idx], binbounds)
pd = PowerDistributor(field.domain, power_domain, idx)
power_domain = PowerSpace(field.target[idx], binbounds)
pd = PowerDistributor(field.target, power_domain, idx)
return pd.adjoint_times(field.weight(1)).weight(-1) # divides by bin size
......@@ -142,12 +142,12 @@ def power_analyze(field, spaces=None, binbounds=None,
the power spectrum of `field`.
"""
for sp in field.domain:
for sp in field.target:
if not sp.harmonic and not isinstance(sp, PowerSpace):
logger.warning("WARNING: Field has a space in `domain` which is "
"neither harmonic nor a PowerSpace.")
spaces = utilities.parse_spaces(spaces, len(field.domain))
spaces = utilities.parse_spaces(spaces, len(field.target))
if len(spaces) == 0:
raise ValueError("No space for analysis specified.")
......@@ -175,11 +175,11 @@ def _create_power_field(domain, power_spectrum):
if not callable(power_spectrum): # we have a Field defined on a PowerSpace
if not isinstance(power_spectrum, Field):
raise TypeError("Field object expected")
if len(power_spectrum.domain) != 1:
if len(power_spectrum.target) != 1:
raise ValueError("exactly one domain required")
if not isinstance(power_spectrum.domain[0], PowerSpace):
if not isinstance(power_spectrum.target[0], PowerSpace):
raise TypeError("PowerSpace required")
power_domain = power_spectrum.domain[0]
power_domain = power_spectrum.target[0]
fp = power_spectrum
else:
power_domain = PowerSpace(domain)
......@@ -347,15 +347,15 @@ def makeOp(input, dom=None):
raise TypeError("need proper `dom` argument")
return SalingOperator(dom, input)
if dom is not None:
if not dom == input.domain:
if not dom == input.target:
raise ValueError("domain mismatch")
if input.domain is DomainTuple.scalar_domain():
return ScalingOperator(input.domain, float(input.val))
if input.target is DomainTuple.scalar_domain():
return ScalingOperator(input.target, float(input.val))
if isinstance(input, Field):
return DiagonalOperator(input)
if isinstance(input, MultiField):
return BlockDiagonalOperator(
input.domain, {key: makeOp(val) for key, val in input.items()})
input.target, {key: makeOp(val) for key, val in input.items()})
raise NotImplementedError
......@@ -491,10 +491,10 @@ def calculate_position(operator, output):
from .operators.energy_operators import GaussianEnergy, StandardHamiltonian
if not isinstance(operator, Operator):
raise TypeError
if output.domain != operator.target:
if output.target != operator.target:
raise TypeError
cov = 1e-3*output.val.max()**2
invcov = ScalingOperator(output.domain, cov).inverse
invcov = ScalingOperator(output.target, cov).inverse
d = output + invcov.draw_sample(from_inverse=True)
lh = GaussianEnergy(d, invcov) @ operator
H = StandardHamiltonian(
......
......@@ -44,12 +44,12 @@ def field(request):
def test_gaussian(field):
energy = ift.GaussianEnergy(domain=field.domain)
energy = ift.GaussianEnergy(domain=field.target)
ift.extra.check_jacobian_consistency(energy, field)
def test_ScaledEnergy(field):
icov = ift.ScalingOperator(field.domain, 1.2)
icov = ift.ScalingOperator(field.target, 1.2)
energy = ift.GaussianEnergy(inverse_covariance=icov)
ift.extra.check_jacobian_consistency(energy.scale(0.3), field)
......@@ -63,22 +63,22 @@ def test_ScaledEnergy(field):
def test_QuadraticFormOperator(field):
op = ift.ScalingOperator(field.domain, 1.2)
op = ift.ScalingOperator(field.target, 1.2)
endo = ift.makeOp(op.draw_sample())
energy = ift.QuadraticFormOperator(endo)
ift.extra.check_jacobian_consistency(energy, field)
def test_studentt(field):
if isinstance(field.domain, ift.MultiDomain):
if isinstance(field.target, ift.MultiDomain):
return
energy = ift.StudentTEnergy(domain=field.domain, theta=.5)
energy = ift.StudentTEnergy(domain=field.target, theta=.5)
ift.extra.check_jacobian_consistency(energy, field, tol=1e-6)
def test_hamiltonian_and_KL(field):
field = field.ptw("exp")
space = field.domain
space = field.target
lh = ift.GaussianEnergy(domain=space)
hamiltonian = ift.StandardHamiltonian(lh)
ift.extra.check_jacobian_consistency(hamiltonian, field)
......@@ -89,20 +89,20 @@ def test_hamiltonian_and_KL(field):
def test_variablecovariancegaussian(field):
if isinstance(field.domain, ift.MultiDomain):
if isinstance(field.target, ift.MultiDomain):
return
dc = {'a': field, 'b': field.ptw("exp")}
mf = ift.MultiField.from_dict(dc)
energy = ift.VariableCovarianceGaussianEnergy(field.domain, 'a', 'b')
energy = ift.VariableCovarianceGaussianEnergy(field.target, 'a', 'b')
ift.extra.check_jacobian_consistency(energy, mf, tol=1e-6)
energy(ift.Linearization.make_var(mf, want_metric=True)).metric.draw_sample()
def test_inverse_gamma(field):
if isinstance(field.domain, ift.MultiDomain):
if isinstance(field.target, ift.MultiDomain):
return
field = field.ptw("exp")
space = field.domain
space = field.target
d = ift.random.current_rng().normal(10, size=space.shape)**2
d = ift.Field(space, d)
energy = ift.InverseGammaLikelihood(d)
......@@ -110,10 +110,10 @@ def test_inverse_gamma(field):
def testPoissonian(field):
if isinstance(field.domain, ift.MultiDomain):
if isinstance(field.target, ift.MultiDomain):
return
field = field.ptw("exp")
space = field.domain
space = field.target
d = ift.random.current_rng().poisson(120, size=space.shape)
d = ift.Field(space, d)
energy = ift.PoissonianEnergy(d)
......@@ -121,10 +121,10 @@ def testPoissonian(field):
def test_bernoulli(field):
if isinstance(field.domain, ift.MultiDomain):
if isinstance(field.target, ift.MultiDomain):
return
field = field.ptw("sigmoid")
space = field.domain
space = field.target
d = ift.random.current_rng().binomial(1, 0.1, size=space.shape)
d = ift.Field(space, d)
energy = ift.BernoulliEnergy(d)
......
......@@ -29,7 +29,7 @@ SPACE_COMBINATIONS = [(), SPACES[0], SPACES[1], SPACES]
@pmp('domain', SPACE_COMBINATIONS)
@pmp('attribute_desired_type',
[['domain', ift.DomainTuple], ['val', np.ndarray],
[['target', ift.DomainTuple], ['val', np.ndarray],
['shape', tuple], ['size', (np.int, np.int64)]])
def test_return_types(domain, attribute_desired_type):
attribute = attribute_desired_type[0]
......@@ -215,23 +215,23 @@ def test_weight():
f = ift.Field.full(s1, 10.)
f2 = f.weight(1)
assert_equal(f.weight(1).val, f2.val)
assert_equal(f.domain.total_volume(), 1)
assert_equal(f.domain.total_volume(0), 1)
assert_equal(f.domain.total_volume((0,)), 1)
assert_equal(f.target.total_volume(), 1)
assert_equal(f.target.total_volume(0), 1)
assert_equal(f.target.total_volume((0,)), 1)
assert_equal(f.total_volume(), 1)
assert_equal(f.total_volume(0), 1)
assert_equal(f.total_volume((0,)), 1)
assert_equal(f.domain.scalar_weight(), 0.1)
assert_equal(f.domain.scalar_weight(0), 0.1)
assert_equal(f.domain.scalar_weight((0,)), 0.1)
assert_equal(f.target.scalar_weight(), 0.1)
assert_equal(f.target.scalar_weight(0), 0.1)
assert_equal(f.target.scalar_weight((0,)), 0.1)
assert_equal(f.scalar_weight(), 0.1)
assert_equal(f.scalar_weight(0), 0.1)
assert_equal(f.scalar_weight((0,)), 0.1)
s1 = ift.GLSpace(10)
f = ift.Field.full(s1, 10.)
assert_equal(f.domain.scalar_weight(), None)
assert_equal(f.domain.scalar_weight(0), None)
assert_equal(f.domain.scalar_weight((0,)), None)
assert_equal(f.target.scalar_weight(), None)
assert_equal(f.target.scalar_weight(0), None)
assert_equal(f.target.scalar_weight((0,)), None)
@pmp('dom', [ift.RGSpace(10), ift.GLSpace(10)])
......@@ -290,15 +290,15 @@ def test_stdfunc():
assert_equal(f.val, 27)
assert_equal(f.shape, (200,))
assert_equal(f.dtype, np.int)
fx = ift.full(f.domain, 0)
fx = ift.full(f.target, 0)
assert_equal(f.dtype, fx.dtype)
assert_equal(f.shape, fx.shape)
assert_equal(fx.val, 0)
fx = ift.full(f.domain, 1)
fx = ift.full(f.target, 1)
assert_equal(f.dtype, fx.dtype)
assert_equal(f.shape, fx.shape)
assert_equal(fx.val, 1)
fx = ift.full(f.domain, 67.)
fx = ift.full(f.target, 67.)
assert_equal(f.shape, fx.shape)
assert_equal(fx.val, 67.)
f = ift.Field.from_random("normal", s)
......
......@@ -190,13 +190,13 @@ def test_gauss(minimizer):
@property
def gradient(self):
x = self.position.val[0]
return ift.Field.full(self.position.domain, 2*x*np.exp(-(x**2)))
return ift.Field.full(self.position.target, 2*x*np.exp(-(x**2)))
def apply_metric(self, x):
p = self.position.val[0]
v = (2 - 4*p*p)*np.exp(-p**2)
return ift.DiagonalOperator(
ift.Field.full(self.position.domain, v))(x)
ift.Field.full(self.position.target, v))(x)
try:
minimizer = eval(minimizer)
......@@ -227,20 +227,20 @@ def test_cosh(minimizer):
@property
def gradient(self):
x = self.position.val[0]
return ift.Field.full(self.position.domain, np.sinh(x))
return ift.Field.full(self.position.target, np.sinh(x))
@property
def metric(self):
x = self.position.val[0]
v = np.cosh(x)
return ift.DiagonalOperator(
ift.Field.full(self.position.domain, v))
ift.Field.full(self.position.target, v))
def apply_metric(self, x):
p = self.position.val[0]
v = np.cosh(p)
return ift.DiagonalOperator(
ift.Field.full(self.position.domain, v))(x)
ift.Field.full(self.position.target, v))(x)
try:
minimizer = eval(minimizer)
......
......@@ -60,7 +60,7 @@ def test_times(space):
diag = ift.Field.from_random('normal', domain=space)
D = ift.DiagonalOperator(diag)
tt = D.times(rand1)
assert_equal(tt.domain[0], space)
assert_equal(tt.target[0], space)
def test_adjoint_times(space):
......@@ -68,7 +68,7 @@ def test_adjoint_times(space):
diag = ift.Field.from_random('normal', domain=space)
D = ift.DiagonalOperator(diag)
tt = D.adjoint_times(rand1)
assert_equal(tt.domain[0], space)
assert_equal(tt.target[0], space)
def test_inverse_times(space):
......@@ -76,7 +76,7 @@ def test_inverse_times(space):
diag = ift.Field.from_random('normal', domain=space)
D = ift.DiagonalOperator(diag)
tt = D.inverse_times(rand1)
assert_equal(tt.domain[0], space)
assert_equal(tt.target[0], space)
def test_adjoint_inverse_times(space):
......@@ -84,7 +84,7 @@ def test_adjoint_inverse_times(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)
assert_equal(tt.target[0], space)
def test_diagonal(space):
......
......@@ -24,14 +24,14 @@ from ..common import setup_function, teardown_function
def test_simplification():
from nifty6.operators.operator import _ConstantOperator
f1 = ift.Field.full(ift.RGSpace(10), 2.)
op = ift.FFTOperator(f1.domain)
op = ift.FFTOperator(f1.target)
_, op2 = op.simplify_for_constant_input(f1)
assert_equal(isinstance(op2, _ConstantOperator), True)
assert_allclose(op(f1).val, op2(f1).val)
dom = {"a": ift.RGSpace(10)}
f1 = ift.full(dom, 2.)
op = ift.FFTOperator(f1.domain["a"]).ducktape("a")
op = ift.FFTOperator(f1.target["a"]).ducktape("a")
_, op2 = op.simplify_for_constant_input(f1)
assert_equal(isinstance(op2, _ConstantOperator), True)
assert_allclose(op(f1).val, op2(f1).val)
......@@ -40,8 +40,8 @@ def test_simplification():
f1 = ift.full(dom, 2.)
pdom = {"a": ift.RGSpace(10)}
f2 = ift.full(pdom, 2.)
o1 = ift.FFTOperator(f1.domain["a"])
o2 = ift.FFTOperator(f1.domain["b"])
o1 = ift.FFTOperator(f1.target["a"])
o2 = ift.FFTOperator(f1.target["b"])
op = (o1.ducktape("a").ducktape_left("a") +
o2.ducktape("b").ducktape_left("b"))
_, op2 = op.simplify_for_constant_input(f2)
......
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