class_docstr: Dense implementation of :class:`AutoGaussian` .
  
  The following are equivalent::
  
      guide = AutoGaussian(model, backend="dense")
      guide = AutoGaussianDense(model)
class_docstr_tok: ["Dense","implementation","of",":","class",":","`","AutoGaussian","`",".","The","following","are","equivalent",":",":","guide","=","AutoGaussian","(","model",",","backend=","''","dense","''",")","guide","=","AutoGaussianDense","(","model",")"]
code: def _setup_prototype(self, *args, **kwargs):
      super()._setup_prototype(*args, **kwargs)
  
      # Collect global shapes and per-axis indices.
      self._dense_shapes = {}
      global_indices = {}
      pos = 0
      for d, event_shape in self._unconstrained_event_shapes.items():
          batch_shape = self._factors[d]["fn"].batch_shape
          self._dense_shapes[d] = batch_shape, event_shape
          end = pos + (batch_shape + event_shape).numel()
          global_indices[d] = torch.arange(pos, end).reshape(
              batch_shape + (-1,)
          )
          pos = end
      self._dense_size = pos
  
      # Create sparse -> dense precision scatter indices.
      self._dense_scatter = {}
      for d, site in self._factors.items():
          prec_sqrt_shape = deep_getattr(self.prec_sqrts, d).shape
          info_vec_shape = prec_sqrt_shape[:-1]
          precision_shape = (
              prec_sqrt_shape[:-1] + prec_sqrt_shape[-2:-1]
          )
          index1 = torch.zeros(info_vec_shape, dtype=torch.long)
          index2 = torch.zeros(precision_shape, dtype=torch.long)
  
          # Collect local offsets and create index1 for info_vec blockwise.
          upstreams = [
              u
              for u in self.dependencies[d]
              if not self._factors[u]["is_observed"]
          ]
          local_offsets = {}
          pos = 0
          for u in upstreams:
              local_offsets[u] = pos
              broken_plates = self._plates[u] - self._plates[d]
              pos += (
                  self._event_numel[u]
                  * _plates_to_shape(broken_plates).numel()
              )
              u_index = global_indices[u]
  
              # Permute broken plates to the right of preserved plates.
              u_index = _break_plates(
                  u_index, self._plates[u], self._plates[d]
              )
  
              # Scatter global indices into the [u] block.
              u_start = local_offsets[u]
              u_stop = u_start + u_index.size(-1)
              index1[..., u_start:u_stop] = u_index
  
          # Create index2 for precision blockwise.
          for u, v in itertools.product(upstreams, upstreams):
              u_index = global_indices[u]
              v_index = global_indices[v]
  
              # Permute broken plates to the right of preserved plates.
              u_index = _break_plates(
                  u_index, self._plates[u], self._plates[d]
              )
              v_index = _break_plates(
                  v_index, self._plates[v], self._plates[d]
              )
  
              # Scatter global indices into the [u,v] block.
              u_start = local_offsets[u]
              u_stop = u_start + u_index.size(-1)
              v_start = local_offsets[v]
              v_stop = v_start + v_index.size(-1)
              index2[
                  ..., u_start:u_stop, v_start:v_stop
              ] = self._dense_size * u_index.unsqueeze(
                  -1
              ) + v_index.unsqueeze(
                  -2
              )
  
          self._dense_scatter[d] = index1.reshape(-1), index2.reshape(
              -1
          )
  
imports: import itertools
  from abc import ABCMeta, abstractmethod
  from collections import OrderedDict, defaultdict
  from contextlib import ExitStack
  from types import SimpleNamespace
  from typing import Callable, Dict, Optional, Set, Tuple, Union
  import torch
  from torch.distributions import biject_to
  import pyro
  import pyro.distributions
  import pyro.poutine
  from pyro.distributions import constraints
  from pyro.infer.inspect import get_dependencies, is_sample_site
  from pyro.nn.module import PyroModule, PyroParam
  from pyro.ops.linalg import ignore_torch_deprecation_warnings
  from pyro.poutine.runtime import am_i_wrapped, get_plates
  from pyro.poutine.util import site_is_subsample
  from .guides import AutoGuide
  from .initialization import InitMessenger, init_to_feasible
  from .utils import deep_getattr, deep_setattr, helpful_support_errors
label_desc: Use image node_id 1 for calling the AutoGaussianDense obj's underlying member method code with example usage: obj._setup_prototype() without return types