Skip to content

Commit

Permalink
Merge pull request #74 from vpratz/Development
Browse files Browse the repository at this point in the history
Bugfix: check_tensor_sanity use of .numpy() only possible in eager mode.
  • Loading branch information
stefanradev93 committed May 28, 2023
2 parents 187140a + 763248c commit 153dfef
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions bayesflow/helper_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,20 @@

def check_tensor_sanity(tensor, logger):
"""Tests for the present of NaNs and Infs in a tensor."""

if tf.reduce_any(tf.math.is_nan(tensor)):
num_na = tf.reduce_sum(tf.cast(tf.math.is_nan(tensor), tf.int8)).numpy()
logger.warn(f"Warning! Returned estimates contain {num_na} nan values!")
if tf.reduce_any(tf.math.is_inf(tensor)):
num_inf = tf.reduce_sum(tf.cast(tf.math.is_inf(tensor), tf.int8)).numpy()
logger.warn(f"Warning! Returned estimates contain {num_inf} inf values!")
if tf.executing_eagerly():
if tf.reduce_any(tf.math.is_nan(tensor)):
num_na = tf.reduce_sum(tf.cast(tf.math.is_nan(tensor), tf.int8)).numpy()
logger.warn(f"Warning! Returned estimates contain {num_na} nan values!")
if tf.reduce_any(tf.math.is_inf(tensor)):
num_inf = tf.reduce_sum(tf.cast(tf.math.is_inf(tensor), tf.int8)).numpy()
logger.warn(f"Warning! Returned estimates contain {num_inf} inf values!")
else:
if tf.reduce_any(tf.math.is_nan(tensor)):
num_na = tf.reduce_sum(tf.cast(tf.math.is_nan(tensor), tf.int8))
tf.print("Warning! Returned estimates contain", num_na, "nan values!")
if tf.reduce_any(tf.math.is_inf(tensor)):
num_inf = tf.reduce_sum(tf.cast(tf.math.is_inf(tensor), tf.int8))
tf.print(f"Warning! Returned estimates contain", num_inf, "inf values!")


def merge_left_into_right(left_dict, right_dict):
Expand Down

0 comments on commit 153dfef

Please sign in to comment.