code: def test_moments(shape):
      df = torch.empty(shape).uniform_(1.8, 5).requires_grad_()
      loc = torch.empty(shape).uniform_(-1.0, 1.0).requires_grad_()
      scale = torch.empty(shape).uniform_(0.5, 1.0).requires_grad_()
      params = [df, loc, scale]
  
      def model():
          with pyro.plate_stack("plates", shape):
              with pyro.plate("particles", 100000):
                  return pyro.sample("x", dist.StudentT(df, loc, scale))
  
      value = model()
      expected_moments = get_moments(value)
  
      reparam_model = poutine.reparam(model, {"x": StudentTReparam()})
      trace = poutine.trace(reparam_model).get_trace()
      assert isinstance(trace.nodes["x"]["fn"], dist.Normal)
      trace.compute_log_prob()  # smoke test only
      value = trace.nodes["x"]["value"]
      actual_moments = get_moments(value)
      assert_close(actual_moments, expected_moments, atol=0.05)
  
      for actual_m, expected_m in zip(actual_moments, expected_moments):
          expected_grads = grad(
              expected_m.sum(), params, retain_graph=True
          )
          actual_grads = grad(actual_m.sum(), params, retain_graph=True)
          assert_close(actual_grads[0], expected_grads[0], atol=0.2)
          assert_close(actual_grads[1], expected_grads[1], atol=0.1)
          assert_close(actual_grads[2], expected_grads[2], atol=0.1)
  
file_path: pyro/tests/infer/reparam/test_studentt.py
imports: import pytest
  import torch
  from scipy.stats import ks_2samp
  from torch.autograd import grad
  import pyro
  import pyro.distributions
  from pyro import poutine
  from pyro.infer.reparam import StudentTReparam
  from tests.common import assert_close
  from .util import check_init_reparam
label_desc: Use image node_id 2 for calling a global function with example usage: test_moments(shape) and returns: pyro