tensorflow_probability/python/internal/distribution_util.py
def assert_integer_form(x,
                        data=None,
                        summarize=None,
                        message=None,
                        int_dtype=None,
                        name="assert_integer_form"):
  """Assert that x has integer components (or floats equal to integers).

  Args:
    x: Floating-point `Tensor`
    data: The tensors to print out if the condition is `False`. Defaults to
      error message and first few entries of `x` and `y`.
    summarize: Print this many entries of each tensor.
    message: A string to prefix to the default message.
    int_dtype: A `tf.dtype` used to cast the float to. The default (`None`)
      implies the smallest possible signed int will be used for casting.
    name: A name for this operation (optional).

  Returns:
    Op raising `InvalidArgumentError` if `cast(x, int_dtype) != x`.
  """
  with tf.name_scope(name):
    x = tf.convert_to_tensor(value=x, name="x")
    if dtype_util.is_integer(x.dtype):
      return tf.no_op()
    message = message or "{} has non-integer components".format(x)
    if int_dtype is None:
      try:
        int_dtype = {
            tf.float16: tf.int16,
            tf.float32: tf.int32,
            tf.float64: tf.int64,
        }[dtype_util.base_dtype(x.dtype)]
      except KeyError:
        raise TypeError("Unrecognized type {}".format(dtype_util.name(x.dtype)))
    return assert_util.assert_equal(
        x,
        tf.cast(tf.cast(x, int_dtype), x.dtype),
        data=data,
        summarize=summarize,
        message=message,
        name=name)
def assert_integer_form(x,
                        data=None,
                        summarize=None,
                        message=None,
                        int_dtype=None,
                        name="assert_integer_form"):
  """Assert that x has integer components (or floats equal to integers).

  Args:
    x: Floating-point `Tensor`
    data: The tensors to print out if the condition is `False`. Defaults to
      error message and first few entries of `x` and `y`.
    summarize: Print this many entries of each tensor.
    message: A string to prefix to the default message.
    int_dtype: A `tf.dtype` used to cast the float to. The default (`None`)
      implies the smallest possible signed int will be used for casting.
    name: A name for this operation (optional).

  Returns:
    Op raising `InvalidArgumentError` if `cast(x, int_dtype) != x`.
  """
  with tf.name_scope(name):
    x = tf.convert_to_tensor(value=x, name="x")
    if dtype_util.is_integer(x.dtype):
      return tf.no_op()
    message = message or "{} has non-integer components".format(x)
    if int_dtype is None:
      try:
        int_dtype = {
            tf.float16: tf.int16,
            tf.float32: tf.int32,
            tf.float64: tf.int64,
        }[dtype_util.base_dtype(x.dtype)]
      except KeyError:
        raise TypeError("Unrecognized type {}".format(dtype_util.name(x.dtype)))
    return assert_util.assert_equal(
        x,
        tf.cast(tf.cast(x, int_dtype), x.dtype),
        data=data,
        summarize=summarize,
        message=message,
        name=name)
def assert_integer_form ( x , data = None , summarize = None , message = None , int_dtype = None , name = "assert_integer_form" ) : with tf . name_scope ( name ) : x = tf . convert_to_tensor ( value = x , name = "x" ) if dtype_util . is_integer ( x . dtype ) : return tf . no_op ( ) message = message or "{} has non-integer components" . format ( x ) if int_dtype is None : try : int_dtype = { tf . float16 : tf . int16 , tf . float32 : tf . int32 , tf . float64 : tf . int64 , } [ dtype_util . base_dtype ( x . dtype ) ] except KeyError : raise TypeError ( "Unrecognized type {}" . format ( dtype_util . name ( x . dtype ) ) ) return assert_util . assert_equal ( x , tf . cast ( tf . cast ( x , int_dtype ) , x . dtype ) , data = data , summarize = summarize , message = message , name = name )
Assert that x has integer components (or floats equal to integers).

  Args:
    x: Floating-point `Tensor`
    data: The tensors to print out if the condition is `False`. Defaults to
      error message and first few entries of `x` and `y`.
    summarize: Print this many entries of each tensor.
    message: A string to prefix to the default message.
    int_dtype: A `tf.dtype` used to cast the float to. The default (`None`)
      implies the smallest possible signed int will be used for casting.
    name: A name for this operation (optional).

  Returns:
    Op raising `InvalidArgumentError` if `cast(x, int_dtype) != x`.
Assert that x has integer components ( or floats equal to integers ) .