code: def tensor_train_matrix(
      tensor, rank, svd="truncated_svd", verbose=False
  ):
      """Decompose a tensor into a matrix in tt-format
  
      Parameters
      ----------
      tensor : tensorized matrix
          if your input matrix is of size (4, 9) and your tensorized_shape (2, 2, 3, 3)
          then tensor should be tl.reshape(matrix, (2, 2, 3, 3))
      rank : 'same', float or int tuple
          - if 'same' creates a decomposition with the same number of parameters as `tensor`
          - if float, creates a decomposition with `rank` x the number of parameters of `tensor`
          - otherwise, the actual rank to be used, e.g. (1, rank_2, ..., 1) of size tensor.ndim//2. Note that boundary conditions dictate that the first rank = last rank = 1.
      svd : str, default is 'truncated_svd'
          function to use to compute the SVD, acceptable values in tensorly.SVD_FUNS
      verbose : boolean, optional
              level of verbosity
  
      Returns
      -------
      tt_matrix
      """
      order = tl.ndim(tensor)
      n_input = order // 2  # (n_output = n_input)
  
      if tl.ndim(tensor) != n_input * 2:
          msg = "The tensor should have as many dimensions for inputs and outputs, i.e. order should be even "
          msg += f"but got a tensor of order tl.ndim(tensor)={order} which is odd."
          raise ValueError(msg)
  
      in_shape = tl.shape(tensor)[:n_input]
      out_shape = tl.shape(tensor)[n_input:]
  
      if n_input == 1:
          # A TTM with a single factor is just a matrix...
          return TTMatrix(
              [tensor.reshape(1, in_shape[0], out_shape[0], 1)]
          )
  
      new_idx = list(
          [
              idx
              for tuple_ in zip(
                  range(n_input), range(n_input, 2 * n_input)
              )
              for idx in tuple_
          ]
      )
      new_shape = list([a * b for (a, b) in zip(in_shape, out_shape)])
      tensor = tl.reshape(tl.transpose(tensor, new_idx), new_shape)
  
      factors = tensor_train(
          tensor, rank, svd=svd, verbose=verbose
      ).factors
      for i in range(len(factors)):
          factors[i] = tl.reshape(
              factors[i],
              (factors[i].shape[0], in_shape[i], out_shape[i], -1),
          )
  
      return TTMatrix(factors)
  
file_path: tensorly/tensorly/decomposition/_tt.py
imports: import tensorly
  from ._base_decomposition import DecompositionMixin
  from ..tt_tensor import validate_tt_rank, TTTensor
  from ..tt_matrix import validate_tt_matrix_rank, TTMatrix
  from ..tenalg.svd import svd_interface
label_desc: Use image node_id 2 for calling a global function with example usage: tensor_train_matrix(tensor, rank, svd, verbose) and returns: TTMatrix, TTMatrix