code: def test_gradient_against_estimate(dtype):
      """check sparsemax-loss Rop, against estimated-loss Rop."""
      random = np.random.RandomState(7)
  
      # sparsemax is not a smooth function so gradient estimation is only
      # possible for float64.
      if dtype != "float64":
          return
  
      z = random.uniform(low=-3, high=3, size=(test_obs, 10)).astype(
          dtype
      )
      q = np.zeros((test_obs, 10)).astype(dtype)
      q[
          np.arange(0, test_obs),
          np.random.randint(0, 10, size=test_obs),
      ] = 1
  
      (jacob_sym,), (jacob_num,) = tf.test.compute_gradient(
          lambda logits: sparsemax_loss(logits, sparsemax(logits), q),
          [z],
      )
      test_utils.assert_allclose_according_to_type(jacob_sym, jacob_num)
  
file_path: addons/tensorflow_addons/losses/tests/sparsemax_loss_test.py
imports: import pytest
  from packaging.version import Version
  import tensorflow
  import numpy
  from tensorflow_addons.activations import sparsemax
  from tensorflow_addons.losses import sparsemax_loss, SparsemaxLoss
  from tensorflow_addons.utils import test_utils
label_desc: Use image node_id 4 for calling a global function with example usage: test_gradient_against_estimate(dtype) without return types