numpy divide by zero warnings are annoying

384 views
Skip to first unread message

kcrisman

unread,
Apr 15, 2011, 11:35:27 PM4/15/11
to sage-support
I want to get rid of them. I am pretty sure I'm not dividing by zero
anywhere; 1/sqrt(f**2+1) really shouldn't ever be zero here. Any
ideas?

y = var('y')
g = 1
P=plot_slope_field(g,(x,3,4),(y,-1,1))
P
<two sets of warnings>

And when I say "get rid of", I mean by tomorrow morning in a talk I'm
giving. This is almost certainly due to the recent numpy upgrades
being pickier, based on the little searching I did. I'm not turning
off warnings in numpy, though, since we use it under the hood only
here.

Thanks,
- kcrisman

D. S. McNeil

unread,
Apr 16, 2011, 12:49:16 AM4/16/11
to sage-s...@googlegroups.com
> I'm not turning off warnings in numpy, though, since we use it under the hood only
> here.

I'm confused. I was going to recommend numpy.seterr(all='ignore')
before I read this, maybe wrapping plot to restore the original state
after the call.. but now I'm not sure what kind of solution you want.
:^)

In this case, the problem is being caused by the default parameters in
plot_slope_field. If you override headlength=0 with some small
number, there's no problem. IOW,

P=plot_slope_field(g,(x,3,4),(y,-1,1),headlength=1e-8)

works for me. FYI, it's the following few lines in Quiver._h_arrows at fault:

minsh = self.minshaft * self.headlength
[....]
shrink = length/minsh
X0 = shrink * X0[np.newaxis,:]
Y0 = shrink * Y0[np.newaxis,:]

Probably we should change the defaults and/or (if it's not done
already) ask our matplotlib friends to special-case 0 for no
arrowheads.

Does that help?


Doug

kcrisman

unread,
Apr 16, 2011, 8:23:15 PM4/16/11
to sage-support


On Apr 16, 12:49 am, "D. S. McNeil" <dsm...@gmail.com> wrote:
> > I'm not turning off warnings in numpy, though, since we use it under the hood only
> > here.
>
> I'm confused.  I was going to recommend numpy.seterr(all='ignore')
> before I read this, maybe wrapping plot to restore the original state
> after the call..  but now I'm not sure what kind of solution you want.
>  :^)

That was exactly my thought, that this is inappropriate.

> In this case, the problem is being caused by the default parameters in
> plot_slope_field.  If you override headlength=0 with some small
> number, there's no problem.  IOW,
>
> P=plot_slope_field(g,(x,3,4),(y,-1,1),headlength=1e-8)
>
> works for me.  FYI, it's the following few lines in Quiver._h_arrows at fault:
>
>         minsh = self.minshaft * self.headlength
>         [....]
>         shrink = length/minsh
>         X0 = shrink * X0[np.newaxis,:]
>         Y0 = shrink * Y0[np.newaxis,:]
>
> Probably we should change the defaults and/or (if it's not done
> already) ask our matplotlib friends to special-case 0 for no
> arrowheads.
>
> Does that help?

Nice catch! So it wasn't what I thought (though I admit I didn't have
time to actually look at the backtrace much). I had to use Sage 4.4.4
today in a talk just to avoid this. Since it's a warning, it
wouldn't show up in doctesting as a failure.

Yes, it would be worth posting this as a pure pylab example (which I
don't quite know how to do it as, naturally) upstream. See
http://trac.sagemath.org/sage_trac/ticket/11208 (and also
http://trac.sagemath.org/sage_trac/ticket/2922, which is tangentially
related).

- kcrisman
Reply all
Reply to author
Forward
0 new messages