code: def check_nth_order_unary(
      x, op, grad_ops, orders, rtol=None, atol=None
  ):
      """Assert n-th order autograd gradient against expected gradient.
  
      Multiple order of gradients can be checked by passing list of
      function computing the particular order gradient and passing the
      corresponding list of order.
  
      Note
      ----
      1. Orders should always be monotonically increasing.
      2. Elements of grads_ops should correspond to elements of orders
      i.e. grads_op = [grad_op, grad_grad_grad_op] should be passed with
           orders = [1, 3]
  
      Parameters
      ----------
      x : mxnet.NDArray
          Input Array.
      op : Callable
          Operation to perform on Input Array.
      grad_ops : Callable or List of Callable
          Function to compute and assert gradient of given order.
      orders : int or List of int
          Order/s to assert expected and computed gradients.
  
      Returns
      -------
      None
  
      """
      if isinstance(orders, int):
          orders = [orders]
          grad_ops = [grad_ops]
  
      assert all(
          i < j for i, j in zip(orders[0:-1], orders[1:])
      ), "orders should be monotonically increasing"
      assert len(set(orders)) == len(
          orders
      ), "orders should have unique elements"
      highest_order = max(orders)
  
      x = nd.array(x)
      x.attach_grad()
  
      expected_grads = [grad_op(x) for grad_op in grad_ops]
      computed_grads = []
      head_grads = []
  
      # Perform compute.
      with autograd.record():
          y = op(x)
          for current_order in range(1, highest_order + 1):
              head_grad = nd.random.normal(shape=x.shape)
              y = autograd.grad(
                  heads=y,
                  variables=x,
                  head_grads=head_grad,
                  create_graph=True,
                  retain_graph=True,
              )[0]
              if current_order in orders:
                  computed_grads.append(y)
              head_grads.append(head_grad)
  
      # Validate all the gradients.
      for order, grad, computed_grad in zip(
          orders, expected_grads, computed_grads
      ):
          # Compute expected values.
          expected_grad = grad.asnumpy()
          for head_grad in head_grads[:order]:
              expected_grad *= head_grad.asnumpy()
  
          assert_almost_equal(
              expected_grad,
              computed_grad.asnumpy(),
              rtol=rtol,
              atol=atol,
          )
  
imports: import math
  import random
  from functools import reduce
  from operator import mul
  import random
  from common import xfail_when_nonstandard_decimal_separator
  import mxnet
  from mxnet import nd, autograd, gluon
  from mxnet.test_utils import assert_almost_equal, random_arrays, random_uniform_arrays, rand_shape_nd, same
label_desc: Use image node_id 31 for calling a global function with example usage: check_nth_order_unary(x, op, grad_ops, orders, rtol, atol) without return types