code: def test_op_cross_entropy_with_soft_max_and_axis(
      output_vector, target_vector, axis, device_id, precision
  ):
      dt = PRECISION_TO_TYPE[precision]
  
      x = AA(output_vector, dtype=dt)
      t = AA(target_vector, dtype=dt)
  
      expected_forward = []
      expected_backward_left = []
      expected_backward_right = []
  
      for sample, target in zip(x, t):
          ox = sample - sample.max()  # subtract max to avoid overflow
          exp_x = np.exp(ox)
          s_max = exp_x / np.sum(exp_x)  # softmax function
          forward = np.asarray(
              -np.sum(target * np.log(s_max, dtype=dt), dtype=dt)
          )
          expected_forward.append(forward.tolist())
  
          s = np.sum(target, dtype=dt)
          backward = np.subtract(s_max * s, target)
  
          expected_backward_left.append(backward.tolist())
          expected_backward_right.append(-1 * sample)
  
      expected_forward = [
          np.reshape(AA(expected_forward, dtype=dt), (x.shape[0], 1))
      ]
      expected_backward_left = AA(expected_backward_left, dtype=dt)
  
      expected_backward = {
          "left_arg": [expected_backward_left],
          "right_arg": [expected_backward_right],
      }
  
      from cntk.losses import cross_entropy_with_softmax
  
      _test_binary_op(
          precision,
          device_id,
          cross_entropy_with_softmax,
          output_vector,
          target_vector,
          expected_forward,
          expected_backward,
          op_param_dict={"axis": axis},
      )
  
file_path: CNTK/bindings/python/cntk/losses/tests/losses_test.py
imports: from __future__ import division
  import numpy
  import pytest
  import cntk
  from cntk.ops.tests.ops_test_utils import _test_binary_op, AA, precision, PRECISION_TO_TYPE, unittest_helper
label_desc: Use image node_id 2 for calling a global function with example usage: test_op_cross_entropy_with_soft_max_and_axis(output_vector, target_vector, axis, device_id, precision) without return types