tensorflow_probability/python/distributions/batch_reshape.py
def validate_init_args_statically(distribution, batch_shape):
  """Helper to __init__ which makes or raises assertions."""
  if tensorshape_util.rank(batch_shape.shape) is not None:
    if tensorshape_util.rank(batch_shape.shape) != 1:
      raise ValueError("`batch_shape` must be a vector "
                       "(saw rank: {}).".format(
                           tensorshape_util.rank(batch_shape.shape)))

  batch_shape_static = tensorshape_util.constant_value_as_shape(batch_shape)
  batch_size_static = tensorshape_util.num_elements(batch_shape_static)
  dist_batch_size_static = tensorshape_util.num_elements(
      distribution.batch_shape)

  if batch_size_static is not None and dist_batch_size_static is not None:
    if batch_size_static != dist_batch_size_static:
      raise ValueError("`batch_shape` size ({}) must match "
                       "`distribution.batch_shape` size ({}).".format(
                           batch_size_static, dist_batch_size_static))

  if tensorshape_util.dims(batch_shape_static) is not None:
    if any(
        tf.compat.dimension_value(dim) is not None and
        tf.compat.dimension_value(dim) < 1 for dim in batch_shape_static):
      raise ValueError("`batch_shape` elements must be >=-1.")
def validate_init_args_statically(distribution, batch_shape):
  """Helper to __init__ which makes or raises assertions."""
  if tensorshape_util.rank(batch_shape.shape) is not None:
    if tensorshape_util.rank(batch_shape.shape) != 1:
      raise ValueError("`batch_shape` must be a vector "
                       "(saw rank: {}).".format(
                           tensorshape_util.rank(batch_shape.shape)))

  batch_shape_static = tensorshape_util.constant_value_as_shape(batch_shape)
  batch_size_static = tensorshape_util.num_elements(batch_shape_static)
  dist_batch_size_static = tensorshape_util.num_elements(
      distribution.batch_shape)

  if batch_size_static is not None and dist_batch_size_static is not None:
    if batch_size_static != dist_batch_size_static:
      raise ValueError("`batch_shape` size ({}) must match "
                       "`distribution.batch_shape` size ({}).".format(
                           batch_size_static, dist_batch_size_static))

  if tensorshape_util.dims(batch_shape_static) is not None:
    if any(
        tf.compat.dimension_value(dim) is not None and
        tf.compat.dimension_value(dim) < 1 for dim in batch_shape_static):
      raise ValueError("`batch_shape` elements must be >=-1.")
def validate_init_args_statically ( distribution , batch_shape ) : if tensorshape_util . rank ( batch_shape . shape ) is not None : if tensorshape_util . rank ( batch_shape . shape ) != 1 : raise ValueError ( "`batch_shape` must be a vector " "(saw rank: {})." . format ( tensorshape_util . rank ( batch_shape . shape ) ) ) batch_shape_static = tensorshape_util . constant_value_as_shape ( batch_shape ) batch_size_static = tensorshape_util . num_elements ( batch_shape_static ) dist_batch_size_static = tensorshape_util . num_elements ( distribution . batch_shape ) if batch_size_static is not None and dist_batch_size_static is not None : if batch_size_static != dist_batch_size_static : raise ValueError ( "`batch_shape` size ({}) must match " "`distribution.batch_shape` size ({})." . format ( batch_size_static , dist_batch_size_static ) ) if tensorshape_util . dims ( batch_shape_static ) is not None : if any ( tf . compat . dimension_value ( dim ) is not None and tf . compat . dimension_value ( dim ) < 1 for dim in batch_shape_static ) : raise ValueError ( "`batch_shape` elements must be >=-1." )
Helper to __init__ which makes or raises assertions.
Helper to __init__ which makes or raises assertions .