Permalink
Browse files

Merge pull request #220 from pv/ticket/1623

BUG: integrate: fix complex_ode y attribute
  • Loading branch information...
2 parents d8fafcc + 0076fdd commit 8bb894b4018ae91c24241dc8c5a55af1bc171f31 @pv pv committed Jun 9, 2012
Showing with 35 additions and 11 deletions.
  1. +13 −0 doc/release/0.11.0-notes.rst
  2. +18 −10 scipy/integrate/_ode.py
  3. +4 −1 scipy/integrate/tests/test_integrate.py
@@ -197,6 +197,19 @@ Removal of ``scipy.maxentropy``
The ``scipy.maxentropy`` module, which was deprecated in the 0.10.0 release,
has been removed. Logistic regression in scikits.learn is a good and modern
alternative for this functionality.
+alternative for this functionality.
+
+Behavior of ``scipy.integrate.complex_ode``
+-------------------------------------------
+
+The behavior of the ``y`` attribute of ``complex_ode`` is changed.
+Previously, it expressed the complex-valued solution in the form::
+
+ z = ode.y[::2] + 1j * ode.y[1::2]
+
+Now, it is directly the complex-valued solution::
+
+ z = ode.y
Other changes
View
@@ -278,18 +278,22 @@ def __init__(self, f, jac=None):
self.jac = jac
self.f_params = ()
self.jac_params = ()
- self.y = []
+ self._y = []
+
+ @property
+ def y(self):
+ return self._y
def set_initial_value(self, y, t=0.0):
"""Set initial conditions y(t) = y."""
if isscalar(y):
y = [y]
- n_prev = len(self.y)
+ n_prev = len(self._y)
if not n_prev:
self.set_integrator('') # find first available integrator
- self.y = asarray(y, self._integrator.scalar)
+ self._y = asarray(y, self._integrator.scalar)
self.t = t
- self._integrator.reset(len(self.y), self.jac is not None)
+ self._integrator.reset(len(self._y), self.jac is not None)
return self
def set_integrator(self, name, **integrator_params):
@@ -311,10 +315,10 @@ def set_integrator(self, name, **integrator_params):
'available.' % name)
else:
self._integrator = integrator(**integrator_params)
- if not len(self.y):
+ if not len(self._y):
self.t = 0.0
- self.y = array([0.0], self._integrator.scalar)
- self._integrator.reset(len(self.y), self.jac is not None)
+ self._y = array([0.0], self._integrator.scalar)
+ self._integrator.reset(len(self._y), self.jac is not None)
return self
def integrate(self, t, step=0, relax=0):
@@ -325,10 +329,10 @@ def integrate(self, t, step=0, relax=0):
mth = self._integrator.run_relax
else:
mth = self._integrator.run
- self.y, self.t = mth(self.f, self.jac or (lambda: None),
- self.y, self.t, t,
+ self._y, self.t = mth(self.f, self.jac or (lambda: None),
+ self._y, self.t, t,
self.f_params, self.jac_params)
- return self.y
+ return self._y
def successful(self):
"""Check if integration was successful."""
@@ -399,6 +403,10 @@ def _wrap_jac(self, t, y, *jac_args):
self.jac_tmp[::2, 1::2] = -self.jac_tmp[1::2, ::2]
return self.jac_tmp
+ @property
+ def y(self):
+ return self._y[::2] + 1j * self._y[1::2]
+
def set_integrator(self, name, **integrator_params):
"""
Set integrator by name.
@@ -8,7 +8,8 @@
allclose
from numpy.testing import assert_, TestCase, run_module_suite, \
- assert_array_almost_equal, assert_raises, assert_allclose
+ assert_array_almost_equal, assert_raises, assert_allclose, \
+ assert_array_equal
from scipy.integrate import odeint, ode, complex_ode
#------------------------------------------------------------------------------
@@ -155,7 +156,9 @@ def _do_problem(self, problem, integrator, method='adams'):
method=method)
ig.set_initial_value(problem.z0, t=0.0)
z = ig.integrate(problem.stop_t)
+ z2 = ig.y
+ assert_array_equal(z, z2)
assert_(ig.successful(), (problem, method))
assert_(problem.verify(array([z]), problem.stop_t), (problem, method))

0 comments on commit 8bb894b

Please sign in to comment.