code: def test_rejector(rate, factor):
      num_samples = 200000
      rates = torch.tensor(rate).expand(num_samples, 1)
      factors = torch.tensor(factor).expand(num_samples, 1)
  
      dist1 = Exponential(rates)
      dist2 = RejectionExponential(
          rates, factors
      )  # implemented using Rejector
      x1 = dist1.rsample()
      x2 = dist2.rsample()
      assert_equal(
          x1.mean(), x2.mean(), prec=0.03, msg="bug in .rsample()"
      )
      assert_equal(
          x1.std(), x2.std(), prec=0.03, msg="bug in .rsample()"
      )
      assert_equal(
          dist1.log_prob(x1),
          dist2.log_prob(x1),
          msg="bug in .log_prob()",
      )
  
file_path: pyro/tests/distributions/test_rejector.py
imports: import pytest
  import torch
  from torch.autograd import grad
  from pyro.distributions import Exponential, Gamma
  from pyro.distributions.testing.rejection_exponential import RejectionExponential
  from pyro.distributions.testing.rejection_gamma import RejectionGamma, RejectionStandardGamma, ShapeAugmentedBeta, ShapeAugmentedGamma
  from tests.common import assert_equal
label_desc: Use image node_id 4 for calling a global function with example usage: test_rejector(rate, factor) without return types