code: def mode_dot(
      x: Union[ivy.Array, ivy.NativeArray],
      /,
      matrix_or_vector: Union[ivy.Array, ivy.NativeArray],
      mode: int,
      transpose: Optional[bool] = False,
      *,
      out: Optional[ivy.Array] = None,
  ) -> ivy.Array:
      """N-mode product of a tensor and a matrix or vector at the specified mode.
  
      Parameters
      ----------
      x
          tensor of shape ``(i_1, ..., i_k, ..., i_N)``
      matrix_or_vector
          1D or 2D array of shape ``(J, i_k)`` or ``(i_k, )``
          matrix or vectors to which to n-mode multiply the tensor
      mode
          int in the range(1, N)
      transpose
          If True, the matrix is transposed.
          For complex tensors, the conjugate transpose is used.
      out
          optional output array, for writing the result to. It must have a shape that the
          result can broadcast to.
  
      Returns
      -------
      ivy.Array
          `mode`-mode product of `tensor` by `matrix_or_vector`
          * of shape :math:`(i_1, ..., i_{k-1}, J, i_{k+1}, ..., i_N)`
            if matrix_or_vector is a matrix
          * of shape :math:`(i_1, ..., i_{k-1}, i_{k+1}, ..., i_N)`
            if matrix_or_vector is a vector
      """
      # the mode along which to fold might decrease if we take product with a vector
      fold_mode = mode
      new_shape = list(x.shape)
      ndims = len(matrix_or_vector.shape)
  
      if ndims == 2:  # Tensor times matrix
          # Test for the validity of the operation
          dim = 0 if transpose else 1
          if matrix_or_vector.shape[dim] != x.shape[mode]:
              raise ValueError(
                  f"shapes {x.shape} and {matrix_or_vector.shape} not aligned in"
                  f" mode-{mode} multiplication: {x.shape[mode]} (mode {mode}) !="
                  f" {matrix_or_vector.shape[dim]} (dim 1 of matrix)"
              )
  
          if transpose:
              matrix_or_vector = ivy.conj(
                  ivy.permute_dims(matrix_or_vector, (1, 0))
              )
  
          new_shape[mode] = matrix_or_vector.shape[0]
          vec = False
  
      elif ndims == 1:  # Tensor times vector
          if matrix_or_vector.shape[0] != x.shape[mode]:
              raise ValueError(
                  f"shapes {x.shape} and {matrix_or_vector.shape} not aligned for"
                  f" mode-{mode} multiplication: {x.shape[mode]} (mode {mode}) !="
                  f" {matrix_or_vector.shape[0]} (vector size)"
              )
          if len(new_shape) > 1:
              new_shape.pop(mode)
          else:
              new_shape = []
          vec = True
  
      else:
          raise ValueError(
              "Can only take n_mode_product with a vector or a matrix."
              f"Provided array of dimension {ndims} not in [1, 2]."
          )
  
      res = ivy.matmul(matrix_or_vector, ivy.unfold(x, mode))
  
      if vec:  # We contracted with a vector, leading to a vector
          return ivy.reshape(res, new_shape, out=out)
      else:  # tensor times vec: refold the unfolding
          return ivy.fold(res, fold_mode, new_shape, out=out)
  
imports: import logging
  from typing import Union, Optional, Tuple, List, Sequence, Literal
  import ivy
  from ivy.utils.backend import current_backend
  from ivy.func_wrapper import to_native_arrays_and_back, handle_out_argument, handle_nestable, handle_array_like_without_promotion, handle_array_function, handle_device, inputs_to_ivy_arrays, handle_backend_invalid
  from ivy.utils.exceptions import handle_exceptions
label_desc: Use image node_id 14 for calling a global function with example usage: mode_dot(matrix_or_vector, mode, transpose) and returns: ivy, ivy