tensorflow_probability/python/distributions/transformed_distribution.py
def _maybe_validate_shape_override(self, override_shape, base_is_scalar,
                                     validate_args, name):
    """Helper to __init__ which ensures override batch/event_shape are valid."""
    if override_shape is None:
      override_shape = []

    override_shape = tf.convert_to_tensor(
        value=override_shape, dtype=tf.int32, name=name)

    if not dtype_util.is_integer(override_shape.dtype):
      raise TypeError("shape override must be an integer")

    override_is_scalar = _is_scalar_from_shape_tensor(override_shape)
    if tf.get_static_value(override_is_scalar):
      return self._empty

    dynamic_assertions = []

    if tensorshape_util.rank(override_shape.shape) is not None:
      if tensorshape_util.rank(override_shape.shape) != 1:
        raise ValueError("shape override must be a vector")
    elif validate_args:
      dynamic_assertions += [
          assert_util.assert_rank(
              override_shape, 1, message="shape override must be a vector")
      ]

    if tf.get_static_value(override_shape) is not None:
      if any(s < 0 for s in tf.get_static_value(override_shape)):
        raise ValueError("shape override must have non-negative elements")
    elif validate_args:
      dynamic_assertions += [
          assert_util.assert_non_negative(
              override_shape,
              message="shape override must have non-negative elements")
      ]

    is_both_nonscalar = prefer_static.logical_and(
        prefer_static.logical_not(base_is_scalar),
        prefer_static.logical_not(override_is_scalar))
    if tf.get_static_value(is_both_nonscalar) is not None:
      if tf.get_static_value(is_both_nonscalar):
        raise ValueError("base distribution not scalar")
    elif validate_args:
      dynamic_assertions += [
          assert_util.assert_equal(
              is_both_nonscalar, False, message="base distribution not scalar")
      ]

    if not dynamic_assertions:
      return override_shape
    return distribution_util.with_dependencies(
        dynamic_assertions, override_shape)
def _maybe_validate_shape_override(self, override_shape, base_is_scalar,
                                     validate_args, name):
    """Helper to __init__ which ensures override batch/event_shape are valid."""
    if override_shape is None:
      override_shape = []

    override_shape = tf.convert_to_tensor(
        value=override_shape, dtype=tf.int32, name=name)

    if not dtype_util.is_integer(override_shape.dtype):
      raise TypeError("shape override must be an integer")

    override_is_scalar = _is_scalar_from_shape_tensor(override_shape)
    if tf.get_static_value(override_is_scalar):
      return self._empty

    dynamic_assertions = []

    if tensorshape_util.rank(override_shape.shape) is not None:
      if tensorshape_util.rank(override_shape.shape) != 1:
        raise ValueError("shape override must be a vector")
    elif validate_args:
      dynamic_assertions += [
          assert_util.assert_rank(
              override_shape, 1, message="shape override must be a vector")
      ]

    if tf.get_static_value(override_shape) is not None:
      if any(s < 0 for s in tf.get_static_value(override_shape)):
        raise ValueError("shape override must have non-negative elements")
    elif validate_args:
      dynamic_assertions += [
          assert_util.assert_non_negative(
              override_shape,
              message="shape override must have non-negative elements")
      ]

    is_both_nonscalar = prefer_static.logical_and(
        prefer_static.logical_not(base_is_scalar),
        prefer_static.logical_not(override_is_scalar))
    if tf.get_static_value(is_both_nonscalar) is not None:
      if tf.get_static_value(is_both_nonscalar):
        raise ValueError("base distribution not scalar")
    elif validate_args:
      dynamic_assertions += [
          assert_util.assert_equal(
              is_both_nonscalar, False, message="base distribution not scalar")
      ]

    if not dynamic_assertions:
      return override_shape
    return distribution_util.with_dependencies(
        dynamic_assertions, override_shape)
def _maybe_validate_shape_override ( self , override_shape , base_is_scalar , validate_args , name ) : if override_shape is None : override_shape = [ ] override_shape = tf . convert_to_tensor ( value = override_shape , dtype = tf . int32 , name = name ) if not dtype_util . is_integer ( override_shape . dtype ) : raise TypeError ( "shape override must be an integer" ) override_is_scalar = _is_scalar_from_shape_tensor ( override_shape ) if tf . get_static_value ( override_is_scalar ) : return self . _empty dynamic_assertions = [ ] if tensorshape_util . rank ( override_shape . shape ) is not None : if tensorshape_util . rank ( override_shape . shape ) != 1 : raise ValueError ( "shape override must be a vector" ) elif validate_args : dynamic_assertions += [ assert_util . assert_rank ( override_shape , 1 , message = "shape override must be a vector" ) ] if tf . get_static_value ( override_shape ) is not None : if any ( s < 0 for s in tf . get_static_value ( override_shape ) ) : raise ValueError ( "shape override must have non-negative elements" ) elif validate_args : dynamic_assertions += [ assert_util . assert_non_negative ( override_shape , message = "shape override must have non-negative elements" ) ] is_both_nonscalar = prefer_static . logical_and ( prefer_static . logical_not ( base_is_scalar ) , prefer_static . logical_not ( override_is_scalar ) ) if tf . get_static_value ( is_both_nonscalar ) is not None : if tf . get_static_value ( is_both_nonscalar ) : raise ValueError ( "base distribution not scalar" ) elif validate_args : dynamic_assertions += [ assert_util . assert_equal ( is_both_nonscalar , False , message = "base distribution not scalar" ) ] if not dynamic_assertions : return override_shape return distribution_util . with_dependencies ( dynamic_assertions , override_shape )
Helper to __init__ which ensures override batch/event_shape are valid.
Helper to __init__ which ensures override batch / event_shape are valid .