code: def test_sampling(distr_class, params, serialize_fn) -> None:
      distr = distr_class(**params)
      distr = serialize_fn(distr)
      samples = distr.sample()
      assert samples.shape == (2,)
      num_samples = 1_000_000
      samples = distr.sample(num_samples)
      assert samples.shape == (num_samples, 2)
  
      np_samples = samples.asnumpy()
      # avoid accuracy issues with float32 when calculating std
      # see https://github.com/numpy/numpy/issues/8869
      np_samples = np_samples.astype(np.float64)
  
      assert np.isfinite(np_samples).all()
      assert np.allclose(
          np_samples.mean(axis=0),
          distr.mean.asnumpy(),
          atol=1e-2,
          rtol=1e-2,
      )
  
      if distr_class not in DISTRIBUTIONS_WITHOUT_STDDEV:
          emp_std = np_samples.std(axis=0)
          assert np.allclose(
              emp_std, distr.stddev.asnumpy(), atol=1e-1, rtol=1e-1
          )
  
      if distr_class in DISTRIBUTIONS_WITH_CDF:
          emp_cdf, edges = empirical_cdf(np_samples)
          calc_cdf = distr.cdf(mx.nd.array(edges)).asnumpy()
          assert np.allclose(calc_cdf[1:, :], emp_cdf, atol=1e-2)
  
      if distr_class in DISTRIBUTIONS_WITH_QUANTILE_FUNCTION:
          levels = np.linspace(1.0e-3, 1.0 - 1.0e-3, 100)
          emp_qfunc = np.percentile(np_samples, levels * 100, axis=0)
          calc_qfunc = distr.quantile(mx.nd.array(levels)).asnumpy()
          assert np.allclose(calc_qfunc, emp_qfunc, rtol=1e-1)
  
file_path: gluonts/test/mx/distribution/test_distribution_sampling.py
imports: import mxnet
  import numpy
  import pytest
  from flaky import flaky
  from gluonts.core.serde import dump_json, load_json
  from gluonts.mx.model.tpp.distribution import Loglogistic, Weibull
  from gluonts.mx.distribution import Beta, Binned, Categorical, Dirichlet, DirichletMultinomial, Gamma, Gaussian, GenPareto, Laplace, MultivariateGaussian, NegativeBinomial, PiecewiseLinear, Poisson, StudentT, Uniform, ZeroAndOneInflatedBeta
  from gluonts.testutil import empirical_cdf
label_desc: Use image node_id 1 for calling a global function with example usage: test_sampling(distr_class, params, serialize_fn) without return types