class_docstr: Mixin to provide Pyro compatibility for PyTorch distributions.
  
  You should instead use `TorchDistribution` for new distribution classes.
  
  This is mainly useful for wrapping existing PyTorch distributions for
  use in Pyro.  Derived classes must first inherit from
  :class:`torch.distributions.distribution.Distribution` and then inherit
  from :class:`TorchDistributionMixin`.
class_docstr_tok: ["Mixin","to","provide","Pyro","compatibility","for","PyTorch","distributions",".","You","should","instead","use","`","TorchDistribution","`","for","new","distribution","classes",".","This","is","mainly","useful","for","wrapping","existing","PyTorch","distributions","for","use","in","Pyro",".","Derived","classes","must","first","inherit","from",":","class",":","`","torch.distributions.distribution.Distribution","`","and","then","inherit","from",":","class",":","`","TorchDistributionMixin","`","."]
docstr: Reinterprets the ``n`` rightmost dimensions of this distributions
  :attr:`~torch.distributions.distribution.Distribution.batch_shape`
  as event dims, adding them to the left side of
  :attr:`~torch.distributions.distribution.Distribution.event_shape`.
  
  Example:
  
      .. doctest::
         :hide:
  
         >>> d0 = dist.Normal(torch.zeros(2, 3, 4, 5), torch.ones(2, 3, 4, 5))
         >>> [d0.batch_shape, d0.event_shape]
         [torch.Size([2, 3, 4, 5]), torch.Size([])]
         >>> d1 = d0.to_event(2)
  
      >>> [d1.batch_shape, d1.event_shape]
      [torch.Size([2, 3]), torch.Size([4, 5])]
      >>> d2 = d1.to_event(1)
      >>> [d2.batch_shape, d2.event_shape]
      [torch.Size([2]), torch.Size([3, 4, 5])]
      >>> d3 = d1.to_event(2)
      >>> [d3.batch_shape, d3.event_shape]
      [torch.Size([]), torch.Size([2, 3, 4, 5])]
  
  :param int reinterpreted_batch_ndims: The number of batch dimensions to
      reinterpret as event dimensions. May be negative to remove
      dimensions from an :class:`pyro.distributions.torch.Independent` .
      If None, convert all dimensions to event dimensions.
  :return: A reshaped version of this distribution.
  :rtype: :class:`pyro.distributions.torch.Independent`
code: def to_event(self, reinterpreted_batch_ndims=None):
      """
      Reinterprets the ``n`` rightmost dimensions of this distributions
      :attr:`~torch.distributions.distribution.Distribution.batch_shape`
      as event dims, adding them to the left side of
      :attr:`~torch.distributions.distribution.Distribution.event_shape`.
  
      Example:
  
          .. doctest::
             :hide:
  
             >>> d0 = dist.Normal(torch.zeros(2, 3, 4, 5), torch.ones(2, 3, 4, 5))
             >>> [d0.batch_shape, d0.event_shape]
             [torch.Size([2, 3, 4, 5]), torch.Size([])]
             >>> d1 = d0.to_event(2)
  
          >>> [d1.batch_shape, d1.event_shape]
          [torch.Size([2, 3]), torch.Size([4, 5])]
          >>> d2 = d1.to_event(1)
          >>> [d2.batch_shape, d2.event_shape]
          [torch.Size([2]), torch.Size([3, 4, 5])]
          >>> d3 = d1.to_event(2)
          >>> [d3.batch_shape, d3.event_shape]
          [torch.Size([]), torch.Size([2, 3, 4, 5])]
  
      :param int reinterpreted_batch_ndims: The number of batch dimensions to
          reinterpret as event dimensions. May be negative to remove
          dimensions from an :class:`pyro.distributions.torch.Independent` .
          If None, convert all dimensions to event dimensions.
      :return: A reshaped version of this distribution.
      :rtype: :class:`pyro.distributions.torch.Independent`
      """
      if reinterpreted_batch_ndims is None:
          reinterpreted_batch_ndims = len(self.batch_shape)
  
      # Deconstruct Independent distributions.
      base_dist = self
      while isinstance(base_dist, torch.distributions.Independent):
          reinterpreted_batch_ndims += (
              base_dist.reinterpreted_batch_ndims
          )
          base_dist = base_dist.base_dist
  
      if reinterpreted_batch_ndims == 0:
          return base_dist
      if reinterpreted_batch_ndims < 0:
          raise ValueError(
              "Cannot remove event dimensions from {}".format(
                  type(self)
              )
          )
      return pyro.distributions.torch.Independent(
          base_dist, reinterpreted_batch_ndims
      )
  
imports: import warnings
  from collections import OrderedDict
  from typing import Callable
  import torch
  from torch.distributions.kl import kl_divergence, register_kl
  import pyro.distributions.torch
  from .None import constraints
  from .distribution import Distribution
  from .score_parts import ScoreParts
  from .util import broadcast_shape, scale_and_mask
label_desc: Use image node_id 10 for calling the TorchDistributionMixin obj's underlying member method code with example usage: obj.to_event(reinterpreted_batch_ndims) and returns: pyro, base_dist