tensorflow_probability/python/distributions/vector_diffeomixture.py
def maybe_check_quadrature_param(param, name, validate_args):
  """Helper which checks validity of `loc` and `scale` init args."""
  with tf.name_scope("check_" + name):
    assertions = []
    if tensorshape_util.rank(param.shape) is not None:
      if tensorshape_util.rank(param.shape) == 0:
        raise ValueError("Mixing params must be a (batch of) vector; "
                         "{}.rank={} is not at least one.".format(
                             name, tensorshape_util.rank(param.shape)))
    elif validate_args:
      assertions.append(
          assert_util.assert_rank_at_least(
              param,
              1,
              message=("Mixing params must be a (batch of) vector; "
                       "{}.rank is not at least one.".format(name))))

    # TODO(jvdillon): Remove once we support k-mixtures.
    if tensorshape_util.with_rank_at_least(param.shape, 1)[-1] is not None:
      if tf.compat.dimension_value(param.shape[-1]) != 1:
        raise NotImplementedError("Currently only bimixtures are supported; "
                                  "{}.shape[-1]={} is not 1.".format(
                                      name,
                                      tf.compat.dimension_value(
                                          param.shape[-1])))
    elif validate_args:
      assertions.append(
          assert_util.assert_equal(
              tf.shape(input=param)[-1],
              1,
              message=("Currently only bimixtures are supported; "
                       "{}.shape[-1] is not 1.".format(name))))

    if assertions:
      return distribution_util.with_dependencies(assertions, param)
    return param
def maybe_check_quadrature_param(param, name, validate_args):
  with tf.name_scope("check_" + name):
    assertions = []
    if tensorshape_util.rank(param.shape) is not None:
      if tensorshape_util.rank(param.shape) == 0:
        raise ValueError("Mixing params must be a (batch of) vector; "
                         "{}.rank={} is not at least one.".format(
                             name, tensorshape_util.rank(param.shape)))
    elif validate_args:
      assertions.append(
          assert_util.assert_rank_at_least(
              param,
              1,
              message=("Mixing params must be a (batch of) vector; "
                       "{}.rank is not at least one.".format(name))))

    # TODO(jvdillon): Remove once we support k-mixtures.
    if tensorshape_util.with_rank_at_least(param.shape, 1)[-1] is not None:
      if tf.compat.dimension_value(param.shape[-1]) != 1:
        raise NotImplementedError("Currently only bimixtures are supported; "
                                  "{}.shape[-1]={} is not 1.".format(
                                      name,
                                      tf.compat.dimension_value(
                                          param.shape[-1])))
    elif validate_args:
      assertions.append(
          assert_util.assert_equal(
              tf.shape(input=param)[-1],
              1,
              message=("Currently only bimixtures are supported; "
                       "{}.shape[-1] is not 1.".format(name))))

    if assertions:
      return distribution_util.with_dependencies(assertions, param)
    return param
def maybe_check_quadrature_param ( param , name , validate_args ) : with tf . name_scope ( "check_" + name ) : assertions = [ ] if tensorshape_util . rank ( param . shape ) is not None : if tensorshape_util . rank ( param . shape ) == 0 : raise ValueError ( "Mixing params must be a (batch of) vector; " "{}.rank={} is not at least one." . format ( name , tensorshape_util . rank ( param . shape ) ) ) elif validate_args : assertions . append ( assert_util . assert_rank_at_least ( param , 1 , message = ( "Mixing params must be a (batch of) vector; " "{}.rank is not at least one." . format ( name ) ) ) ) # TODO(jvdillon): Remove once we support k-mixtures. if tensorshape_util . with_rank_at_least ( param . shape , 1 ) [ - 1 ] is not None : if tf . compat . dimension_value ( param . shape [ - 1 ] ) != 1 : raise NotImplementedError ( "Currently only bimixtures are supported; " "{}.shape[-1]={} is not 1." . format ( name , tf . compat . dimension_value ( param . shape [ - 1 ] ) ) ) elif validate_args : assertions . append ( assert_util . assert_equal ( tf . shape ( input = param ) [ - 1 ] , 1 , message = ( "Currently only bimixtures are supported; " "{}.shape[-1] is not 1." . format ( name ) ) ) ) if assertions : return distribution_util . with_dependencies ( assertions , param ) return param
Helper which checks validity of `loc` and `scale` init args.
Helper which checks validity of loc and scale init args .