Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: integrate: Fix crash with repeated t values in odeint. #8822

Merged
merged 1 commit into from
May 14, 2018

Conversation

WarrenWeckesser
Copy link
Member

Two changes to odeint:

  • Require t to be monotonically increasing or monotonically
    decreasing. Repeated values are allowed.
  • If the initial value in t is repeated, don't bother calling
    LSODA for those times. Just copy the initial condition to the
    output.
    This fixes the problem where an input such as t = np.zeros(10)
    would abort the Python interpreter (because of how the Fortran
    subroutine LSODA handled the repeated calls with the same value
    of t).

Closes gh-8217.

@WarrenWeckesser WarrenWeckesser added scipy.integrate defect A clear bug or issue that prevents SciPy from being installed or used as expected labels May 11, 2018
@WarrenWeckesser WarrenWeckesser added this to the 1.2.0 milestone May 11, 2018

dt = np.diff(t)
if not((dt >= 0).all() or (dt <= 0).all()):
raise ValueError("The values in t must be monotonically increasing "
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess, since we allow for repeated values, this should read as must either all nondecreasing or all nonincreasing but not a mixture. or something along those lines.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By every definition that I have seen, the statement "t is monotonically increasing" means t[i] <= t[i+1] for all i, so repeated values are allowed.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But I guess it wouldn't hurt to state explicitly that repeated values are allowed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also thought that "monotonically increasing" was < and "monotonically nondecreasing was <= but upon reading the definitions this does indeed appear mistaken! I agree adding a (t[i] <= t[i+1] for all i) sort of parenthetical is worth it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a note to the docstring and the error message about allowing repeated values.

@ilayn
Copy link
Member

ilayn commented May 12, 2018

Looks good to me apart from a tiny detail.

Two changes to odeint:

* Require `t` to be monotonically increasing or monotonically
  decreasing.  Repeated values are allowed.
* If the initial value in `t` is repeated, don't bother calling
  LSODA for those times.  Just copy the initial condition to the
  output.
  This fixes the problem where an input such as `t = np.zeros(10)`
  would abort the Python interpreter (because of how the Fortran
  subroutine LSODA handled the repeated calls with the same value
  of t).

Closes scipygh-8217.
@pv pv merged commit 0aee4a2 into scipy:master May 14, 2018
@pv
Copy link
Member

pv commented May 14, 2018

Thanks, issues seemed addressed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
defect A clear bug or issue that prevents SciPy from being installed or used as expected scipy.integrate
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: odeint crashes via lsoda instead of giving an error for zero timestep
4 participants