code: def tensor(primitive, shape):
      shape = canonical_shape(shape)
  
      class tensor:
          T = [primitive, shape]
  
          def __init__(self):
              self._val = []
  
          @classmethod
          def __type_info__(cls):
              return Type(
                  "tensor",
                  list(shape) + [get_type_info(primitive)],
                  python_class=cls,
              )
  
          @classmethod
          def get_primitive(cls):
              return primitive
  
          @classmethod
          def get_shape(cls):
              return shape
  
          @property
          def val(self):
              return self._val
  
          @val.setter
          def val(self, v):
              if not isinstance(v, np.ndarray):
                  raise ValueError(
                      "tensor should have value of type ndarray, got {} instead".format(
                          type(v)
                      )
                  )
  
              v_type = numpy_type_to_builtin_type(v.dtype)
              promoted_type = promote_types(v_type, primitive)
              primitive_np_type = nptype_from_builtin(primitive)
              if (
                  v_type == primitive
                  or v.dtype == np.dtype("O")
                  or v.dtype == primitive_np_type
              ):
                  # np.array of symbolic has object type. Don't cast type.
                  self._val = v
              elif promoted_type == primitive:
                  self._val = v.astype(primitive_np_type)
              else:
                  logger.warning(
                      "Saving value type of {} into a builtin type of {}, might lose precision!".format(
                          v.dtype, builtin_to_string(primitive)
                      )
                  )
                  self._val = v.astype(primitive_np_type)
  
      tensor.__template_name__ = (
          "tensor["
          + primitive.__name__
          + ","
          + ",".join(str(s) for s in shape)
          + "]"
      )
      tensor.__name__ = (
          "tensor["
          + ",".join(str(s) for s in shape)
          + ","
          + primitive.__name__
          + "]"
      )
      return tensor
  
file_path: coremltools/coremltools/converters/mil/mil/types/type_tensor.py
imports: import numpy
  import sympy
  from coremltools import _logger
  from .get_type_info import get_type_info
  from .type_mapping import builtin_to_string, is_subtype, is_tensor, nptype_from_builtin, numpy_type_to_builtin_type, promote_types
  from .type_spec import Type
label_desc: Use image node_id 3 for calling a global function with example usage: tensor(primitive, shape) and returns: tensor, Type, primitive, shape, self