code: def test_gluon_bernoulli():
      class TestBernoulli(HybridBlock):
          def __init__(self, func, is_logit=False):
              super(TestBernoulli, self).__init__()
              self._is_logit = is_logit
              self._func = func
  
          def forward(self, params, *args):
              bernoulli = (
                  mgp.Bernoulli(logit=params, validate_args=True)
                  if self._is_logit
                  else mgp.Bernoulli(prob=params, validate_args=True)
              )
              return _distribution_method_invoker(
                  bernoulli, self._func, *args
              )
  
      # Test log_prob
      shapes = [(), (1,), (2, 3), 6]
      for shape, hybridize, use_logit in itertools.product(
          shapes, [True, False], [True, False]
      ):
          prob = np.random.uniform(size=shape)
          sample = npx.random.bernoulli(prob=0.5, size=shape)
          param = prob
          if use_logit:
              param = prob_to_logit(param)
          net = TestBernoulli("log_prob", use_logit)
          if hybridize:
              net.hybridize()
          mx_out = net(param, sample).asnumpy()
          np_out = _np.log(
              ss.bernoulli.pmf(sample.asnumpy(), 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)
          sample = npx.random.bernoulli(prob=0.5, size=shape)
          param = prob
          if use_logit:
              param = prob_to_logit(param)
          net = TestBernoulli("variance", use_logit)
          if hybridize:
              net.hybridize()
          mx_out = net(param).asnumpy()
          np_out = ss.bernoulli(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]
      ):
          prob = np.random.uniform(size=shape)
          sample = npx.random.bernoulli(prob=0.5, size=shape)
          param = prob
          if use_logit:
              param = prob_to_logit(param)
          net = TestBernoulli("entropy", use_logit)
          if hybridize:
              net.hybridize()
          mx_out = net(param).asnumpy()
          np_out = ss.bernoulli(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 22 for calling a global function with example usage: test_gluon_bernoulli() and returns: _distribution_method_invoker