我的问题是关于当前的 scipy ode 求解器。来自scipy 文档页面 http://docs.scipy.org/doc/scipy/reference/generated/scipy.integrate.ode.html#scipy.integrate.ode,它们的用法是:
# A problem to integrate and the corresponding jacobian:
from scipy.integrate import ode
y0, t0 = [1.0j, 2.0], 0
def f(t, y, arg1):
return [1j*arg1*y[0] + y[1], -arg1*y[1]**2]
def jac(t, y, arg1):
return [[1j*arg1, 1], [0, -arg1*2*y[1]]]
# The integration:
r = ode(f, jac).set_integrator('zvode', method='bdf', with_jacobian=True)
r.set_initial_value(y0, t0).set_f_params(2.0).set_jac_params(2.0)
t1 = 10
dt = 1
while r.successful() and r.t < t1:
r.integrate(r.t+dt)
print("%g %g" % (r.t, r.y))
我的问题是:它使用了大量的 python 循环(while 循环),这本质上减慢了程序的速度。我可以尝试编写 C 代码并使用 ctypes 来使其更快,但我将无法访问 scipy 中像 dopri5 这样的好算法(除非我自己实现)。
是否有任何矢量化编码方式可以使其更快?
谢谢你!