class_docstr: Declares a Pyro-managed random attribute of a :class:`PyroModule`, similar
  to :func:`pyro.sample <pyro.primitives.sample>`.
  
  This can be used either to set attributes of :class:`PyroModule`
  instances::
  
      assert isinstance(my_module, PyroModule)
      my_module.x = PyroSample(Normal(0, 1))                    # independent
      my_module.y = PyroSample(lambda self: Normal(self.x, 1))  # dependent
  
  or EXPERIMENTALLY as a decorator on lazy initialization methods::
  
      class MyModule(PyroModule):
          @PyroSample
          def x(self):
              return Normal(0, 1)       # independent
  
          @PyroSample
          def y(self):
              return Normal(self.x, 1)  # dependent
  
          def forward(self):
              return self.y             # accessed like a @property
  
  :param prior: distribution object or function that inputs the
      :class:`PyroModule` instance ``self`` and returns a distribution
      object.
class_docstr_tok: ["Declares","a","Pyro-managed","random","attribute","of","a",":","class",":","`","PyroModule","`",",","similar","to",":","func",":","`","pyro.sample","<","pyro.primitives.sample",">","`",".","This","can","be","used","either","to","set","attributes","of",":","class",":","`","PyroModule","`","instances",":",":","assert","isinstance","(","my_module",",","PyroModule",")","my_module.x","=","PyroSample","(","Normal","(","0",",","1",")",")","#","independent","my_module.y","=","PyroSample","(","lambda","self",":","Normal","(","self.x",",","1",")",")","#","dependent","or","EXPERIMENTALLY","as","a","decorator","on","lazy","initialization","methods",":",":","class","MyModule","(","PyroModule",")",":","@","PyroSample","def","x","(","self",")",":","return","Normal","(","0",",","1",")","#","independent","@","PyroSample","def","y","(","self",")",":","return","Normal","(","self.x",",","1",")","#","dependent","def","forward","(","self",")",":","return","self.y","#","accessed","like","a","@","property",":","param","prior",":","distribution","object","or","function","that","inputs","the",":","class",":","`","PyroModule","`","instance","``","self","``","and","returns","a","distribution","object","."]
code: def __get__(self, obj, obj_type):
      assert issubclass(obj_type, PyroModule)
      if obj is None:
          return self
  
      if self.name is None:
          for name in dir(obj_type):
              if getattr(obj_type, name) is self:
                  self.name = name
                  break
      else:
          setattr(
              obj_type, self.prior.__name__, self.prior
          )  # for pickling
  
      obj.__dict__["_pyro_samples"].setdefault(self.name, self.prior)
      return obj.__getattr__(self.name)
  
imports: import functools
  import inspect
  import weakref
  from collections import OrderedDict, namedtuple
  import torch
  from torch.distributions import constraints, transform_to
  import pyro
  from pyro.ops.provenance import detach_provenance
  from pyro.poutine.runtime import _PYRO_PARAM_STORE
label_desc: Use image node_id 2 for calling the PyroSample obj's underlying member method code with example usage: obj.__get__(obj, obj_type) and returns: obj, self