[IPython-dev] from __future__ import division

Fernando Perez fperez.net at gmail.com
Thu Jun 15 03:36:43 CDT 2006


On 6/15/06, Gaël Varoquaux <gael.varoquaux at normalesup.org> wrote:
>     Hi again,
>
>         Fernando's solution does not solve the problem. I am a bit lost.
> I managed to get a minimal example that shows the problem. I am running
> ipython7.1.fix1, if I run the following code using a "%run -i" :
>
> ###############################################
> #Global imports.
> from __future__ import division     # So that 2/3 = 0.6666 and not 0 !
> from scipy import *
> from pylab import *
> w_0 = 50e-6
> # mesh grid of the region of space we are interested in :
> xrange = 0.04
> yrange = 0.002
> [dx, dy] = [xrange/50.0, yrange/50.0]
> [Xgrid,Ygrid] = mgrid[-xrange:(xrange+dx):dx,-yrange:(yrange+dy):dy]
> w = lambda z : w_0 *sqrt( 1 + z **2 )
> Gaussian_beam = lambda y,z :  exp(-(y**2)/(2*w(z)**2))
> GaussianMap = Gaussian_beam(Ygrid,0)
> ###############################################
>
>     If I start ipython with no switch, this works fine. If I start it
> with "-pylab" switch", then I get an "OverflowError: math range error" on
> the last line. This is a minimal example. Removing "w_O" from the
> definition of "w" gets rid of the error.
>
>     I have no clue what the error means nor why it is triggered with the
> pylab mode.
>
>     I think this is an ipython bug but I am not sure. If it is fixed in
> 7.2 please let me know.

This has nothing to do with ipython, it's most likely a problem
stemming from a combination of pylab, numpy and scipy.  On my system
(running mpl 0.87.3 with numerix='numpy', numpy and scipy form SVN as
of 2 days ago), it works just fine.

I'd recommend that you start by NOT doing this:

> from scipy import *
> from pylab import *

which makes it harder to know where the problem is coming from (you
don't know what you are actually calling).  Import each library with
its own name (alias it to a single letter if you want), and then track
exactly which call is firing when the problem appears.

If you get an error, post a full traceback obtained with

xmode verbose

so we can see /exactly/ what is going on in your computer.  Never say
'I get this error', instead always post a traceback.

You also need to let us know precisely which versions of everything
you are running.  I've attached a version of your script which should
make it easier to pin down exactly what's going on.

Here's what I get, regardless of whether I use the division ipythonrc
hack I showed earlier:

In [12]: run divbug
2/3 is not 0!  0.666666666667

scipy version: 0.5.0.1940
mpl   version: 0.87.3
numerix flag : numpy

If we got here, all is OK.



Cheers,

f
-------------- next part --------------
A non-text attachment was scrubbed...
Name: divbug.py
Type: text/x-python
Size: 722 bytes
Desc: not available
Url : http://projects.scipy.org/pipermail/ipython-dev/attachments/20060615/007ddacf/attachment.py 


More information about the IPython-dev mailing list