def sum_mvns(distributions):
graph_parents = [tensor for distribution in distributions<EOL>for tensor in distribution._graph_parents]  <EOL>with tf.compat.v1.name_scope('<STR_LIT>', values=graph_parents):<EOL><INDENT>if all([isinstance(mvn, tfd.MultivariateNormalDiag)<EOL>for mvn in distributions]):<EOL><INDENT>return tfd.MultivariateNormalDiag(<EOL>loc=sum([mvn.mean() for mvn in distributions]),<EOL>scale_diag=tf.sqrt(sum([<EOL>mvn.scale.diag**<NUM_LIT:2> for mvn in distributions])))<EOL><DEDENT>else:<EOL><INDENT>raise NotImplementedError(<EOL>'<STR_LIT>'<EOL>'<STR_LIT>'.format(distributions))<EOL><DEDENT><DEDENT>
Attempt to sum MultivariateNormal distributions.

    The sum of (multivariate) normal random variables is itself (multivariate)
    normal, with mean given by the sum of means and (co)variance given by the
    sum of (co)variances. This method exploits this fact to compute the
    sum of a list of `tfd.MultivariateNormalDiag` objects.

    It may in the future be extended to support summation of other forms of
    (Multivariate)Normal distributions.

    Args:
      distributions: Python `iterable` of `tfd.MultivariateNormalDiag`
        distribution instances. These must all have the same event
        shape, and broadcast to a consistent batch shape.

    Returns:
      sum_distribution: A `tfd.MultivariateNormalDiag` instance with mean
        equal to the sum of input means and covariance equal to the sum of
        input covariances.