From 43c9ed4bfa7738129c528e1e30e1a90fa4d1f6e8 Mon Sep 17 00:00:00 2001 From: Sam Holt Date: Fri, 9 Aug 2024 17:07:10 +0200 Subject: [PATCH] enforce float --- oommfc/drivers/driver.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/oommfc/drivers/driver.py b/oommfc/drivers/driver.py index 3ffaf16..2ab4dc1 100644 --- a/oommfc/drivers/driver.py +++ b/oommfc/drivers/driver.py @@ -246,11 +246,11 @@ def _time_dependence(term, **kwargs): "used with time driver." ) from None ts = np.arange(0, tmax + term.dt, term.dt) - try: # vector output from term.func - tlist = [list(term.func(t)) for t in ts] + if isinstance(term.func(ts[0]), (list, tuple, np.ndarray)): + tlist = [[float(x) for x in term.func(t)] for t in ts] dtlist = (np.gradient(tlist)[0] / term.dt).tolist() - except TypeError: # scalar output from term.func - tlist = [term.func(t) for t in ts] + else: # scalar output from term.func + tlist = [float(term.func(t)) for t in ts] dtlist = list(np.gradient(tlist) / term.dt) term.tlist = tlist term.dtlist = dtlist