code: def test_op_slice(
      input_data, slice_params, expected_result, device_id, precision
  ):
      input_data = AA(input_data, dtype=PRECISION_TO_TYPE[precision])
  
      def _ax_slices(x, beg_index, end_index, axis, strides):
          """
          Creates a NumPy slicing array from slice operator's arguments
          """
          ax_slices = []
          for i in range(0, len(x.shape)):
              if i == axis:
                  if end_index >= x.shape[i]:
                      ax_slices.append(
                          slice(beg_index, None, abs(strides))
                      )
                  else:
                      ax_slices.append(
                          slice(beg_index, end_index, abs(strides))
                      )
              else:
                  ax_slices.append(slice(None))  # corresponds to ':'
          return ax_slices
  
      # Backward pass test
      # ==================
      # The gradient of the slice operator is a tensor of the same shape as the
      # input tensor, having 1 for elements that were taken and 0 for elements
      # that were dropped.
  
      def grad_slice(x, beg_index, end_index, axis, strides):
          res = np.zeros_like(x)
          ax_slices = _ax_slices(x, beg_index, end_index, axis, strides)
          res[ax_slices] = x[ax_slices]
          res[res != 0] = 1
          return res
  
      expected_forward = AA(
          [expected_result], dtype=PRECISION_TO_TYPE[precision]
      )
      expected_backward = {
          "arg": [grad_slice(np.asarray(input_data), *slice_params)]
      }
  
      _test_unary_op(
          precision,
          device_id,
          C.slice,
          input_data,
          expected_forward,
          expected_backward,
          {
              "begin_index": slice_params[0],
              "end_index": slice_params[1],
              "axis": slice_params[2],
              "strides": slice_params[3],
          },
      )
  
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
  import cntk
  from cntk import Value
  from cntk.axis import Axis
  from cntk.internal import sanitize_dtype_cntk
  from ..None import constant
label_desc: Use image node_id 5 for calling a global function with example usage: test_op_slice(input_data, slice_params, expected_result, device_id, precision) and returns: ax_slices, res