Browse code

silence warnings from division by 0

Joseph Weston authored on 17/11/2017 12:15:57 • Bas Nijholt committed on 20/11/2017 15:49:57
Showing 1 changed files
... ...
@@ -2,6 +2,7 @@
2 2
 # Copyright 2017 Christoph Groth
3 3
 
4 4
 import warnings
5
+import functools
5 6
 from fractions import Fraction as Frac
6 7
 from collections import defaultdict
7 8
 import numpy as np
... ...
@@ -412,10 +413,23 @@ def algorithm_4 (f, a, b, tol):
412 413
 
413 414
 ################ Tests ################
414 415
 
416
+def silence_warnings(f):
417
+
418
+    @functools.wraps(f)
419
+    def _(*args, **kwargs):
420
+        with warnings.catch_warnings():
421
+            warnings.simplefilter("ignore")
422
+            return f(*args, **kwargs)
423
+
424
+    return _
425
+
426
+
427
+@silence_warnings
415 428
 def f0(x):
416 429
     return x * np.sin(1/x) * np.sqrt(abs(1 - x))
417 430
 
418 431
 
432
+@silence_warnings
419 433
 def f7(x):
420 434
     return x**-0.5
421 435
 
... ...
@@ -431,10 +445,12 @@ def f21(x):
431 445
     return y
432 446
 
433 447
 
448
+@silence_warnings
434 449
 def f63(x):
435 450
     return abs(x - 0.987654321)**-0.45
436 451
 
437 452
 
453
+@silence_warnings
438 454
 def fdiv(x):
439 455
     return abs(x - 0.987654321)**-1.1
440 456