code: def to_tensor(
      x: Union[Tensor, np.ndarray],
      cspace: Optional[str] = None,
      dtype=None,
      override_checks: bool = False,
      enforce_tensor: bool = False,
  ) -> Tensor:
      r"""
          Convert an array to a caer.Tensor.
  
          To convert a Numpy Array to a ``caer.Tensor``, specify the ``cspace`` attribute (either bgr/rgb/gray/hsv/hls/lab).
          If a ``caer.Tensor`` is passed, its attributes are preserved.
  
          If ``x`` is a ``caer.Tensor`` and ``cspace`` is specified, the colorspace of the Tensor will be updated accordingly.
          To prevent this, set ``cspace=None``.
  
      .. warning::
          ``override_checks`` and ``enforce_tensor`` should not be used. If not handled property, a silly bug may pop up at an unexpected time.
  
      Args:
          x (Tensor, ndarray, PIL): Tensor/Array to convert.
          cspace (str): ``must`` be specified if you are converting a Numpy array to a ``caer.Tensor``. Value should be either bgr/rgb/gray/hsv/hls/lab.
          dtype (numpy): (optional) Data Type
          override_checks (bool): WARNING: Intended for internal usage only. If not handled properly, a silly bug may pop up at an unexpected time.
          enforce_tensor (bool): WARNING: Intended for internal usage only. If not handled properly, a silly bug may pop up at an unexpected time.
      """
      if isinstance(x, Tensor):
          if (
              cspace is None
          ):  # if unsure of the cspace (usually in cases when converting a foreign array to a caer.Tensor)
              return x
  
          else:
              # Preserve
              x = Tensor(x, cspace=cspace, dtype=dtype)
              tens = _preserve_tensor_attrs(old=x)
              return tens
  
      elif isinstance(x, np.ndarray):
          return from_numpy(x, cspace=cspace, override_checks=override_checks, enforce_tensor=enforce_tensor)  # type: ignore[arg-type]
  
      # If PIL Image
      elif "PIL" in str(type(x)):
          if cspace is None:
              raise ValueError(
                  "The `cspace` attribute must be specified when converting from foreign arrays to a caer.Tensor. Supported values: bgr/rgb/gray/hsv/hls/lab."
              )
  
          x = np.array(x)
          return Tensor(x, cspace=cspace, dtype=dtype)
  
      else:
          raise TypeError(
              f"Cannot convert class {type(x)} to a caer.Tensor. Currently, only Numpy arrays and (to a limited extend) PIL images) are supported."
          )
  
imports: import numpy
  from .tensor import Tensor
  from typing import Tuple, Optional, Union
label_desc: Use image node_id 2 for calling a global function with example usage: to_tensor(x, cspace, dtype, override_checks, enforce_tensor) and returns: x, tens, from_numpy, Tensor