def METHOD_NAME(tensor, matrix_or_vector, mode, transpose=False):
    """n-mode product of a tensor and a matrix or vector at the specified mode
    Mathematically: :math:`\\text{tensor} \\times_{\\text{mode}} \\text{matrix or vector}`
    Parameters
    ----------
    tensor : ndarray
        tensor of shape ``(i_1, ..., i_k, ..., i_N)``
    matrix_or_vector : ndarray
        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
    Returns
    -------
    ndarray
        `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
    See also
    --------
    multi_mode_dot : chaining several mode_dot in one call
    """
    # the mode along which to fold might decrease if we take product with a vector
    tensor_order = tl.ndim(tensor)
    start = ord("a")
    tensor_modes = "".join(chr(start + i) for i in range(tensor_order))
    result_modes = [
        chr(start + tensor_order + 1) if i == mode else j
        for i, j in enumerate(tensor_modes)
    ]
    if tl.ndim(matrix_or_vector) == 2:  # Tensor times matrix
        # Test for the validity of the operation
        dim = 0 if transpose else 1
        if matrix_or_vector.shape[dim] != tensor.shape[mode]:
            raise ValueError(
                f"shapes {tensor.shape} and {matrix_or_vector.shape} not aligned in mode-{mode} multiplication: "
                f"{tensor.shape[mode]} (mode {mode}) != {matrix_or_vector.shape[dim]} (dim 1 of matrix)"
            )
        if transpose:
            matrix_or_vector = tl.conj(tl.transpose(matrix_or_vector))
        matrix_or_vector_modes = [chr(start + tensor_order + 1), tensor_modes[mode]]
    elif tl.ndim(matrix_or_vector) == 1:  # Tensor times vector
        if matrix_or_vector.shape[0] != tensor.shape[mode]:
            raise ValueError(
                f"shapes {tensor.shape} and {matrix_or_vector.shape} not aligned for mode-{mode} multiplication: "
                f"{tensor.shape[mode]} (mode {mode}) != {matrix_or_vector.shape[0]} (vector size)"
            )
        matrix_or_vector_modes = [tensor_modes[mode]]
        result_modes.pop(mode)
    else:
        raise ValueError(
            "Can only take n_mode_product with a vector or a matrix."
            f"Provided array of dimension {tl.ndim(matrix_or_vector)} not in [1, 2]."
        )
    result_modes = "".join(result_modes)
    matrix_or_vector_modes = "".join(matrix_or_vector_modes)
    equation = f"{tensor_modes},{matrix_or_vector_modes}->{result_modes}"
    return tl.einsum(equation, tensor, matrix_or_vector)