Skip to content

Commit

Permalink
A round of black.
Browse files Browse the repository at this point in the history
  • Loading branch information
bluescarni committed Nov 21, 2023
1 parent b0907f9 commit e23b659
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 54 deletions.
54 changes: 21 additions & 33 deletions heyoka/_test_cfunc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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)
8 changes: 6 additions & 2 deletions heyoka/_test_elp2000.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
18 changes: 9 additions & 9 deletions heyoka/_test_expression.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
2 changes: 0 additions & 2 deletions heyoka/_test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))


5 changes: 3 additions & 2 deletions heyoka/_test_scalar_integrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 12 additions & 4 deletions heyoka/_test_sympy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 6 additions & 2 deletions heyoka/_test_vsop2013.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

0 comments on commit e23b659

Please sign in to comment.