class_docstr: A running covariance computation.
  
  The running covariance computation supports batching. The `event_ndims`
  parameter indicates the number of trailing dimensions to treat as part of
  the event, and to compute covariance across. The leading dimensions, if
  any, are treated as batch shape, and no cross terms are computed.
  
  For example, if the incoming samples have shape `[5, 7]`, the `event_ndims`
  selects among three different covariance computations:
  - `event_ndims=0` treats the samples as a `[5, 7]` batch of scalar random
    variables, and computes their variances in batch.  The shape of the result
    is `[5, 7]`.
  - `event_ndims=1` treats the samples as a `[5]` batch of vector random
    variables of shape `[7]`, and computes their covariances in batch.  The
    shape of the result is `[5, 7, 7]`.
  - `event_ndims=2` treats the samples as a single random variable of
    shape `[5, 7]` and computes its covariance.  The shape of the result
    is `[5, 7, 5, 7]`.
  
  `RunningCovariance` is meant to serve general streaming covariance needs.
  For a specialized version that fits streaming over MCMC samples, see
  `CovarianceReducer` in `tfp.experimental.mcmc`.
docstr: Starts a `RunningCovariance` from shape and dtype metadata.
  
  Args:
    shape: Python `Tuple` or `TensorShape` representing the shape of incoming
      samples.  This is useful to supply if the `RunningCovariance` will be
      carried by a `tf.while_loop`, so that broadcasting does not change the
      shape across loop iterations.
    dtype: Dtype of incoming samples and the resulting statistics.
      By default, the dtype is `tf.float32`. Any integer dtypes will be
      cast to corresponding floats (i.e. `tf.int32` will be cast to
      `tf.float32`), as intermediate calculations should be performing
      floating-point division.
    event_ndims:  Number of dimensions that specify the event shape, from
      the inner-most dimensions.  Specifying `None` returns all cross
      product terms (no batching) and is the default.
    name: Python `str` name prefixed to Ops created by this class.
  
  Returns:
    cov: An empty `RunningCovariance`, ready for incoming samples.
  
  Raises:
    ValueError: if `event_ndims` is greater than the rank of the intended
      incoming samples (operation is extraneous).
docstr_tok: ["Starts","a","`","RunningCovariance","`","from","shape","and","dtype","metadata",".","Args",":","shape",":","Python","`","Tuple","`","or","`","TensorShape","`","representing","the","shape","of","incoming","samples",".","This","is","useful","to","supply","if","the","`","RunningCovariance","`","will","be","carried","by","a","`","tf.while_loop","`",",","so","that","broadcasting","does","not","change","the","shape","across","loop","iterations",".","dtype",":","Dtype","of","incoming","samples","and","the","resulting","statistics",".","By","default",",","the","dtype","is","`","tf.float32","`",".","Any","integer","dtypes","will","be","cast","to","corresponding","floats","(","i.e",".","`","tf.int32","`","will","be","cast","to","`","tf.float32","`",")",",","as","intermediate","calculations","should","be","performing","floating-point","division",".","event_ndims",":","Number","of","dimensions","that","specify","the","event","shape",",","from","the","inner-most","dimensions",".","Specifying","`","None","`","returns","all","cross","product","terms","(","no","batching",")","and","is","the","default",".","name",":","Python","`","str","`","name","prefixed","to","Ops","created","by","this","class",".","Returns",":","cov",":","An","empty","`","RunningCovariance","`",",","ready","for","incoming","samples",".","Raises",":","ValueError",":","if","`","event_ndims","`","is","greater","than","the","rank","of","the","intended","incoming","samples","(","operation","is","extraneous",")","."]
code: def from_shape(
      cls,
      shape=(),
      dtype=tf.float32,
      event_ndims=None,
      name="RunningCovariance",
  ):
      """Starts a `RunningCovariance` from shape and dtype metadata.
  
      Args:
        shape: Python `Tuple` or `TensorShape` representing the shape of incoming
          samples.  This is useful to supply if the `RunningCovariance` will be
          carried by a `tf.while_loop`, so that broadcasting does not change the
          shape across loop iterations.
        dtype: Dtype of incoming samples and the resulting statistics.
          By default, the dtype is `tf.float32`. Any integer dtypes will be
          cast to corresponding floats (i.e. `tf.int32` will be cast to
          `tf.float32`), as intermediate calculations should be performing
          floating-point division.
        event_ndims:  Number of dimensions that specify the event shape, from
          the inner-most dimensions.  Specifying `None` returns all cross
          product terms (no batching) and is the default.
        name: Python `str` name prefixed to Ops created by this class.
  
      Returns:
        cov: An empty `RunningCovariance`, ready for incoming samples.
  
      Raises:
        ValueError: if `event_ndims` is greater than the rank of the intended
          incoming samples (operation is extraneous).
      """
      dtype = _float_dtype_like(dtype)
      event_ndims = _default_covariance_event_ndims(event_ndims, shape)
      if event_ndims == 0:
          extra_ndims_shape = ()
      else:
          # event_ndims cannot be None by this point
          extra_ndims_shape = shape[
              -event_ndims:
          ]  # pylint: disable=invalid-unary-operand-type
      return cls(
          num_samples=tf.zeros((), dtype=dtype),
          mean=tf.zeros(shape, dtype=dtype),
          sum_squared_residuals=tf.zeros(
              ps.concat([shape, extra_ndims_shape], axis=0), dtype=dtype
          ),
          event_ndims=event_ndims,
          name=name,
      )
  
imports: import functools
  import math
  import numpy
  import tensorflow.compat.v2
  from tensorflow_probability.python.internal import dtype_util
  from tensorflow_probability.python.internal import nest_util
  from tensorflow_probability.python.internal import prefer_static
  from tensorflow_probability.python.mcmc import diagnostic
  from tensorflow.python.util import nest
label_desc: Use image node_id 4 for calling the RunningCovariance obj's underlying member method code with example usage: obj.from_shape(cls, shape, dtype, event_ndims, name) and returns: cls