code: def test_sparsemax_loss_of_inf(dtype):
      """check sparsemax-loss is infinity safe."""
      q = np.asarray([[0, 0, 1], [0, 0, 1], [0, 0, 1], [0, 0, 1]])
      z_neg = np.asarray(
          [
              [0, -np.inf, 0],
              [0, -np.inf, -np.inf],
              [-np.inf, -np.inf, 0],
              [-np.inf, -np.inf, -np.inf],
          ]
      ).astype(dtype)
      z_pos = np.asarray(
          [
              [0, np.inf, 0],
              [0, np.inf, np.inf],
              [np.inf, np.inf, 0],
              [np.inf, np.inf, np.inf],
          ]
      ).astype(dtype)
      z_mix = np.asarray(
          [
              [0, np.inf, 0],
              [0, np.inf, -np.inf],
              [-np.inf, np.inf, 0],
              [-np.inf, np.inf, -np.inf],
          ]
      ).astype(dtype)
  
      _, tf_loss_neg = _tf_sparsemax_loss(z_neg, q, dtype)
      np.testing.assert_equal(
          np.asanyarray([0.25, np.inf, 0, np.nan]), tf_loss_neg
      )
  
      _, tf_loss_pos = _tf_sparsemax_loss(z_pos, q, dtype)
      np.testing.assert_equal(
          np.asanyarray([np.nan, np.nan, np.nan, np.nan]), tf_loss_pos
      )
  
      _, tf_loss_mix = _tf_sparsemax_loss(z_mix, q, dtype)
      np.testing.assert_equal(
          np.asanyarray([np.nan, np.nan, np.nan, np.nan]), tf_loss_mix
      )
  
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 10 for calling a global function with example usage: test_sparsemax_loss_of_inf(dtype) without return types