Skip to content

Commit 4def9cf

Browse files
committed
Merge branch 'Development' of https://github.com/stefanradev93/BayesFlow into Development
2 parents 62a9b94 + 153dfef commit 4def9cf

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

bayesflow/helper_functions.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,20 @@
2929

3030
def check_tensor_sanity(tensor, logger):
3131
"""Tests for the present of NaNs and Infs in a tensor."""
32-
33-
if tf.reduce_any(tf.math.is_nan(tensor)):
34-
num_na = tf.reduce_sum(tf.cast(tf.math.is_nan(tensor), tf.int8)).numpy()
35-
logger.warn(f"Warning! Returned estimates contain {num_na} nan values!")
36-
if tf.reduce_any(tf.math.is_inf(tensor)):
37-
num_inf = tf.reduce_sum(tf.cast(tf.math.is_inf(tensor), tf.int8)).numpy()
38-
logger.warn(f"Warning! Returned estimates contain {num_inf} inf values!")
32+
if tf.executing_eagerly():
33+
if tf.reduce_any(tf.math.is_nan(tensor)):
34+
num_na = tf.reduce_sum(tf.cast(tf.math.is_nan(tensor), tf.int8)).numpy()
35+
logger.warn(f"Warning! Returned estimates contain {num_na} nan values!")
36+
if tf.reduce_any(tf.math.is_inf(tensor)):
37+
num_inf = tf.reduce_sum(tf.cast(tf.math.is_inf(tensor), tf.int8)).numpy()
38+
logger.warn(f"Warning! Returned estimates contain {num_inf} inf values!")
39+
else:
40+
if tf.reduce_any(tf.math.is_nan(tensor)):
41+
num_na = tf.reduce_sum(tf.cast(tf.math.is_nan(tensor), tf.int8))
42+
tf.print("Warning! Returned estimates contain", num_na, "nan values!")
43+
if tf.reduce_any(tf.math.is_inf(tensor)):
44+
num_inf = tf.reduce_sum(tf.cast(tf.math.is_inf(tensor), tf.int8))
45+
tf.print(f"Warning! Returned estimates contain", num_inf, "inf values!")
3946

4047

4148
def merge_left_into_right(left_dict, right_dict):

0 commit comments

Comments
 (0)