Commit 32119550 authored by Rouven Lemmerz's avatar Rouven Lemmerz

change from_random argument order and default to 'normal'

parent 895884f3
Pipeline #75211 passed with stages
in 8 minutes and 22 seconds
...@@ -43,7 +43,7 @@ if __name__ == '__main__': ...@@ -43,7 +43,7 @@ if __name__ == '__main__':
harmonic_space = position_space.get_default_codomain() harmonic_space = position_space.get_default_codomain()
HT = ift.HarmonicTransformOperator(harmonic_space, position_space) HT = ift.HarmonicTransformOperator(harmonic_space, position_space)
position = ift.from_random('normal', harmonic_space) position = ift.from_random(harmonic_space, 'normal')
# Define power spectrum and amplitudes # Define power spectrum and amplitudes
def sqrtpspec(k): def sqrtpspec(k):
...@@ -58,13 +58,13 @@ if __name__ == '__main__': ...@@ -58,13 +58,13 @@ if __name__ == '__main__':
# Generate mock data # Generate mock data
p = R(sky) p = R(sky)
mock_position = ift.from_random('normal', harmonic_space) mock_position = ift.from_random(harmonic_space, 'normal')
tmp = p(mock_position).val.astype(np.float64) tmp = p(mock_position).val.astype(np.float64)
data = ift.random.current_rng().binomial(1, tmp) data = ift.random.current_rng().binomial(1, tmp)
data = ift.Field.from_raw(R.target, data) data = ift.Field.from_raw(R.target, data)
# Compute likelihood and Hamiltonian # Compute likelihood and Hamiltonian
position = ift.from_random('normal', harmonic_space) position = ift.from_random(harmonic_space, 'normal')
likelihood = ift.BernoulliEnergy(data) @ p likelihood = ift.BernoulliEnergy(data) @ p
ic_newton = ift.DeltaEnergyController( ic_newton = ift.DeltaEnergyController(
name='Newton', iteration_limit=100, tol_rel_deltaE=1e-8) name='Newton', iteration_limit=100, tol_rel_deltaE=1e-8)
......
...@@ -40,7 +40,7 @@ def make_checkerboard_mask(position_space): ...@@ -40,7 +40,7 @@ def make_checkerboard_mask(position_space):
def make_random_mask(): def make_random_mask():
# Random mask for spherical mode # Random mask for spherical mode
mask = ift.from_random('pm1', position_space) mask = ift.from_random(position_space, 'pm1')
mask = (mask + 1)/2 mask = (mask + 1)/2
return mask.val return mask.val
......
...@@ -90,7 +90,7 @@ if __name__ == '__main__': ...@@ -90,7 +90,7 @@ if __name__ == '__main__':
# Generate mock data and define likelihood operator # Generate mock data and define likelihood operator
d_space = R.target[0] d_space = R.target[0]
lamb = R(sky) lamb = R(sky)
mock_position = ift.from_random('normal', domain) mock_position = ift.from_random(domain, 'normal')
data = lamb(mock_position) data = lamb(mock_position)
data = ift.random.current_rng().poisson(data.val.astype(np.float64)) data = ift.random.current_rng().poisson(data.val.astype(np.float64))
data = ift.Field.from_raw(d_space, data) data = ift.Field.from_raw(d_space, data)
...@@ -103,7 +103,7 @@ if __name__ == '__main__': ...@@ -103,7 +103,7 @@ if __name__ == '__main__':
# Compute MAP solution by minimizing the information Hamiltonian # Compute MAP solution by minimizing the information Hamiltonian
H = ift.StandardHamiltonian(likelihood) H = ift.StandardHamiltonian(likelihood)
initial_position = ift.from_random('normal', domain) initial_position = ift.from_random(domain, 'normal')
H = ift.EnergyAdapter(initial_position, H, want_metric=True) H = ift.EnergyAdapter(initial_position, H, want_metric=True)
H, convergence = minimizer(H) H, convergence = minimizer(H)
......
...@@ -98,7 +98,7 @@ if __name__ == '__main__': ...@@ -98,7 +98,7 @@ if __name__ == '__main__':
N = ift.ScalingOperator(data_space, noise) N = ift.ScalingOperator(data_space, noise)
# Generate mock signal and data # Generate mock signal and data
mock_position = ift.from_random('normal', signal_response.domain) mock_position = ift.from_random(signal_response.domain, 'normal')
data = signal_response(mock_position) + N.draw_sample_with_dtype(dtype=np.float64) data = signal_response(mock_position) + N.draw_sample_with_dtype(dtype=np.float64)
# Minimization parameters # Minimization parameters
......
...@@ -97,7 +97,7 @@ if __name__ == '__main__': ...@@ -97,7 +97,7 @@ if __name__ == '__main__':
N = ift.ScalingOperator(data_space, noise) N = ift.ScalingOperator(data_space, noise)
# Generate mock signal and data # Generate mock signal and data
mock_position = ift.from_random('normal', signal_response.domain) mock_position = ift.from_random(signal_response.domain, 'normal')
data = signal_response(mock_position) + N.draw_sample_with_dtype(dtype=np.float64) data = signal_response(mock_position) + N.draw_sample_with_dtype(dtype=np.float64)
plot = ift.Plot() plot = ift.Plot()
......
...@@ -42,8 +42,8 @@ def _adjoint_implementation(op, domain_dtype, target_dtype, atol, rtol, ...@@ -42,8 +42,8 @@ def _adjoint_implementation(op, domain_dtype, target_dtype, atol, rtol,
needed_cap = op.TIMES | op.ADJOINT_TIMES needed_cap = op.TIMES | op.ADJOINT_TIMES
if (op.capability & needed_cap) != needed_cap: if (op.capability & needed_cap) != needed_cap:
return return
f1 = from_random("normal", op.domain, dtype=domain_dtype) f1 = from_random(op.domain, "normal", dtype=domain_dtype)
f2 = from_random("normal", op.target, dtype=target_dtype) f2 = from_random(op.target, "normal", dtype=target_dtype)
res1 = f1.s_vdot(op.adjoint_times(f2)) res1 = f1.s_vdot(op.adjoint_times(f2))
res2 = op.times(f1).s_vdot(f2) res2 = op.times(f1).s_vdot(f2)
if only_r_linear: if only_r_linear:
...@@ -55,11 +55,11 @@ def _inverse_implementation(op, domain_dtype, target_dtype, atol, rtol): ...@@ -55,11 +55,11 @@ def _inverse_implementation(op, domain_dtype, target_dtype, atol, rtol):
needed_cap = op.TIMES | op.INVERSE_TIMES needed_cap = op.TIMES | op.INVERSE_TIMES
if (op.capability & needed_cap) != needed_cap: if (op.capability & needed_cap) != needed_cap:
return return
foo = from_random("normal", op.target, dtype=target_dtype) foo = from_random(op.target, "normal", dtype=target_dtype)
res = op(op.inverse_times(foo)) res = op(op.inverse_times(foo))
assert_allclose(res, foo, atol=atol, rtol=rtol) assert_allclose(res, foo, atol=atol, rtol=rtol)
foo = from_random("normal", op.domain, dtype=domain_dtype) foo = from_random(op.domain, "normal", dtype=domain_dtype)
res = op.inverse_times(op(foo)) res = op.inverse_times(op(foo))
assert_allclose(res, foo, atol=atol, rtol=rtol) assert_allclose(res, foo, atol=atol, rtol=rtol)
...@@ -75,8 +75,8 @@ def _check_linearity(op, domain_dtype, atol, rtol): ...@@ -75,8 +75,8 @@ def _check_linearity(op, domain_dtype, atol, rtol):
needed_cap = op.TIMES needed_cap = op.TIMES
if (op.capability & needed_cap) != needed_cap: if (op.capability & needed_cap) != needed_cap:
return return
fld1 = from_random("normal", op.domain, dtype=domain_dtype) fld1 = from_random(op.domain, "normal", dtype=domain_dtype)
fld2 = from_random("normal", op.domain, dtype=domain_dtype) fld2 = from_random(op.domain, "normal", dtype=domain_dtype)
alpha = np.random.random() # FIXME: this can break badly with MPI! alpha = np.random.random() # FIXME: this can break badly with MPI!
val1 = op(alpha*fld1+fld2) val1 = op(alpha*fld1+fld2)
val2 = alpha*op(fld1)+op(fld2) val2 = alpha*op(fld1)+op(fld2)
...@@ -88,7 +88,7 @@ def _actual_domain_check_linear(op, domain_dtype=None, inp=None): ...@@ -88,7 +88,7 @@ def _actual_domain_check_linear(op, domain_dtype=None, inp=None):
if (op.capability & needed_cap) != needed_cap: if (op.capability & needed_cap) != needed_cap:
return return
if domain_dtype is not None: if domain_dtype is not None:
inp = from_random("normal", op.domain, dtype=domain_dtype) inp = from_random(op.domain, "normal", dtype=domain_dtype)
elif inp is None: elif inp is None:
raise ValueError('Need to specify either dtype or inp') raise ValueError('Need to specify either dtype or inp')
assert_(inp.domain is op.domain) assert_(inp.domain is op.domain)
...@@ -219,7 +219,7 @@ def consistency_check(op, domain_dtype=np.float64, target_dtype=np.float64, ...@@ -219,7 +219,7 @@ def consistency_check(op, domain_dtype=np.float64, target_dtype=np.float64,
def _get_acceptable_location(op, loc, lin): def _get_acceptable_location(op, loc, lin):
if not np.isfinite(lin.val.s_sum()): if not np.isfinite(lin.val.s_sum()):
raise ValueError('Initial value must be finite') raise ValueError('Initial value must be finite')
dir = from_random("normal", loc.domain) dir = from_random(loc.domain, "normal")
dirder = lin.jac(dir) dirder = lin.jac(dir)
if dirder.norm() == 0: if dirder.norm() == 0:
dir = dir * (lin.val.norm()*1e-5) dir = dir * (lin.val.norm()*1e-5)
......
...@@ -124,7 +124,7 @@ class Field(Operator): ...@@ -124,7 +124,7 @@ class Field(Operator):
return Field(DomainTuple.make(new_domain), self._val) return Field(DomainTuple.make(new_domain), self._val)
@staticmethod @staticmethod
def from_random(random_type, domain, dtype=np.float64, **kwargs): def from_random(domain, random_type='normal', dtype=np.float64, **kwargs):
"""Draws a random field with the given parameters. """Draws a random field with the given parameters.
Parameters Parameters
......
...@@ -524,7 +524,7 @@ class CorrelatedFieldMaker: ...@@ -524,7 +524,7 @@ class CorrelatedFieldMaker:
for kk, op in lst: for kk, op in lst:
sc = StatCalculator() sc = StatCalculator()
for _ in range(prior_info): for _ in range(prior_info):
sc.add(op(from_random('normal', op.domain))) sc.add(op(from_random(op.domain, 'normal')))
mean = sc.mean.val mean = sc.mean.val
stddev = sc.var.ptw("sqrt").val stddev = sc.var.ptw("sqrt").val
for m, s in zip(mean.flatten(), stddev.flatten()): for m, s in zip(mean.flatten(), stddev.flatten()):
...@@ -539,7 +539,7 @@ class CorrelatedFieldMaker: ...@@ -539,7 +539,7 @@ class CorrelatedFieldMaker:
scm = 1. scm = 1.
for a in self._a: for a in self._a:
op = a.fluctuation_amplitude*self._azm.ptw("reciprocal") op = a.fluctuation_amplitude*self._azm.ptw("reciprocal")
res = np.array([op(from_random('normal', op.domain)).val res = np.array([op(from_random(op.domain, 'normal')).val
for _ in range(nsamples)]) for _ in range(nsamples)])
scm *= res**2 + 1. scm *= res**2 + 1.
return fluctuations_slice_mean/np.mean(np.sqrt(scm)) return fluctuations_slice_mean/np.mean(np.sqrt(scm))
......
...@@ -101,7 +101,7 @@ class MultiField(Operator): ...@@ -101,7 +101,7 @@ class MultiField(Operator):
return self._transform(lambda x: x.imag) return self._transform(lambda x: x.imag)
@staticmethod @staticmethod
def from_random(random_type, domain, dtype=np.float64, **kwargs): def from_random(domain, random_type='normal', dtype=np.float64, **kwargs):
"""Draws a random multi-field with the given parameters. """Draws a random multi-field with the given parameters.
Parameters Parameters
...@@ -131,7 +131,7 @@ class MultiField(Operator): ...@@ -131,7 +131,7 @@ class MultiField(Operator):
else: else:
dtype = np.dtype(dtype) dtype = np.dtype(dtype)
dtype = {kk: dtype for kk in domain.keys()} dtype = {kk: dtype for kk in domain.keys()}
dct = {kk: Field.from_random(random_type, domain[kk], dtype[kk], **kwargs) dct = {kk: Field.from_random(domain[kk], random_type, dtype[kk], **kwargs)
for kk in domain.keys()} for kk in domain.keys()}
return MultiField.from_dict(dct) return MultiField.from_dict(dct)
......
...@@ -61,7 +61,7 @@ class BlockDiagonalOperator(EndomorphicOperator): ...@@ -61,7 +61,7 @@ class BlockDiagonalOperator(EndomorphicOperator):
val = tuple( val = tuple(
op.draw_sample_with_dtype(dtype[key], from_inverse) op.draw_sample_with_dtype(dtype[key], from_inverse)
if op is not None if op is not None
else from_random('normal', self._domain[key], dtype=dtype) else from_random(self._domain[key], 'normal', dtype=dtype)
for op, key in zip(self._ops, self._domain.keys())) for op, key in zip(self._ops, self._domain.keys()))
return MultiField(self._domain, val) return MultiField(self._domain, val)
......
...@@ -161,8 +161,7 @@ class DiagonalOperator(EndomorphicOperator): ...@@ -161,8 +161,7 @@ class DiagonalOperator(EndomorphicOperator):
return Field(self._domain, res) return Field(self._domain, res)
def draw_sample_with_dtype(self, dtype, from_inverse=False): def draw_sample_with_dtype(self, dtype, from_inverse=False):
res = Field.from_random(random_type="normal", domain=self._domain, res = Field.from_random(domain=self._domain, random_type="normal", dtype=dtype)
dtype=dtype)
return self.process_sample(res, from_inverse) return self.process_sample(res, from_inverse)
def __repr__(self): def __repr__(self):
......
...@@ -35,7 +35,7 @@ class DomainTupleFieldInserter(LinearOperator): ...@@ -35,7 +35,7 @@ class DomainTupleFieldInserter(LinearOperator):
Slice in new sub-domain in which the input field shall be written into. Slice in new sub-domain in which the input field shall be written into.
""" """
def __init__(self, target, space, pos): def __init__(self, target, space, index):
if not space <= len(target) or space < 0: if not space <= len(target) or space < 0:
raise ValueError raise ValueError
self._target = DomainTuple.make(target) self._target = DomainTuple.make(target)
...@@ -48,13 +48,13 @@ class DomainTupleFieldInserter(LinearOperator): ...@@ -48,13 +48,13 @@ class DomainTupleFieldInserter(LinearOperator):
nshp = new_space.shape nshp = new_space.shape
fst_dims = sum(len(dd.shape) for dd in self.target[:space]) fst_dims = sum(len(dd.shape) for dd in self.target[:space])
if len(pos) != len(nshp): if len(index) != len(nshp):
raise ValueError("shape mismatch between new_space and position") raise ValueError("shape mismatch between new_space and position")
for s, p in zip(nshp, pos): for s, p in zip(nshp, index):
if p < 0 or p >= s: if p < 0 or p >= s:
raise ValueError("bad position value") raise ValueError("bad position value")
self._slc = (slice(None),)*fst_dims + pos self._slc = (slice(None),)*fst_dims + index
def apply(self, x, mode): def apply(self, x, mode):
self._check_input(x, mode) self._check_input(x, mode)
......
...@@ -93,8 +93,7 @@ class ScalingOperator(EndomorphicOperator): ...@@ -93,8 +93,7 @@ class ScalingOperator(EndomorphicOperator):
def draw_sample_with_dtype(self, dtype, from_inverse=False): def draw_sample_with_dtype(self, dtype, from_inverse=False):
from ..sugar import from_random from ..sugar import from_random
return from_random(random_type="normal", domain=self._domain, return from_random(domain=self._domain, random_type="normal", dtype=dtype, std=self._get_fct(from_inverse))
std=self._get_fct(from_inverse), dtype=dtype)
def __call__(self, other): def __call__(self, other):
res = EndomorphicOperator.__call__(self, other) res = EndomorphicOperator.__call__(self, other)
......
...@@ -134,7 +134,7 @@ def probe_diagonal(op, nprobes, random_type="pm1"): ...@@ -134,7 +134,7 @@ def probe_diagonal(op, nprobes, random_type="pm1"):
''' '''
sc = StatCalculator() sc = StatCalculator()
for i in range(nprobes): for i in range(nprobes):
x = from_random(random_type, op.domain) x = from_random(op.domain, random_type)
sc.add(op(x).conjugate()*x) sc.add(op(x).conjugate()*x)
return sc.mean return sc.mean
......
...@@ -256,7 +256,7 @@ def full(domain, val): ...@@ -256,7 +256,7 @@ def full(domain, val):
return Field.full(domain, val) return Field.full(domain, val)
def from_random(random_type, domain, dtype=np.float64, **kwargs): def from_random(domain, random_type='normal', dtype=np.float64, **kwargs):
"""Convenience function creating Fields/MultiFields with random values. """Convenience function creating Fields/MultiFields with random values.
Parameters Parameters
...@@ -283,8 +283,8 @@ def from_random(random_type, domain, dtype=np.float64, **kwargs): ...@@ -283,8 +283,8 @@ def from_random(random_type, domain, dtype=np.float64, **kwargs):
random numbers, even for the same initial RNG state. random numbers, even for the same initial RNG state.
""" """
if isinstance(domain, (dict, MultiDomain)): if isinstance(domain, (dict, MultiDomain)):
return MultiField.from_random(random_type, domain, dtype, **kwargs) return MultiField.from_random(domain, random_type, dtype, **kwargs)
return Field.from_random(random_type, domain, dtype, **kwargs) return Field.from_random(domain, random_type, dtype, **kwargs)
def makeField(domain, arr): def makeField(domain, arr):
...@@ -466,7 +466,7 @@ def exec_time(obj, want_metric=True): ...@@ -466,7 +466,7 @@ def exec_time(obj, want_metric=True):
logger.info('Energy.metric(position): {}'.format(time() - t0)) logger.info('Energy.metric(position): {}'.format(time() - t0))
elif isinstance(obj, Operator): elif isinstance(obj, Operator):
want_metric = bool(want_metric) want_metric = bool(want_metric)
pos = from_random('normal', obj.domain) pos = from_random(obj.domain, 'normal')
t0 = time() t0 = time()
obj(pos) obj(pos)
logger.info('Operator call with field: {}'.format(time() - t0)) logger.info('Operator call with field: {}'.format(time() - t0))
...@@ -509,7 +509,7 @@ def calculate_position(operator, output): ...@@ -509,7 +509,7 @@ def calculate_position(operator, output):
lh = GaussianEnergy(d, invcov) @ operator lh = GaussianEnergy(d, invcov) @ operator
H = StandardHamiltonian( H = StandardHamiltonian(
lh, ic_samp=GradientNormController(iteration_limit=200)) lh, ic_samp=GradientNormController(iteration_limit=200))
pos = 0.1*from_random('normal', operator.domain) pos = 0.1 * from_random(operator.domain, 'normal')
minimizer = NewtonCG(GradientNormController(iteration_limit=10)) minimizer = NewtonCG(GradientNormController(iteration_limit=10))
for ii in range(3): for ii in range(3):
kl = MetricGaussianKL(pos, H, 3, mirror_samples=True) kl = MetricGaussianKL(pos, H, 3, mirror_samples=True)
......
...@@ -26,7 +26,7 @@ spaces = [ift.GLSpace(5), ...@@ -26,7 +26,7 @@ spaces = [ift.GLSpace(5),
ift.MultiDomain.make({'': ift.RGSpace(5, distances=.789)}), ift.MultiDomain.make({'': ift.RGSpace(5, distances=.789)}),
(ift.RGSpace(3, distances=.789), ift.UnstructuredDomain(2))] (ift.RGSpace(3, distances=.789), ift.UnstructuredDomain(2))]
pmp = pytest.mark.parametrize pmp = pytest.mark.parametrize
field = list2fixture([ift.from_random('normal', sp) for sp in spaces]) field = list2fixture([ift.from_random(sp, 'normal') for sp in spaces])
ntries = 10 ntries = 10
...@@ -62,7 +62,7 @@ def test_studentt(field): ...@@ -62,7 +62,7 @@ def test_studentt(field):
return return
energy = ift.StudentTEnergy(domain=field.domain, theta=.5) energy = ift.StudentTEnergy(domain=field.domain, theta=.5)
ift.extra.check_jacobian_consistency(energy, field, tol=1e-6) ift.extra.check_jacobian_consistency(energy, field, tol=1e-6)
theta = ift.from_random('normal',field.domain).exp() theta = ift.from_random(field.domain, 'normal').exp()
energy = ift.StudentTEnergy(domain=field.domain, theta=theta) energy = ift.StudentTEnergy(domain=field.domain, theta=theta)
ift.extra.check_jacobian_consistency(energy, field, tol=1e-6, ntries=ntries) ift.extra.check_jacobian_consistency(energy, field, tol=1e-6, ntries=ntries)
...@@ -73,7 +73,7 @@ def test_hamiltonian_and_KL(field): ...@@ -73,7 +73,7 @@ def test_hamiltonian_and_KL(field):
lh = ift.GaussianEnergy(domain=space) lh = ift.GaussianEnergy(domain=space)
hamiltonian = ift.StandardHamiltonian(lh) hamiltonian = ift.StandardHamiltonian(lh)
ift.extra.check_jacobian_consistency(hamiltonian, field, ntries=ntries) ift.extra.check_jacobian_consistency(hamiltonian, field, ntries=ntries)
samps = [ift.from_random('normal', space) for i in range(2)] samps = [ift.from_random(space, 'normal') for i in range(2)]
kl = ift.AveragedEnergy(hamiltonian, samps) kl = ift.AveragedEnergy(hamiltonian, samps)
ift.extra.check_jacobian_consistency(kl, field, ntries=ntries) ift.extra.check_jacobian_consistency(kl, field, ntries=ntries)
......
...@@ -104,7 +104,7 @@ def test_DiagonalOperator_power_analyze2(space1, space2): ...@@ -104,7 +104,7 @@ def test_DiagonalOperator_power_analyze2(space1, space2):
ift.RGSpace((2, 3, 7)) ift.RGSpace((2, 3, 7))
]) ])
def test_norm(space): def test_norm(space):
f = ift.Field.from_random("normal", domain=space, dtype=np.complex128) f = ift.Field.from_random(domain=space, random_type="normal", dtype=np.complex128)
gd = f.val.reshape(-1) gd = f.val.reshape(-1)
assert_allclose(f.norm(), np.linalg.norm(gd)) assert_allclose(f.norm(), np.linalg.norm(gd))
assert_allclose(f.norm(1), np.linalg.norm(gd, ord=1)) assert_allclose(f.norm(1), np.linalg.norm(gd, ord=1))
...@@ -115,8 +115,8 @@ def test_norm(space): ...@@ -115,8 +115,8 @@ def test_norm(space):
def test_vdot(): def test_vdot():
s = ift.RGSpace((10,)) s = ift.RGSpace((10,))
f1 = ift.Field.from_random("normal", domain=s, dtype=np.complex128) f1 = ift.Field.from_random(domain=s, random_type="normal", dtype=np.complex128)
f2 = ift.Field.from_random("normal", domain=s, dtype=np.complex128) f2 = ift.Field.from_random(domain=s, random_type="normal", dtype=np.complex128)
assert_allclose(f1.s_vdot(f2), f1.vdot(f2, spaces=0).val) assert_allclose(f1.s_vdot(f2), f1.vdot(f2, spaces=0).val)
assert_allclose(f1.s_vdot(f2), np.conj(f2.s_vdot(f1))) assert_allclose(f1.s_vdot(f2), np.conj(f2.s_vdot(f1)))
...@@ -297,8 +297,8 @@ def test_stdfunc(): ...@@ -297,8 +297,8 @@ def test_stdfunc():
fx = ift.full(f.domain, 67.) fx = ift.full(f.domain, 67.)
assert_equal(f.shape, fx.shape) assert_equal(f.shape, fx.shape)
assert_equal(fx.val, 67.) assert_equal(fx.val, 67.)
f = ift.Field.from_random("normal", s) f = ift.Field.from_random(s, "normal")
f2 = ift.Field.from_random("normal", s) f2 = ift.Field.from_random(s, "normal")
assert_equal((f > f2).val, f.val > f2.val) assert_equal((f > f2).val, f.val > f2.val)
assert_equal((f >= f2).val, f.val >= f2.val) assert_equal((f >= f2).val, f.val >= f2.val)
assert_equal((f < f2).val, f.val < f2.val) assert_equal((f < f2).val, f.val < f2.val)
...@@ -341,7 +341,7 @@ def test_funcs(num, dom, func): ...@@ -341,7 +341,7 @@ def test_funcs(num, dom, func):
@pmp('dtype', [np.float64, np.complex128]) @pmp('dtype', [np.float64, np.complex128])
def test_from_random(rtype, dtype): def test_from_random(rtype, dtype):
sp = ift.RGSpace(3) sp = ift.RGSpace(3)
ift.Field.from_random(rtype, sp, dtype=dtype) ift.Field.from_random(sp, rtype, dtype=dtype)
def test_field_of_objects(): def test_field_of_objects():
......
...@@ -38,7 +38,7 @@ def test_kl(constants, point_estimates, mirror_samples, mf): ...@@ -38,7 +38,7 @@ def test_kl(constants, point_estimates, mirror_samples, mf):
lh = ift.GaussianEnergy(domain=op.target, sampling_dtype=np.float64) @ op lh = ift.GaussianEnergy(domain=op.target, sampling_dtype=np.float64) @ op
ic = ift.GradientNormController(iteration_limit=5) ic = ift.GradientNormController(iteration_limit=5)
h = ift.StandardHamiltonian(lh, ic_samp=ic) h = ift.StandardHamiltonian(lh, ic_samp=ic)
mean0 = ift.from_random('normal', h.domain) mean0 = ift.from_random(h.domain, 'normal')
nsamps = 2 nsamps = 2
kl = ift.MetricGaussianKL(mean0, kl = ift.MetricGaussianKL(mean0,
......
...@@ -52,8 +52,8 @@ slow_minimizers = ['ift.SteepestDescent(IC)'] ...@@ -52,8 +52,8 @@ slow_minimizers = ['ift.SteepestDescent(IC)']
slow_minimizers) slow_minimizers)
@pmp('space', spaces) @pmp('space', spaces)
def test_quadratic_minimization(minimizer, space): def test_quadratic_minimization(minimizer, space):
starting_point = ift.Field.from_random('normal', domain=space)*10 starting_point = ift.Field.from_random(domain=space, random_type='normal') * 10
covariance_diagonal = ift.Field.from_random('uniform', domain=space) + 0.5 covariance_diagonal = ift.Field.from_random(domain=space, random_type='uniform') + 0.5
covariance = ift.DiagonalOperator(covariance_diagonal) covariance = ift.DiagonalOperator(covariance_diagonal)
required_result = ift.full(space, 1.) required_result = ift.full(space, 1.)
...@@ -78,11 +78,11 @@ def test_quadratic_minimization(minimizer, space): ...@@ -78,11 +78,11 @@ def test_quadratic_minimization(minimizer, space):
def test_WF_curvature(space): def test_WF_curvature(space):
required_result = ift.full(space, 1.) required_result = ift.full(space, 1.)
s = ift.Field.from_random('uniform', domain=space) + 0.5 s = ift.Field.from_random(domain=space, random_type='uniform') + 0.5
S = ift.DiagonalOperator(s) S = ift.DiagonalOperator(s)
r = ift.Field.from_random('uniform', domain=space) r = ift.Field.from_random(domain=space, random_type='uniform')
R = ift.DiagonalOperator(r) R = ift.DiagonalOperator(r)
n = ift.Field.from_random('uniform', domain=space) + 0.5 n = ift.Field.from_random(domain=space, random_type='uniform') + 0.5
N = ift.DiagonalOperator(n) N = ift.DiagonalOperator(n)
all_diag = 1./s + r**2/n all_diag = 1./s + r**2/n
curv = ift.WienerFilterCurvature(R, N, S, iteration_controller=IC, curv = ift.WienerFilterCurvature(R, N, S, iteration_controller=IC,
...@@ -100,7 +100,7 @@ def test_WF_curvature(space): ...@@ -100,7 +100,7 @@ def test_WF_curvature(space):
if len(space.shape) == 1: if len(space.shape) == 1:
R = ift.ValueInserter(space, [0]) R = ift.ValueInserter(space, [0])
n = ift.from_random('uniform', R.domain) + 0.5 n = ift.from_random(R.domain, 'uniform') + 0.5
N = ift.DiagonalOperator(n) N = ift.DiagonalOperator(n)
all_diag = 1./s + R(1/n) all_diag = 1./s + R(1/n)
curv = ift.WienerFilterCurvature(R.adjoint, N, S, curv = ift.WienerFilterCurvature(R.adjoint, N, S,
...@@ -125,7 +125,7 @@ def test_rosenbrock(minimizer): ...@@ -125,7 +125,7 @@ def test_rosenbrock(minimizer):
except ImportError: except ImportError:
raise SkipTest raise SkipTest
space = ift.DomainTuple.make(ift.UnstructuredDomain((2,)))