scipy/scipy — pull request #395 by rgommers (2013-01-05 13:27:27+00:00)
Title: MAINT: in integrate.ode, generate understandable error for f2py issue.

Closes ticket 1187. Note that this cannot be tested without a warning message
being printed by vodemodule.c, even when redirecting stderr::

import sys
from scipy import integrate

class RedirectStdStreams(object):
def __init__(self, stdout=None, stderr=None):
self._stdout = stdout or sys.stdout
self._stderr = stderr or sys.stderr

def __enter__(self):
self.old_stdout, self.old_stderr = sys.stdout, sys.stderr
self.old_stdout.flush(); self.old_stderr.flush()
sys.stdout, sys.stderr = self._stdout, self._stderr

def __exit__(self, exc_type, exc_value, traceback):
self._stdout.flush(); self._stderr.flush()
sys.stdout = self.old_stdout

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]]]

with RedirectStdStreams():
r = integrate.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)

For the f2py change suggested by Pearu, a numpy ticket should be opened.