From 7d735091dea36f4f63b5dbaaec78df9c1af1abbf Mon Sep 17 00:00:00 2001 From: Valentin Boettcher Date: Mon, 12 Dec 2022 17:23:19 -0500 Subject: [PATCH] be clever when calculationg tanhsinh zs --- stocproc/stocproc.py | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/stocproc/stocproc.py b/stocproc/stocproc.py index 9f58a2e..0498248 100644 --- a/stocproc/stocproc.py +++ b/stocproc/stocproc.py @@ -861,9 +861,14 @@ class StocProc_TanhSinh(StocProc): tmp1 = self.fl * y tmp2 = -1j * self.omega_k - z = np.fromiter( - (np.sum(tmp1 * np.exp(tmp2 * t)) for t in self.t), dtype=tmp2.dtype - ) + exp_fac = np.exp(tmp2 * self.t[1]) + + z = np.empty(len(self.t), dtype=tmp2.dtype) + last = tmp1.astype(tmp2.dtype) + + for i in range(len(self.t)): + z[i] = np.sum(last) + last *= exp_fac return z @@ -879,11 +884,17 @@ class StocProc_TanhSinh(StocProc): tmp1 = self.fl * y tmp2 = -1j * self.omega_k + exp_fac = np.exp(tmp2 * self.t[1]) pre = tmp1 * tmp2 - z_dot = np.fromiter( - (np.sum(pre * np.exp(tmp2 * t)) for t in self.t), dtype=tmp2.dtype - ) + + z_dot = np.empty(len(self.t), dtype=tmp2.dtype) + last = pre + + for i in range(len(self.t)): + z_dot[i] = np.sum(last) + last *= exp_fac + return z_dot