code: def test_sparse_unary_with_numerics():
      def check_sparse_simple(
          name,
          stype,
          mxnet_func,
          forward_numpy_call,
          backward_numpy_call,
          output_grad_stype=None,
          backward_is_use_output=False,
      ):
          if output_grad_stype is None:
              output_grad_stype = stype
  
          (
              expected_result_type,
              expected_grad_result_type,
          ) = get_fw_bw_result_types_2(
              forward_numpy_call,
              stype,
              backward_numpy_call,
              output_grad_stype,
          )
          if backward_is_use_output is True:
              expected_grad_result_type = expected_result_type
  
          shape = (3, 4)
          data = mx.symbol.Variable("data")
  
          grad_stypes = {"data": expected_grad_result_type}
  
          y = mxnet_func(data)
          if stype == "default":
              xa = np.random.uniform(low=-1.0, high=1.0, size=shape)
              xa_np = xa
          else:
              xa = create_sparse_array(
                  shape,
                  stype,
                  data_init=None,
                  rsp_indices=[1],
                  modifier_func=lambda a: a - 0.5,
                  shuffle_csr_indices=True,
              )
              xa_np = xa.asnumpy()
  
          if output_grad_stype != "default":
              out_grad = create_sparse_array(
                  shape,
                  output_grad_stype,
                  data_init=None,
                  rsp_indices=[1, 2],
                  modifier_func=lambda a: a - 0.5,
                  shuffle_csr_indices=True,
              )
              out_grad_np = out_grad.asnumpy()
          else:
              out_grad_np = np.ones(xa.shape)
              out_grad = mx.nd.array(out_grad_np)
  
          output_np = forward_numpy_call(xa_np)
          input_grad_np = backward_numpy_call(output_np, out_grad_np)
  
          outputs = check_symbolic_forward(y, [xa], [output_np])
          output = outputs[0]
  
          assert output.stype == expected_result_type
  
          input_grad_dict = check_symbolic_backward(
              y,
              location=[xa],
              out_grads=[out_grad],
              expected=[input_grad_np],
              grad_stypes=grad_stypes,
          )
          inp_grad = input_grad_dict["data"]
  
          assert inp_grad.stype == expected_grad_result_type
  
      def check_sparse_function(
          name,
          mxnet_func,
          forward_numpy_call,
          backward_numpy_call,
          backward_is_use_output=False,
      ):
          check_sparse_simple(
              name,
              "default",
              mxnet_func,
              forward_numpy_call,
              backward_numpy_call,
          )
          for output_grad_stype in [None, "row_sparse", "default"]:
              check_sparse_simple(
                  name,
                  "row_sparse",
                  mxnet_func,
                  forward_numpy_call,
                  backward_numpy_call,
                  output_grad_stype=output_grad_stype,
                  backward_is_use_output=backward_is_use_output,
              )
  
          for output_grad_stype in [None, "csr", "default"]:
              check_sparse_simple(
                  name,
                  "csr",
                  mxnet_func,
                  forward_numpy_call,
                  backward_numpy_call,
                  output_grad_stype=output_grad_stype,
                  backward_is_use_output=backward_is_use_output,
              )
  
      check_sparse_function(
          "relu",
          lambda x: mx.sym.relu(x),
          lambda x: np.maximum(x, 0.0),
          lambda output, outg: outg
          * assign_each(output, lambda x: x > 0.0),
          backward_is_use_output=True,
      )
  
      check_sparse_function(
          "sigmoid",
          lambda x: mx.sym.sigmoid(x),
          lambda x: np.divide(1.0, (1.0 + np.exp(-x))),
          lambda output, outg: outg
          * assign_each(output, lambda x: x * (1.0 - x)),
          backward_is_use_output=True,
      )
  
imports: from mxnet.test_utils import *
  from mxnet.base import MXNetError
  import pytest
  from common import assertRaises
  import random
  import warnings
label_desc: Use image node_id 23 for calling a global function with example usage: test_sparse_unary_with_numerics() without return types