[Numpy-discussion] Stop program when getting a warning (invalid value encountered in sqrt)

Jóan Petur Petersen joanpeturpetersen@gmail....
Tue Nov 9 05:34:01 CST 2010


I have write quite a large program, but I occationally get the following
warning message:

Warning: invalid value encountered in sqrt

The programs runs for several hours finding the hyperparameters of a
Gaussian Process, but occationally this warning pop up. Maybe due tue
rounding errors or maybe because some numbers become nan.

Can I make the program stop instead of just giving a warning, so that I get
a traceback to where it comes from?

For example in IPython:

In [4]: def test():
   ...:     np.sqrt(-1)
   ...:     np.sqrt(-1)

In [5]: test()
Warning: invalid value encountered in sqrt
Warning: invalid value encountered in sqrt

Gives the warning two times instead of stopping.

Best regard,
Jóan Petur Petersen
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20101109/93461a5c/attachment.html 

More information about the NumPy-Discussion mailing list