class_docstr: Extension of IndepMessenger that includes subsampling.
class_docstr_tok: ["Extension","of","IndepMessenger","that","includes","subsampling","."]
docstr: Helper function for plate. See its docstrings for details.
docstr_tok: ["Helper","function","for","plate",".","See","its","docstrings","for","details","."]
code: def _subsample(
      name: str,
      size: Optional[int] = None,
      subsample_size: Optional[int] = None,
      subsample: Optional[torch.Tensor] = None,
      use_cuda: Optional[bool] = None,
      device: Optional[str] = None,
  ) -> Tuple[int, int, Optional[torch.Tensor]]:
      """
      Helper function for plate. See its docstrings for details.
      """
      if size is None:
          assert subsample_size is None
          assert subsample is None
          size = -1  # This is PyTorch convention for "arbitrary size"
          subsample_size = -1
      else:
          msg = Message(
              type="sample",
              name=name,
              fn=_Subsample(size, subsample_size, use_cuda, device),
              is_observed=False,
              args=(),
              kwargs={},
              value=subsample,
              infer={},
              scale=1.0,
              mask=None,
              cond_indep_stack=(),
              done=False,
              stop=False,
              continuation=None,
          )
          apply_stack(msg)
          subsample = msg["value"]
  
      with ignore_jit_warnings():
          if subsample_size is None:
              assert subsample is not None
              subsample_size = (
                  subsample.size(0)
                  if isinstance(subsample, torch.Tensor)
                  else len(subsample)
              )
          elif subsample is not None and subsample_size != len(
              subsample
          ):
              raise ValueError(
                  "subsample_size does not match len(subsample), {} vs {}.".format(
                      subsample_size, len(subsample)
                  )
                  + " Did you accidentally use different subsample_size in the model and guide?"
              )
  
      return size, subsample_size, subsample
  
file_path: pyro/pyro/poutine/subsample_messenger.py
imports: from typing import Optional, Tuple
  import torch
  from pyro.distributions.distribution import Distribution
  from pyro.poutine.indep_messenger import CondIndepStackFrame, IndepMessenger
  from pyro.poutine.runtime import Message, apply_stack
  from pyro.poutine.util import is_validation_enabled
  from pyro.util import ignore_jit_warnings
label_desc: Use image node_id 2 for calling the SubsampleMessenger obj's underlying member method code with example usage: obj._subsample(name, size, subsample_size, subsample, use_cuda, device) and returns: size,  subsample_size,  subsample