code: def _ConstantValue(tensor, partial):
      # TODO(touts): Support Variables?
      if not isinstance(tensor, core.Symbol):
          raise TypeError(
              f"{tensor!r} must be a Tensor, but got {type(tensor)}."
          )
      if tensor.op.type == "Const":
          return MakeNdarray(tensor.op.get_attr("value"))
      elif tensor.op.type == "Shape":
          input_shape = tensor.op.inputs[0].get_shape()
          if input_shape.is_fully_defined():
              return np.array(
                  [dim.value for dim in input_shape.dims],
                  dtype=tensor.dtype.as_numpy_dtype,
              )
          else:
              return None
      elif tensor.op.type == "Size":
          input_shape = tensor.op.inputs[0].get_shape()
          if input_shape.is_fully_defined():
              return np.prod(
                  [dim.value for dim in input_shape.dims],
                  dtype=np.int32,
              )
          else:
              return None
      elif tensor.op.type == "Rank":
          input_shape = tensor.op.inputs[0].get_shape()
          if input_shape.ndims is not None:
              return np.ndarray(
                  shape=(),
                  buffer=np.array([input_shape.ndims], dtype=np.int32),
                  dtype=np.int32,
              )
          else:
              return None
      elif tensor.op.type == "Range":
          start = constant_value(tensor.op.inputs[0])
          if start is None:
              return None
          limit = constant_value(tensor.op.inputs[1])
          if limit is None:
              return None
          delta = constant_value(tensor.op.inputs[2])
          if delta is None:
              return None
          return np.arange(
              start, limit, delta, dtype=tensor.dtype.as_numpy_dtype
          )
      elif tensor.op.type == "Cast":
          pre_cast = constant_value(tensor.op.inputs[0])
          if pre_cast is None:
              return None
          cast_dtype = dtypes.as_dtype(tensor.op.get_attr("DstT"))
          return pre_cast.astype(cast_dtype.as_numpy_dtype)
      elif tensor.op.type == "Concat":
          dim = constant_value(tensor.op.inputs[0])
          if dim is None:
              return None
          values = []
          for x in tensor.op.inputs[1:]:
              value = constant_value(x)
              if value is None:
                  return None
              values.append(value)
          return np.concatenate(values, axis=dim)
      elif tensor.op.type == "ConcatV2":
          dim = constant_value(tensor.op.inputs[-1])
          if dim is None:
              return None
          values = []
          for x in tensor.op.inputs[:-1]:
              value = constant_value(x)
              if value is None:
                  return None
              values.append(value)
          return np.concatenate(values, axis=dim)
      elif tensor.op.type == "Pack":
          values = []
          # Some imported GraphDefs have Pack ops with zero inputs. Those are invalid
          # and shouldn't be produced, but to deal sensibly with them here we check
          # and return None.
          if not tensor.op.inputs:
              return None
          # We can't handle axis != 0 Packs at the moment.
          if tensor.op.get_attr("axis") != 0:
              return None
          for x in tensor.op.inputs:
              value = constant_value(x, partial)
              if value is None and not partial:
                  return None
              values.append(value)
          try:
              return np.array(values)
          except ValueError:
              # If partial=True, some of the elements of values may be None.
              return np.array(values, dtype=object)
      elif tensor.op.type == "Unpack":
          # We can't handle axis != 0 Unpacks at the moment.
          if tensor.op.get_attr("axis") != 0:
              return None
          value = constant_value(tensor.op.inputs[0], partial)
          if value is None:
              return None
          return value[tensor.value_index]
      elif tensor.op.type == "Split":
          dim = constant_value(tensor.op.inputs[0])
          value = constant_value(tensor.op.inputs[1], partial)
          if value is None or dim is None:
              return None
          split = np.split(value, tensor.op.get_attr("num_split"), dim)
          return split[tensor.value_index]
      elif tensor.op.type == "Fill":
          fill_shape = tensor.shape
          fill_value = constant_value(tensor.op.inputs[1])
          if fill_shape.is_fully_defined() and fill_value is not None:
              return np.full(
                  fill_shape.as_list(),
                  fill_value,
                  dtype=fill_value.dtype,
              )
          else:
              return None
      elif tensor.op.type == "Equal":
          value1 = constant_value(tensor.op.inputs[0])
          if value1 is None:
              return None
          value2 = constant_value(tensor.op.inputs[1])
          if value2 is None:
              return None
          return np.equal(value1, value2)
      elif tensor.op.type == "NotEqual":
          value1 = constant_value(tensor.op.inputs[0])
          if value1 is None:
              return None
          value2 = constant_value(tensor.op.inputs[1])
          if value2 is None:
              return None
          return np.not_equal(value1, value2)
      elif tensor.op.type == "StopGradient":
          return constant_value(tensor.op.inputs[0], partial)
      elif tensor.op.type in (
          "CheckNumericsV2",
          "DebugIdentityV2",
          "Identity",
      ):
          return constant_value(tensor.op.inputs[0], partial)
      else:
          return None
  
imports: import typing
  from typing import Protocol
  import numpy
  from tensorflow.core.framework import tensor_pb2
  from tensorflow.core.framework import tensor_shape_pb2
  from tensorflow.python.client import pywrap_tf_session
  from tensorflow.python.framework import dtypes
  from tensorflow.python.framework import errors_impl
  from tensorflow.python.framework import tensor_shape
  from tensorflow.python.types import core
  from tensorflow.python.types import internal
  from tensorflow.python.util import compat
  from tensorflow.python.util import nest
  from tensorflow.python.util.tf_export import tf_export
label_desc: Use image node_id 27 for calling a global function with example usage: _ConstantValue(tensor, partial) and returns: MakeNdarray, np, None, np, None, np, None, np, None, None, None, pre_cast, None, np, None, np, None, None, None, None, None, np, value, None, np, None, None, split, None, np, None, np, None, None, np, None, None, constant_value, constant_value, None