[Scipy-tickets] [SciPy] #1187: ode crashes if rhs returns a tuple instead of a list

SciPy Trac scipy-tickets@scipy....
Sat Jan 5 06:26:43 CST 2013

```#1187: ode crashes if rhs returns a tuple instead of a list
--------------------------------------------------------+-------------------
Reporter:  miha                                        |       Owner:  somebody
Type:  defect                                      |      Status:  new
Priority:  normal                                      |   Milestone:  Unscheduled
Component:  scipy.integrate                             |     Version:  0.7.0
Keywords:  integrade, ode, PyObject_Call, tuple, list  |
--------------------------------------------------------+-------------------

Comment(by rgommers):

The first line of your {{{lorenz_compute}}} function is incorrect.  This
works as expected:
{{{
import numpy as np
from scipy import integrate

# Given state [x, y, z] compute right hand side of the Lorenz equations.
# The default coefficients compute the canonical attractor.
def lorenz(t, xyz, coefficients = [10., 8./3., 28.]):
x, y, z = xyz
sigma, beta, rho = coefficients
return [sigma*(y-x), x*(rho-z)-y, x*y-beta*z]

def lorenz_compute(tf = 1000, dt = 0.1, xyz0 = np.random.randn(3)):
solver = integrate.ode(lorenz)
solver.set_integrator('vode')
solver.set_initial_value(xyz0, 0)
soln = []
while solver.successful() and solver.t < tf:
solver.integrate(solver.t + dt)
soln.append([solver.t, solver.y[0], solver.y[1], solver.y[2]])

return np.array(soln)

if __name__ == "__main__":
a = lorenz_compute()
}}}

And then, changing the return of {{{lorenz}}} from list of 3 elements to
tuple of elements gives the {{{SystemError}}} again.

--
Ticket URL: <http://projects.scipy.org/scipy/ticket/1187#comment:8>
SciPy <http://www.scipy.org>
SciPy is open-source software for mathematics, science, and engineering.
```