JensGrabner / mpmath-2

Automatically exported from code.google.com/p/mpmath
Other
3 stars 0 forks source link

UnboundLocalError in findroot #152

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
findroot doesn't properly handle the case where the solver exits without
generating any values, which can occur for example if f(x0) and f(x1) are
identical and nonzero:

>>> findroot(lambda x: -1, 0)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "c:\source\mp\trunk\mpmath\mptypes.py", line 70, in g
    return f(*args, **kwargs)
  File "c:\source\mp\trunk\mpmath\optimization.py", line 950, in findroot
    if not isinstance(x, (list, tuple, matrix)):
UnboundLocalError: local variable 'x' referenced before assignment

Original issue reported on code.google.com by fredrik....@gmail.com on 26 Jun 2009 at 9:42

GoogleCodeExporter commented 9 years ago
Issue 125 has been merged into this issue.

Original comment by Vinzent.Steinberg@gmail.com on 26 Jun 2009 at 7:32

GoogleCodeExporter commented 9 years ago
Yeah, this is a known issue. Should the solver exit without generating values 
at all?

Original comment by Vinzent.Steinberg@gmail.com on 26 Jun 2009 at 7:34

GoogleCodeExporter commented 9 years ago
Given that the solver computes an x1 value, it should probably at least yield 
that.

But arguably, findroot should do something meaningful anyway when no points are
generated.

Original comment by fredrik....@gmail.com on 26 Jun 2009 at 7:36