code: def _checkGrad(self, x_in, y_in, adjoint_a, adjoint_b):
      x_t_shape = x_in.shape[:-2] + (x_in.shape[-1], x_in.shape[-2])
      y_t_shape = y_in.shape[:-2] + (y_in.shape[-1], y_in.shape[-2])
      x = x_in if not adjoint_a else x_in.reshape(x_t_shape)
      y = y_in if not adjoint_b else y_in.reshape(y_t_shape)
      # np.finfo doesn't support bfloat16. So, we manually compute the eps which
      # defines the difference between 1.0 and the next smallest representable
      # float larger than 1.0. For bfloat16, the difference is 1/128.
      if x.dtype == dtypes.bfloat16.as_numpy_dtype:
          epsilon = 0.0078125
      else:
          epsilon = np.finfo(x.dtype).eps
      # Since our gradient is linear, a larger delta decreases the error.
      delta = 10 * epsilon ** (1.0 / 3.0)
  
      def Loss(x, y):
          z = math_ops.matmul(x, y, adjoint_a, adjoint_b)
          # To avoid the high error when reduce_sum over the bfloat16 values, we
          # cast the results to float32.
          if z.dtype == dtypes.bfloat16:
              z = math_ops.cast(z, dtype=dtypes.float32)
          return math_ops.reduce_sum(z)
  
      with self.cached_session():
          (
              (x_jacob_t, y_jacob_t),
              (x_jacob_n, y_jacob_n),
          ) = gradient_checker_v2.compute_gradient(
              Loss, [x, y], delta=delta
          )
          tol = 10 * delta
          self.assertAllClose(x_jacob_t, x_jacob_n, rtol=tol, atol=tol)
          self.assertAllClose(y_jacob_t, y_jacob_n, rtol=tol, atol=tol)
  
imports: import numpy
  from tensorflow.python import tf2
  from tensorflow.python.client import session
  from tensorflow.python.framework import dtypes
  from tensorflow.python.framework import ops
  from tensorflow.python.framework import test_util
  from tensorflow.python.ops import array_ops
  from tensorflow.python.ops import gradient_checker_v2
  from tensorflow.python.ops import math_ops
  from tensorflow.python.ops import variables
  from tensorflow.python.platform import benchmark
  from tensorflow.python.platform import test
label_desc: Use image node_id 1 for calling the BatchMatmulGradientTest obj's underlying member method code with example usage: obj._checkGrad(x_in, y_in, adjoint_a, adjoint_b) and returns: math_ops