Stop program when getting a warning (invalid value encountered in sqrt)

Hi, 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

2010/11/9 Jóan Petur Petersen <joanpeturpetersen@gmail.com>:
I have write quite a large program, but I occationally get the following warning message:
Warning: invalid value encountered in sqrt
Can I make the program stop instead of just giving a warning, so that I get a traceback to where it comes from?
I think np.seterr(invalid='raise') should do the trick. Cheers, Scott
participants (2)
-
Jóan Petur Petersen
-
Scott Sinclair