code: def test_ctc_loss():
      loss = gluon.loss.CTCLoss()
      l = loss(
          mx.np.ones((2, 20, 4)),
          mx.np.array([[1, 0, -1, -1], [2, 1, 1, -1]]),
      )
      assert_almost_equal(l, onp.array([18.82820702, 16.50581741]))
  
      loss = gluon.loss.CTCLoss(layout="TNC")
      l = loss(
          mx.np.ones((20, 2, 4)),
          mx.np.array([[1, 0, -1, -1], [2, 1, 1, -1]]),
      )
      assert_almost_equal(l, onp.array([18.82820702, 16.50581741]))
  
      loss = gluon.loss.CTCLoss(layout="TNC", label_layout="TN")
      l = loss(
          mx.np.ones((20, 2, 4)),
          mx.np.array([[1, 0, -1, -1], [2, 1, 1, -1]]).T,
      )
      assert_almost_equal(l, onp.array([18.82820702, 16.50581741]))
  
      loss = gluon.loss.CTCLoss()
      l = loss(
          mx.np.ones((2, 20, 4)),
          mx.np.array([[2, 1, 2, 2], [3, 2, 2, 2]]),
          None,
          mx.np.array([2, 3]),
      )
      assert_almost_equal(l, onp.array([18.82820702, 16.50581741]))
  
      loss = gluon.loss.CTCLoss()
      l = loss(
          mx.np.ones((2, 25, 4)),
          mx.np.array([[2, 1, -1, -1], [3, 2, 2, -1]]),
          mx.np.array([20, 20]),
      )
      assert_almost_equal(l, onp.array([18.82820702, 16.50581741]))
  
      loss = gluon.loss.CTCLoss()
      l = loss(
          mx.np.ones((2, 25, 4)),
          mx.np.array([[2, 1, 3, 3], [3, 2, 2, 3]]),
          mx.np.array([20, 20]),
          mx.np.array([2, 3]),
      )
      assert_almost_equal(l, onp.array([18.82820702, 16.50581741]))
  
file_path: mxnet/tests/python/unittest/test_loss.py
imports: import mxnet
  import numpy
  from mxnet import gluon, autograd
  from mxnet.test_utils import assert_almost_equal, default_device
  from numpy.core.fromnumeric import size
  from common import xfail_when_nonstandard_decimal_separator
  import unittest
label_desc: Use image node_id 4 for calling a global function with example usage: test_ctc_loss() without return types