code: def _check_gradient(self, s, *input_shapes):
      with self.cached_session():
          r = np.random.RandomState(seed=0)
          for dtype in (
              np.float32,
              np.float64,
              np.complex64,
              np.complex128,
          ):
              with self.subTest(s=s, dtype=dtype):
                  tol = 10 * np.sqrt(np.finfo(dtype).resolution)
                  if dtype in (np.complex64, np.complex128):
                      inputs = [
                          np.array(r.randn(*shape), dtype)
                          + 1j * np.array(r.randn(*shape), dtype)
                          for shape in input_shapes
                      ]
                  else:
                      inputs = [
                          np.array(r.randn(*shape), dtype)
                          for shape in input_shapes
                      ]
                  input_tensors = [
                      constant_op.constant(x, shape=x.shape)
                      for x in inputs
                  ]
                  (
                      analytical,
                      numerical,
                  ) = gradient_checker_v2.compute_gradient(
                      lambda *xs: gen_linalg_ops.einsum(xs, s),
                      input_tensors,
                  )
                  self.assertLess(
                      gradient_checker_v2.max_error(
                          analytical, numerical
                      ),
                      tol,
                  )
  
imports: import numpy
  from tensorflow.python.client import session
  from tensorflow.python.framework import constant_op
  from tensorflow.python.framework import dtypes
  from tensorflow.python.framework import errors
  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 gen_linalg_ops
  from tensorflow.python.ops import gradient_checker_v2
  from tensorflow.python.ops import special_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 EinsumGradTest obj's underlying member method code with example usage: obj._check_gradient(s) without return types