Skip to content

Commit 1ffbd3d

Browse files
authored
RuntimeWarning (fine) filtering
1 parent 75797b1 commit 1ffbd3d

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

fractals/julia_sets.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,13 @@
1515
http://www.math.univ-toulouse.fr/~cheritat/GalII/galery.html
1616
and
1717
https://ddd.uab.cat/pub/pubmat/02141493v43n1/02141493v43n1p27.pdf
18+
19+
Remark: Some overflow runtime warnings are suppressed. This is because of the
20+
way the iterateion loop is implemented, using numpy's efficient computations.
21+
Overflows and infinites are replaced after each step by a large number.
1822
"""
1923

24+
import warnings
2025
from typing import Any, Callable
2126

2227
import numpy
@@ -87,7 +92,7 @@ def iterate_function(
8792
array([ 0, 1, 256])
8893
"""
8994

90-
z_n = z_0.astype('complex64')
95+
z_n = z_0.astype("complex64")
9196
for i in range(nb_iterations):
9297
z_n = eval_function(function_params, z_n)
9398
if infinity is not None:
@@ -117,10 +122,30 @@ def show_results(
117122
pyplot.show()
118123

119124

125+
def ignore_overflow_warnings():
126+
# Fine grained filtering will make sure that we know what we are doing
127+
warnings.filterwarnings(
128+
"ignore", category=RuntimeWarning, message="overflow encountered in multiply"
129+
)
130+
warnings.filterwarnings(
131+
"ignore",
132+
category=RuntimeWarning,
133+
message="invalid value encountered in multiply",
134+
)
135+
warnings.filterwarnings(
136+
"ignore", category=RuntimeWarning, message="overflow encountered in absolute"
137+
)
138+
warnings.filterwarnings(
139+
"ignore", category=RuntimeWarning, message="overflow encountered in exp"
140+
)
141+
142+
120143
if __name__ == "__main__":
121144

122145
z_0 = prepare_grid(window_size, nb_pixels)
123146

147+
ignore_overflow_warnings() # See file header for explanations
148+
124149
nb_iterations = 24
125150
escape_radius = 2 * abs(c_cauliflower) + 1
126151
z_final = iterate_function(

0 commit comments

Comments
 (0)