From e23b6590c6507a1c02f1b8f0e7cd2b5d480c81af Mon Sep 17 00:00:00 2001 From: Francesco Biscani Date: Tue, 21 Nov 2023 09:52:58 +0100 Subject: [PATCH] A round of black. --- heyoka/_test_cfunc.py | 54 ++++++++++++------------------- heyoka/_test_elp2000.py | 8 +++-- heyoka/_test_expression.py | 18 +++++------ heyoka/_test_model.py | 2 -- heyoka/_test_scalar_integrator.py | 5 +-- heyoka/_test_sympy.py | 16 ++++++--- heyoka/_test_vsop2013.py | 8 +++-- 7 files changed, 57 insertions(+), 54 deletions(-) diff --git a/heyoka/_test_cfunc.py b/heyoka/_test_cfunc.py index 6d665279..f3245cf8 100644 --- a/heyoka/_test_cfunc.py +++ b/heyoka/_test_cfunc.py @@ -86,47 +86,27 @@ def test_basic(self): # Tests for correct detection of number of params, time dependency # and list of variables. - cf = make_cfunc( - [y * (x + z), x], vars=[y, z, x] - ) + cf = make_cfunc([y * (x + z), x], vars=[y, z, x]) self.assertEqual(cf.param_size, 0) - cf = make_cfunc( - [y * (x + z), par[0]], vars=[y, z, x] - ) + cf = make_cfunc([y * (x + z), par[0]], vars=[y, z, x]) self.assertEqual(cf.param_size, 1) - cf = make_cfunc( - [y * (x + z) - par[89], par[0]], vars=[y, z, x] - ) + cf = make_cfunc([y * (x + z) - par[89], par[0]], vars=[y, z, x]) self.assertEqual(cf.param_size, 90) - cf = make_cfunc( - [y * (x + z), x], vars=[y, z, x] - ) + cf = make_cfunc([y * (x + z), x], vars=[y, z, x]) self.assertFalse(cf.is_time_dependent) - cf = make_cfunc( - [y * (x + z) + time, x], vars=[y, z, x] - ) + cf = make_cfunc([y * (x + z) + time, x], vars=[y, z, x]) self.assertTrue(cf.is_time_dependent) - cf = make_cfunc( - [y * (x + z), x + time], vars=[y, z, x] - ) + cf = make_cfunc([y * (x + z), x + time], vars=[y, z, x]) self.assertTrue(cf.is_time_dependent) - cf = make_cfunc( - [y * (x + z), x + time] - ) + cf = make_cfunc([y * (x + z), x + time]) self.assertEqual(cf.list_var, [x, y, z]) - cf = make_cfunc( - [y * (x + z), x + time], vars=[y, z, x] - ) + cf = make_cfunc([y * (x + z), x + time], vars=[y, z, x]) self.assertEqual(cf.list_var, [y, z, x]) - cf = make_cfunc( - [y * (x + z), x + time], vars=[y, z, x, s] - ) + cf = make_cfunc([y * (x + z), x + time], vars=[y, z, x, s]) self.assertEqual(cf.list_var, [y, z, x, s]) - cf = make_cfunc( - [y * (x + z), x + time], vars=[s, y, z, x] - ) + cf = make_cfunc([y * (x + z), x + time], vars=[s, y, z, x]) self.assertEqual(cf.list_var, [s, y, z, x]) # NOTE: test for a bug in the multiprecision @@ -859,7 +839,9 @@ def test_single(self): # Tests with no inputs. fn = make_cfunc([expression(fp_t(3)) + par[1], par[0] + time], fp_type=fp_t) - eval_arr = fn(inputs=np.zeros((0,), dtype=fp_t), pars=[fp_t(1), fp_t(2)], time=fp_t(3)) + eval_arr = fn( + inputs=np.zeros((0,), dtype=fp_t), pars=[fp_t(1), fp_t(2)], time=fp_t(3) + ) self.assertTrue( _allclose( eval_arr, @@ -884,7 +866,11 @@ def test_single(self): [expression(fp_t(3)), expression(fp_t(4)) + time], fp_type=fp_t ) - eval_arr = fn(inputs=np.zeros((0,), dtype=fp_t), pars=np.zeros((0,), dtype=fp_t), time=fp_t(3)) + eval_arr = fn( + inputs=np.zeros((0,), dtype=fp_t), + pars=np.zeros((0,), dtype=fp_t), + time=fp_t(3), + ) self.assertTrue( _allclose( eval_arr, @@ -916,6 +902,8 @@ def test_single(self): self.assertEqual(eval_arr[0], 3) # Same but with time. - eval_arr = fn(inputs=[fp_t(1), fp_t(2)], pars=np.zeros((0,), dtype=fp_t), time=fp_t(3)) + eval_arr = fn( + inputs=[fp_t(1), fp_t(2)], pars=np.zeros((0,), dtype=fp_t), time=fp_t(3) + ) self.assertEqual(eval_arr[0], 3) diff --git a/heyoka/_test_elp2000.py b/heyoka/_test_elp2000.py index 04181272..9b3a0c9d 100644 --- a/heyoka/_test_elp2000.py +++ b/heyoka/_test_elp2000.py @@ -20,9 +20,13 @@ def test_basic(self): cf = make_cfunc([sol]) date = 2469000.5 - self.assertAlmostEqual(cf([], time=(date - 2451545.0) / 36525)[0], -361605.79234692274) + self.assertAlmostEqual( + cf([], time=(date - 2451545.0) / 36525)[0], -361605.79234692274 + ) sol = elp2000_cartesian_fk5(thresh=1e-5)[0] cf = make_cfunc([sol]) - self.assertAlmostEqual(cf([], time=(date - 2451545.0) / 36525)[0], -361605.7668217605) + self.assertAlmostEqual( + cf([], time=(date - 2451545.0) / 36525)[0], -361605.7668217605 + ) diff --git a/heyoka/_test_expression.py b/heyoka/_test_expression.py index 49446872..72bc5226 100644 --- a/heyoka/_test_expression.py +++ b/heyoka/_test_expression.py @@ -340,12 +340,12 @@ def test_relu_wrappers(self): x, y = make_vars("x", "y") - self.assertEqual(leaky_relu(0.)(x), relu(x)) - self.assertEqual(leaky_relup(0.)(x), relup(x)) - self.assertEqual(leaky_relu(0.1)(x+y), relu(x+y,0.1)) - self.assertEqual(leaky_relup(0.1)(x+y), relup(x+y,0.1)) - - self.assertEqual(leaky_relu(0.)(x*y), relu(x*y)) - self.assertEqual(leaky_relup(0.)(x*y), relup(x*y)) - self.assertEqual(leaky_relu(0.1)(x*y+y), relu(x*y+y,0.1)) - self.assertEqual(leaky_relup(0.1)(x*y+y), relup(x*y+y,0.1)) + self.assertEqual(leaky_relu(0.0)(x), relu(x)) + self.assertEqual(leaky_relup(0.0)(x), relup(x)) + self.assertEqual(leaky_relu(0.1)(x + y), relu(x + y, 0.1)) + self.assertEqual(leaky_relup(0.1)(x + y), relup(x + y, 0.1)) + + self.assertEqual(leaky_relu(0.0)(x * y), relu(x * y)) + self.assertEqual(leaky_relup(0.0)(x * y), relup(x * y)) + self.assertEqual(leaky_relu(0.1)(x * y + y), relu(x * y + y, 0.1)) + self.assertEqual(leaky_relup(0.1)(x * y + y), relup(x * y + y, 0.1)) diff --git a/heyoka/_test_model.py b/heyoka/_test_model.py index fd28bc97..52e0c88d 100644 --- a/heyoka/_test_model.py +++ b/heyoka/_test_model.py @@ -287,5 +287,3 @@ def test_ffnn(self): my_ffnn4 = model.ffnn([x], [], 1, [linear], [1.2, 1.3]) self.assertTrue(my_ffnn4[0] == expression(1.3) + (expression(1.2) * x)) - - diff --git a/heyoka/_test_scalar_integrator.py b/heyoka/_test_scalar_integrator.py index 5a9c02b7..01ee4fad 100644 --- a/heyoka/_test_scalar_integrator.py +++ b/heyoka/_test_scalar_integrator.py @@ -90,9 +90,10 @@ def test_dtime(self): # BUG: the dtime setter used to be hard-coded # to double. from numpy import longdouble as ld + ta = taylor_adaptive(sys=sys, state=[ld(0.0), ld(0.25)], fp_type=ld) - ta.dtime = (ld('1.1'),ld(0)) - self.assertEqual(ta.dtime, (ld('1.1'),ld(0))) + ta.dtime = (ld("1.1"), ld(0)) + self.assertEqual(ta.dtime, (ld("1.1"), ld(0))) def test_copy(self): from . import taylor_adaptive, make_vars, t_event, sin diff --git a/heyoka/_test_sympy.py b/heyoka/_test_sympy.py index cfa9bc32..ecdf9451 100644 --- a/heyoka/_test_sympy.py +++ b/heyoka/_test_sympy.py @@ -295,10 +295,18 @@ def test_func_conversion(self): ) # relu/relup. - self.assertEqual(to_sympy(core.relu(hx)), spy.Piecewise((x, x > 0), (0., True))) - self.assertEqual(to_sympy(core.relup(hx)), spy.Piecewise((1., x > 0), (0., True))) - self.assertEqual(to_sympy(core.relu(hx, 0.1)), spy.Piecewise((x, x > 0), (x*0.1, True))) - self.assertEqual(to_sympy(core.relup(hx, 0.1)), spy.Piecewise((1., x > 0), (0.1, True))) + self.assertEqual( + to_sympy(core.relu(hx)), spy.Piecewise((x, x > 0), (0.0, True)) + ) + self.assertEqual( + to_sympy(core.relup(hx)), spy.Piecewise((1.0, x > 0), (0.0, True)) + ) + self.assertEqual( + to_sympy(core.relu(hx, 0.1)), spy.Piecewise((x, x > 0), (x * 0.1, True)) + ) + self.assertEqual( + to_sympy(core.relup(hx, 0.1)), spy.Piecewise((1.0, x > 0), (0.1, True)) + ) self.assertEqual(-1.0 * hx, from_sympy(-x)) self.assertEqual(to_sympy(-hx), -x) diff --git a/heyoka/_test_vsop2013.py b/heyoka/_test_vsop2013.py index a2867505..10975de7 100644 --- a/heyoka/_test_vsop2013.py +++ b/heyoka/_test_vsop2013.py @@ -20,9 +20,13 @@ def test_basic(self): cf = make_cfunc([sol]) date = 2411545.0 - self.assertAlmostEqual(cf([], time=(date - 2451545.0) / 365250)[0], 0.3870979635) + self.assertAlmostEqual( + cf([], time=(date - 2451545.0) / 365250)[0], 0.3870979635 + ) sol = vsop2013_cartesian(1, thresh=1e-8) cf = make_cfunc([sol[0]]) - self.assertAlmostEqual(cf([], time=(date - 2451545.0) / 365250)[0], 0.3493879042) + self.assertAlmostEqual( + cf([], time=(date - 2451545.0) / 365250)[0], 0.3493879042 + )