code: def test_gluon_geometric():
      class TestGeometric(HybridBlock):
          def __init__(self, func, is_logit=False):
              super(TestGeometric, self).__init__()
              self._is_logit = is_logit
              self._func = func
  
          def forward(self, params, *args):
              dist = (
                  mgp.Geometric(logit=params, validate_args=True)
                  if self._is_logit
                  else mgp.Geometric(prob=params, validate_args=True)
              )
              return _distribution_method_invoker(
                  dist, self._func, *args
              )
  
      shapes = [(), (1,), (2, 3), 6]
      # Test log_prob
      for shape, hybridize, use_logit in itertools.product(
          shapes, [True, False], [True, False]
      ):
          prob = np.random.uniform(size=shape)
          sample = np.random.randint(0, 10, size=shape).astype(
              "float32"
          )
          param = prob
          if use_logit:
              param = prob_to_logit(param)
          net = TestGeometric("log_prob", use_logit)
          if hybridize:
              net.hybridize()
          mx_out = net(param, sample).asnumpy()
          np_out = ss.geom.logpmf(sample.asnumpy() + 1, prob.asnumpy())
          assert_almost_equal(
              mx_out, np_out, atol=1e-4, rtol=1e-3, use_broadcast=False
          )
  
      # Test variance
      for shape, hybridize, use_logit in itertools.product(
          shapes, [True, False], [True, False]
      ):
          prob = np.random.uniform(size=shape)
          param = prob
          if use_logit:
              param = prob_to_logit(param)
          net = TestGeometric("variance", use_logit)
          if hybridize:
              net.hybridize()
          mx_out = net(param).asnumpy()
          np_out = ss.geom(prob.asnumpy()).var()
          assert_almost_equal(
              mx_out, np_out, atol=1e-4, rtol=1e-3, use_broadcast=False
          )
  
      # Test entropy
      for shape, hybridize, use_logit in itertools.product(
          shapes, [True, False], [True, False]
      ):
          # Add lower bound constraint, otherwise scipy would raise warning.
          prob = np.random.uniform(low=0.1, size=shape)
          param = prob
          if use_logit:
              param = prob_to_logit(param)
          net = TestGeometric("entropy", use_logit)
          if hybridize:
              net.hybridize()
          mx_out = net(param).asnumpy()
          np_out = ss.geom(prob.asnumpy()).entropy()
          assert_almost_equal(
              mx_out, np_out, atol=1e-4, rtol=1e-3, use_broadcast=False
          )
  
imports: import mxnet
  import numpy
  from mxnet import np, npx, autograd
  from mxnet import gluon
  import mxnet.gluon.probability
  from mxnet.gluon.probability import StochasticBlock, StochasticSequential
  from mxnet.gluon import HybridBlock
  from mxnet.test_utils import use_np, assert_almost_equal
  from numpy.testing import assert_array_equal
  import pytest
  import scipy.stats
  import scipy.special
  import itertools
  from numbers import Number
label_desc: Use image node_id 9 for calling a global function with example usage: test_gluon_geometric() and returns: _distribution_method_invoker