code: def test_custom_op():
      # possible places to find library file
      if os.name == "posix":
          lib = "libcustomop_lib.so"
          if os.path.exists(lib):
              fname = lib
          elif os.path.exists(os.path.join(base_path, "build/" + lib)):
              fname = os.path.join(base_path, "build/" + lib)
          else:
              raise MXNetError(f"library {lib} not found ")
      elif os.name == "nt":
          lib = "libcustomop_lib.dll"
          if os.path.exists("windows_package\\lib\\" + lib):
              fname = "windows_package\\lib\\" + lib
          else:
              raise MXNetError(f"library {lib} not found ")
  
      fname = os.path.abspath(fname)
      # load the library containing gemm custom operators
      mx.library.load(fname)
  
      # test symbol 2D gemm custom operators
      s = mx.sym.Variable("s")
      t = mx.sym.Variable("t")
      c = mx.sym.my_gemm(s, t)
      d = mx.sym.state_gemm(s, t)
      # baseline gemm from MXNet
      base = mx.sym.linalg.gemm2(s, t)
  
      # get some random input matrices
      dim_n, dim_k, dim_m = tuple(np.random.randint(1, 5, size=3))
      mat1 = mx.nd.random.uniform(
          -10, 10, shape=(dim_n, dim_k), ctx=mx.cpu()
      )
      mat2 = mx.nd.random.uniform(
          -10, 10, shape=(dim_k, dim_m), ctx=mx.cpu()
      )
  
      # intermediate ndarrays to be populated by gradient compute
      in_grad1 = [
          mx.nd.empty((dim_n, dim_k), ctx=mx.cpu()),
          mx.nd.empty((dim_k, dim_m), ctx=mx.cpu()),
      ]
      in_grad2 = [
          mx.nd.empty((dim_n, dim_k), ctx=mx.cpu()),
          mx.nd.empty((dim_k, dim_m), ctx=mx.cpu()),
      ]
      in_grad_base = [
          mx.nd.empty((dim_n, dim_k), ctx=mx.cpu()),
          mx.nd.empty((dim_k, dim_m), ctx=mx.cpu()),
      ]
  
      exe1 = c._bind(
          ctx=mx.cpu(), args={"s": mat1, "t": mat2}, args_grad=in_grad1
      )
      exe2 = d._bind(
          ctx=mx.cpu(), args={"s": mat1, "t": mat2}, args_grad=in_grad2
      )
      exe_base = base._bind(
          ctx=mx.cpu(),
          args={"s": mat1, "t": mat2},
          args_grad=in_grad_base,
      )
  
      out1 = exe1.forward()
      out2 = exe2.forward()
      # test stateful operator by calling it multiple times
      out2 = exe2.forward()
      out_base = exe_base.forward()
  
      # check that forward compute matches one executed by MXNet
      assert_almost_equal(
          out_base[0].asnumpy(), out1[0].asnumpy(), rtol=1e-3, atol=1e-3
      )
      assert_almost_equal(
          out_base[0].asnumpy(), out2[0].asnumpy(), rtol=1e-3, atol=1e-3
      )
  
      # random output grad ndarray for gradient update
      out_grad = mx.nd.ones((dim_n, dim_m), ctx=mx.cpu())
      exe1.backward([out_grad])
      exe2.backward([out_grad])
      exe_base.backward([out_grad])
  
      # check that gradient compute matches one executed by MXNet
      assert_almost_equal(
          in_grad_base[0].asnumpy(),
          in_grad1[0].asnumpy(),
          rtol=1e-3,
          atol=1e-3,
      )
      assert_almost_equal(
          in_grad_base[0].asnumpy(),
          in_grad2[0].asnumpy(),
          rtol=1e-3,
          atol=1e-3,
      )
  
file_path: mxnet/tests/python/unittest/test_extensions.py
imports: import os
  import platform
  import mxnet
  import numpy
  from mxnet import nd
  from mxnet.gluon import nn
  from mxnet.base import MXNetError
  from mxnet.test_utils import download, is_cd_run, assert_almost_equal, default_device
  import pytest
label_desc: Use image node_id 2 for calling a global function with example usage: test_custom_op() without return types