Commit 542fba82 authored by Martin Reinecke's avatar Martin Reinecke
Browse files

cosmetics and slightly better tests

parent 6d1b25f8
......@@ -559,8 +559,7 @@ def absmax(arr):
if arr._data.size == 0:
tmp = np.array(0, dtype=arr._data.dtype)
else:
tmp = np.asarray(np.linalg.norm(np.atleast_1d(arr._data).reshape(-1),
ord=np.inf))
tmp = np.asarray(np.linalg.norm(arr._data.reshape(-1), ord=np.inf))
res = np.empty_like(tmp)
_comm.Allreduce(tmp, res, MPI.MAX)
return res[()]
......@@ -569,8 +568,7 @@ def absmax(arr):
def norm(arr, ord=2):
if ord == np.inf:
return absmax(arr)
tmp = np.asarray(np.linalg.norm(np.atleast_1d(arr._data).reshape(-1),
ord=ord) ** ord)
tmp = np.asarray(np.linalg.norm(arr._data.reshape(-1), ord=ord) ** ord)
res = np.empty_like(tmp)
_comm.Allreduce(tmp, res, MPI.SUM)
return res[()] ** (1./ord)
......@@ -144,8 +144,8 @@ def ensure_default_distributed(arr):
def absmax(arr):
return np.linalg.norm(np.atleast_1d(arr).rehape(-1), ord=np.inf)
return np.linalg.norm(arr.rehape(-1), ord=np.inf)
def norm(arr, ord=2):
return np.linalg.norm(np.atleast_1d(arr).reshape(-1), ord=ord)
return np.linalg.norm(arr.reshape(-1), ord=ord)
......@@ -23,7 +23,8 @@ from ..operators.energy_operators import Hamiltonian, InverseGammaLikelihood
from ..operators.scaling_operator import ScalingOperator
def make_adjust_variances(a, xi, position, samples=[], scaling=None, ic_samp=None):
def make_adjust_variances(a, xi, position, samples=[], scaling=None,
ic_samp=None):
""" Creates a Hamiltonian for constant likelihood optimizations.
Constructs a Hamiltonian to solve constant likelihood optimizations of the
......
......@@ -69,7 +69,6 @@ class Energy_Tests(unittest.TestCase):
energy = ift.InverseGammaLikelihood(ift.exp, d)
ift.extra.check_value_gradient_consistency(energy, model, tol=1e-7)
@expand(product(
[ift.GLSpace(15),
ift.RGSpace(64, distances=.789),
......
......@@ -110,10 +110,12 @@ class Test_Functionality(unittest.TestCase):
assert_allclose(sc1.mean.local_data, fp1.local_data, rtol=0.2)
assert_allclose(sc2.mean.local_data, fp2.local_data, rtol=0.2)
def test_norm(self):
s = ift.RGSpace((10,))
f = ift.Field.from_random("normal", domain=s, dtype=np.complex128)
gd = f.to_global_data()
@expand(product([ift.RGSpace((8,), harmonic=True), (),
ift.RGSpace((8, 8), harmonic=True, distances=0.123),
ift.RGSpace((2, 3, 7))]))
def test_norm(self, space):
f = ift.Field.from_random("normal", domain=space, dtype=np.complex128)
gd = f.to_global_data().reshape(-1)
assert_allclose(f.norm(), np.linalg.norm(gd))
assert_allclose(f.norm(1), np.linalg.norm(gd, ord=1))
assert_allclose(f.norm(2), np.linalg.norm(gd, ord=2))
......
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