class_docstr: Rejection sampled distribution given an acceptance rate function.
  
  :param Distribution propose: A proposal distribution that samples batched
      proposals via ``propose()``. :meth:`rsample` supports a ``sample_shape``
      arg only if ``propose()`` supports a ``sample_shape`` arg.
  :param callable log_prob_accept: A callable that inputs a batch of
      proposals and returns a batch of log acceptance probabilities.
  :param log_scale: Total log probability of acceptance.
class_docstr_tok: ["Rejection","sampled","distribution","given","an","acceptance","rate","function",".",":","param","Distribution","propose",":","A","proposal","distribution","that","samples","batched","proposals","via","``","propose","(",")","``",".",":","meth",":","`","rsample","`","supports","a","``","sample_shape","``","arg","only","if","``","propose","(",")","``","supports","a","``","sample_shape","``","arg",".",":","param","callable","log_prob_accept",":","A","callable","that","inputs","a","batch","of","proposals","and","returns","a","batch","of","log","acceptance","probabilities",".",":","param","log_scale",":","Total","log","probability","of","acceptance","."]
code: def rsample(self, sample_shape=torch.Size()):
      # Implements parallel batched accept-reject sampling.
      x = self.propose(sample_shape) if sample_shape else self.propose()
      log_prob_accept = self.log_prob_accept(x)
      probs = torch.exp(log_prob_accept).clamp_(0.0, 1.0)
      done = torch.bernoulli(probs).bool()
      while not done.all():
          proposed_x = (
              self.propose(sample_shape)
              if sample_shape
              else self.propose()
          )
          log_prob_accept = self.log_prob_accept(proposed_x)
          prob_accept = torch.exp(log_prob_accept).clamp_(0.0, 1.0)
          accept = torch.bernoulli(prob_accept).bool() & ~done
          if accept.any():
              x[accept] = proposed_x[accept]
              done |= accept
      return x
  
file_path: pyro/pyro/distributions/rejector.py
imports: import torch
  from pyro.distributions.score_parts import ScoreParts
  from pyro.distributions.torch_distribution import TorchDistribution
label_desc: Use image node_id 4 for calling the Rejector obj's underlying member method code with example usage: obj.rsample(sample_shape) and returns: x