code: def test_rsample(dim, df, num_samples=200 * 1000):
      scale_tril = (
          0.5 * torch.randn(dim)
      ).exp().diag() + 0.1 * torch.randn(dim, dim)
      scale_tril = scale_tril.tril(0)
      scale_tril.requires_grad_(True)
  
      d = MultivariateStudentT(
          torch.tensor(df), torch.zeros(dim), scale_tril
      )
      z = d.rsample(sample_shape=(num_samples,))
      loss = z.pow(2.0).sum(-1).mean()
      loss.backward()
  
      actual_scale_tril_grad = scale_tril.grad.data.clone()
      scale_tril.grad.zero_()
  
      analytic = (df / (df - 2.0)) * torch.mm(
          scale_tril, scale_tril.t()
      ).diag().sum()
      analytic.backward()
      expected_scale_tril_grad = scale_tril.grad.data
  
      assert_equal(
          expected_scale_tril_grad, actual_scale_tril_grad, prec=0.1
      )
  
file_path: pyro/tests/distributions/test_mvt.py
imports: import math
  import pytest
  import torch
  from torch.distributions import Gamma, MultivariateNormal, StudentT
  from pyro.distributions import MultivariateStudentT
  from tests.common import assert_equal
label_desc: Use image node_id 4 for calling a global function with example usage: test_rsample(dim, df, num_samples) without return types