parameters: (loc, scale, name="shapes_from_loc_and_scale")
return_statement: return batch_shape, event_shape
docstring: Infer distribution batch and event shapes from a location and scale.
  
    Location and scale family distributions determine their batch/event shape by
    broadcasting the `loc` and `scale` args.  This helper does that broadcast,
    statically if possible.
  
    Batch shape broadcasts as per the normal rules.
    We allow the `loc` event shape to broadcast up to that of `scale`.  We do not
    allow `scale`'s event shape to change.  Therefore, the last dimension of `loc`
    must either be size `1`, or the same as `scale.range_dimension`.
  
    See `MultivariateNormalLinearOperator` for a usage example.
  
    Args:
      loc:  `N-D` `Tensor` with `N >= 1` (already converted to tensor) or `None`.
        If `None`, both batch and event shape are determined by `scale`.
      scale:  A `LinearOperator` instance.
      name:  A string name to prepend to created ops.
  
    Returns:
      batch_shape:  `TensorShape` (if broadcast is done statically), or `Tensor`.
      event_shape:  `TensorShape` (if broadcast is done statically), or `Tensor`.
  
    Raises:
      ValueError:  If the last dimension of `loc` is determined statically to be
        different than the range of `scale`.
docstring_summary: Infer distribution batch and event shapes from a location and scale.
docstring_tokens: Infer distribution batch and event shapes from a location and scale .
function: def shapes_from_loc_and_scale(loc, scale, name="shapes_from_loc_and_scale"):
    """Infer distribution batch and event shapes from a location and scale.
  
    Location and scale family distributions determine their batch/event shape by
    broadcasting the `loc` and `scale` args.  This helper does that broadcast,
    statically if possible.
  
    Batch shape broadcasts as per the normal rules.
    We allow the `loc` event shape to broadcast up to that of `scale`.  We do not
    allow `scale`'s event shape to change.  Therefore, the last dimension of `loc`
    must either be size `1`, or the same as `scale.range_dimension`.
  
    See `MultivariateNormalLinearOperator` for a usage example.
  
    Args:
      loc:  `N-D` `Tensor` with `N >= 1` (already converted to tensor) or `None`.
        If `None`, both batch and event shape are determined by `scale`.
      scale:  A `LinearOperator` instance.
      name:  A string name to prepend to created ops.
  
    Returns:
      batch_shape:  `TensorShape` (if broadcast is done statically), or `Tensor`.
      event_shape:  `TensorShape` (if broadcast is done statically), or `Tensor`.
  
    Raises:
      ValueError:  If the last dimension of `loc` is determined statically to be
        different than the range of `scale`.
    """
    with ops.name_scope(name, values=[loc] + scale.graph_parents):
      # Get event shape.
      event_size = scale.range_dimension_tensor()
      event_size_const = tensor_util.constant_value(event_size)
      if event_size_const is not None:
        event_shape = event_size_const.reshape([1])
      else:
        event_shape = event_size[array_ops.newaxis]
  
      # Static check that event shapes match.
      if loc is not None:
        loc_event_size = tensor_shape.dimension_value(loc.get_shape()[-1])
        if loc_event_size is not None and event_size_const is not None:
          if loc_event_size != 1 and loc_event_size != event_size_const:
            raise ValueError(
                "Event size of 'scale' (%d) could not be broadcast up to that of "
                "'loc' (%d)." % (loc_event_size, event_size_const))
  
      # Get batch shape.
      batch_shape = scale.batch_shape_tensor()
      if loc is None:
        batch_shape_const = tensor_util.constant_value(batch_shape)
        batch_shape = (
            batch_shape_const if batch_shape_const is not None else batch_shape)
      else:
        loc_batch_shape = loc.get_shape().with_rank_at_least(1)[:-1]
        if (loc.get_shape().ndims is None or
            not loc_batch_shape.is_fully_defined()):
          loc_batch_shape = array_ops.shape(loc)[:-1]
        else:
          loc_batch_shape = ops.convert_to_tensor(loc_batch_shape,
                                                  name="loc_batch_shape")
        # This is defined in the core util module.
        # pylint: disable=undefined-variable
        batch_shape = prefer_static_broadcast_shape(batch_shape, loc_batch_shape)
        # pylint: enable=undefined-variable
  
    return batch_shape, event_shape
function_tokens: def shapes_from_loc_and_scale ( loc , scale , name = "shapes_from_loc_and_scale" ) : with ops . name_scope ( name , values = [ loc ] + scale . graph_parents ) : # Get event shape. event_size = scale . range_dimension_tensor ( ) event_size_const = tensor_util . constant_value ( event_size ) if event_size_const is not None : event_shape = event_size_const . reshape ( [ 1 ] ) else : event_shape = event_size [ array_ops . newaxis ] # Static check that event shapes match. if loc is not None : loc_event_size = tensor_shape . dimension_value ( loc . get_shape ( ) [ - 1 ] ) if loc_event_size is not None and event_size_const is not None : if loc_event_size != 1 and loc_event_size != event_size_const : raise ValueError ( "Event size of 'scale' (%d) could not be broadcast up to that of " "'loc' (%d)." % ( loc_event_size , event_size_const ) ) # Get batch shape. batch_shape = scale . batch_shape_tensor ( ) if loc is None : batch_shape_const = tensor_util . constant_value ( batch_shape ) batch_shape = ( batch_shape_const if batch_shape_const is not None else batch_shape ) else : loc_batch_shape = loc . get_shape ( ) . with_rank_at_least ( 1 ) [ : - 1 ] if ( loc . get_shape ( ) . ndims is None or not loc_batch_shape . is_fully_defined ( ) ) : loc_batch_shape = array_ops . shape ( loc ) [ : - 1 ] else : loc_batch_shape = ops . convert_to_tensor ( loc_batch_shape , name = "loc_batch_shape" ) # This is defined in the core util module. # pylint: disable=undefined-variable batch_shape = prefer_static_broadcast_shape ( batch_shape , loc_batch_shape ) # pylint: enable=undefined-variable return batch_shape , event_shape