From 5dbc6d903c401b542c66a11e3fc0121d51f4e378 Mon Sep 17 00:00:00 2001 From: Philipp Arras Date: Wed, 27 Jun 2018 23:10:43 +0200 Subject: [PATCH] Cosmetics --- nifty5/extra/energy_and_model_tests.py | 8 ++++---- test/test_models/test_model_gradients.py | 11 +++++------ 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/nifty5/extra/energy_and_model_tests.py b/nifty5/extra/energy_and_model_tests.py index 34f40b84..824269be 100644 --- a/nifty5/extra/energy_and_model_tests.py +++ b/nifty5/extra/energy_and_model_tests.py @@ -18,12 +18,12 @@ import numpy as np from ..sugar import from_random -from .operator_tests import _assert_allclose from .. import Energy, Model __all__ = ["check_value_gradient_consistency", "check_value_gradient_curvature_consistency"] + def _get_acceptable_model(M): # TODO: do for model val = M.value @@ -32,7 +32,7 @@ def _get_acceptable_model(M): dir = from_random("normal", M.position.domain) dirder = M.gradient(dir) dir *= val/(dirder).norm()*1e-5 - # find a step length that leads to a "reasonable" Model + # Find a step length that leads to a "reasonable" Model for i in range(50): try: M2 = M.at(M.position+dir) @@ -53,7 +53,7 @@ def _get_acceptable_energy(E): dir = from_random("normal", E.position.domain) dirder = E.gradient.vdot(dir) dir *= np.abs(val)/np.abs(dirder)*1e-5 - # find a step length that leads to a "reasonable" energy + # Find a step length that leads to a "reasonable" energy for i in range(50): try: E2 = E.at(E.position+dir) @@ -84,7 +84,7 @@ def check_value_gradient_consistency(E, tol=1e-8, ntries=100): else: dirder = Emid.gradient(dir)/dirnorm if isinstance(E, Model): - #TODO: use relative error here instead + # TODO: use relative error here instead if ((E2.value-val)/dirnorm - dirder).norm()/dirder.norm()< tol: break else: diff --git a/test/test_models/test_model_gradients.py b/test/test_models/test_model_gradients.py index e6d6fd32..b4a7e973 100644 --- a/test/test_models/test_model_gradients.py +++ b/test/test_models/test_model_gradients.py @@ -17,12 +17,11 @@ # and financially supported by the Studienstiftung des deutschen Volkes. import unittest -import nifty5 as ift -import numpy as np from itertools import product from test.common import expand -from numpy.testing import assert_allclose +import nifty5 as ift +import numpy as np class Model_Tests(unittest.TestCase): @@ -32,9 +31,9 @@ class Model_Tests(unittest.TestCase): [4, 78, 23])) def testMul(self, space, seed): np.random.seed(seed) - #TODO: use random Multifields instead + # TODO: use random Multifields instead s1 = ift.full(space, np.random.randn()) s2 = ift.full(space, np.random.randn()) - s1_var = ift.Variable(ift.MultiField({'s1':s1}))['s1'] - s2_var = ift.Variable(ift.MultiField({'s2':s2}))['s2'] + s1_var = ift.Variable(ift.MultiField({'s1': s1}))['s1'] + s2_var = ift.Variable(ift.MultiField({'s2': s2}))['s2'] ift.extra.check_value_gradient_consistency(s1_var*s2_var) -- GitLab