code: def test_log_prob(batch_shape, dim):
      loc = torch.randn(batch_shape + (dim,))
      A = torch.randn(batch_shape + (dim, dim + dim))
      scale_tril = torch.linalg.cholesky(A.matmul(A.transpose(-2, -1)))
      x = torch.randn(batch_shape + (dim,))
      df = torch.randn(batch_shape).exp() + 2
      actual_log_prob = MultivariateStudentT(
          df, loc, scale_tril
      ).log_prob(x)
  
      if dim == 1:
          expected_log_prob = (
              StudentT(df.unsqueeze(-1), loc, scale_tril[..., 0])
              .log_prob(x)
              .sum(-1)
          )
          assert_equal(actual_log_prob, expected_log_prob)
  
      # test the fact MVT(df, loc, scale)(x) = int MVN(loc, scale / m)(x) Gamma(df/2,df/2)(m) dm
      num_samples = 100000
      gamma_samples = Gamma(df / 2, df / 2).sample(
          sample_shape=(num_samples,)
      )
      mvn_scale_tril = scale_tril / gamma_samples.sqrt().unsqueeze(
          -1
      ).unsqueeze(-1)
      mvn = MultivariateNormal(loc, scale_tril=mvn_scale_tril)
      expected_log_prob = mvn.log_prob(x).logsumexp(0) - math.log(
          num_samples
      )
      assert_equal(actual_log_prob, expected_log_prob, prec=0.01)
  
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 3 for calling a global function with example usage: test_log_prob(batch_shape, dim) without return types