[Numpy-discussion] old-Numeric: OverflowError on exp(-760)
Sebastian Haase
haase at msg.ucsf.edu
Wed Jun 14 15:12:58 CDT 2006
Hi,
Thanks for the reply.
Just for general enjoyment: I found a solution:
It seems that substituting
N.exp(-700)
by
N.e ** -700
changes the behaviour to the better ...
Thanks,
Sebastian Haase
On Monday 12 June 2006 15:19, Sasha wrote:
> BTW, here is the relevant explanation from mathmodule.c:
>
> /* ANSI C generally requires libm functions to set ERANGE
> * on overflow, but also generally *allows* them to set
> * ERANGE on underflow too. There's no consistency about
> * the latter across platforms.
> * Alas, C99 never requires that errno be set.
> * Here we suppress the underflow errors (libm functions
> * should return a zero on underflow, and +- HUGE_VAL on
> * overflow, so testing the result for zero suffices to
> * distinguish the cases).
> */
>
> On 6/12/06, Sasha <ndarray at mac.com> wrote:
> > I don't know about numarray, but the difference between Numeric and
> > python math module stems from the fact that the math module ignores
> > errno set by C library and only checks for infinity. Numeric relies
> >
> > on errno exclusively, numpy ignores errors by default:
> > >>> import numpy,math,Numeric
> > >>> numpy.exp(-760)
> >
> > 0.0
> >
> > >>> math.exp(-760)
> >
> > 0.0
> >
> > >>> Numeric.exp(-760)
> >
> > Traceback (most recent call last):
> > File "<stdin>", line 1, in ?
> > OverflowError: math range error
> >
> > >>> numpy.exp(760)
> >
> > inf
> >
> > >>> math.exp(760)
> >
> > Traceback (most recent call last):
> > File "<stdin>", line 1, in ?
> > OverflowError: math range error
> >
> > >>> Numeric.exp(760)
> >
> > Traceback (most recent call last):
> > File "<stdin>", line 1, in ?
> > OverflowError: math range error
> >
> > I would say it's a bug in Numeric, so you are out of luck.
> >
> > Unfortunalely, even MA.exp(-760) does not work, but this is easy to fix:
> > >>> exp =
> > >>> MA.masked_unary_operation(Numeric.exp,0.0,MA.domain_check_interval(-1
> > >>>00,100)) exp(-760).filled()
> >
> > 0
> >
> > You would need to replace -100,100 with the bounds appropriate for your
> > system.
> >
> > On 6/12/06, Sebastian Haase <haase at msg.ucsf.edu> wrote:
> > > Hi,
> > > I'm using Konrad Hinsen's LeastSquares.leastSquaresFit for a convenient
> > > way to do a non linear minimization. It uses the "old" Numeric module.
> > > But since I upgraded to Numeric 24.2 I get OverflowErrors that I
> > > tracked down to
> > >
> > > >>> Numeric.exp(-760.)
> > >
> > > Traceback (most recent call last):
> > > File "<input>", line 1, in ?
> > > OverflowError: math range error
> > >
> > > >From numarray I'm used to getting this:
> > > >>> na.exp(-760)
> > >
> > > 0.0
> > >
> > > Mostly I'm confused because my code worked before I upgraded to version
> > > 24.2.
> > >
> > > Thanks for any hints on how I could revive my code...
> > > -Sebastian Haase
More information about the Numpy-discussion
mailing list