code: def test_op_softmax(sample, device_id, precision):
      t = AA(sample, dtype=PRECISION_TO_TYPE[precision])
      assert len(t.shape) == 1
  
      x_max = t - t.max()
      exp_x = np.exp(x_max)
      forward = exp_x / np.sum(exp_x)
  
      expected_forward = AA([forward])
  
      sample_length = len(forward)
      grad = np.zeros(
          (sample_length, sample_length),
          dtype=PRECISION_TO_TYPE[precision],
      )
  
      for i in range(sample_length):
          for j in range(sample_length):
              if i == j:
                  grad[i, j] = forward[i] * (1 - forward[i])
              else:
                  grad[i, j] = -1 * forward[j] * forward[i]
  
      backward = grad.sum(axis=0)
  
      expected_backward = {"arg": [backward]}
  
      from cntk import softmax
  
      _test_unary_op(
          precision,
          device_id,
          softmax,
          sample,
          expected_forward,
          expected_backward,
      )
  
imports: from __future__ import division
  import numpy
  import cntk
  import pytest
  from .ops_test_utils import unittest_helper, _test_unary_op, _test_binary_op, AA, precision, PRECISION_TO_TYPE, cntk_device
  from cntk.tests.test_utils import TOLERANCE_ABSOLUTE
  from cntk.internal.utils import eval
  from cntk.internal import sanitize_dtype_cntk
  from ..None import constant
  from cntk.variables import Parameter, Constant
label_desc: Use image node_id 22 for calling a global function with example usage: test_op_softmax(sample, device_id, precision) without return types