code: def _check_index(idx):
      """Check if a given value is a valid index into a tensor."""
      if isinstance(idx, (numbers.Integral, tensor_shape.Dimension)):
          return
  
      # Optimistic check. Assumptions:
      # * any object with a dtype is supported
      # * any object with a dtype has a sizeable shape attribute.
      dtype = getattr(idx, "dtype", None)
      if (
          dtype is None
          or dtypes.as_dtype(dtype) not in _SUPPORTED_SLICE_DTYPES
          or idx.shape
          and len(idx.shape) == 1
      ):
          # TODO(slebedev): IndexError seems more appropriate here, but it
          # will break `_slice_helper` contract.
          raise TypeError(_SLICE_TYPE_ERROR + ", got {!r}".format(idx))
  
file_path: tensorflow/tensorflow/python/ops/tensor_getitem_override.py
imports: import numbers
  import numpy
  from tensorflow.python.framework import dtypes
  from tensorflow.python.framework import ops
  from tensorflow.python.framework import tensor
  from tensorflow.python.framework import tensor_shape
  from tensorflow.python.ops import gen_math_ops
  from tensorflow.python.util import dispatch
  from tensorflow.python.util.tf_export import tf_export
label_desc: Use image node_id 2 for calling a global function with example usage: _check_index(idx) without return types