code: def _validate_tt_matrix(tt_tensor):
      factors = tt_tensor
      n_factors = len(factors)
  
      if n_factors < 1:
          raise ValueError(
              "A Tensor-Train (MPS) tensor should be composed of at least one factor."
              f"However, {n_factors} factor was given."
          )
  
      rank = []
      left_shape = []
      right_shape = []
      for index, factor in enumerate(factors):
          (
              current_rank,
              current_left_shape,
              current_right_shape,
              next_rank,
          ) = tl.shape(factor)
  
          # Check that factors are third order tensors
          if not tl.ndim(factor) == 4:
              raise ValueError(
                  "A TTMatrix expresses a tensor as fourth order factors (tt-cores).\n"
                  f"However, tl.ndim(factors[{index}]) = {tl.ndim(factor)}"
              )
          # Consecutive factors should have matching ranks
          if index and tl.shape(factors[index - 1])[-1] != current_rank:
              raise ValueError(
                  "Consecutive factors should have matching ranks\n"
                  " -- e.g. tl.shape(factors[0])[-1]) == tl.shape(factors[1])[0])\n"
                  f"However, tl.shape(factor[{index-1}])[-1] == {tl.shape(factors[index - 1])[-1]} but"
                  f" tl.shape(factor[{index}])[0] == {current_rank} "
              )
          # Check for boundary conditions
          if (index == 0) and current_rank != 1:
              raise ValueError(
                  "Boundary conditions dictate factor[0].shape[0] == 1."
                  f"However, got factor[0].shape[0] = {current_rank}."
              )
          if (index == n_factors - 1) and next_rank != 1:
              raise ValueError(
                  "Boundary conditions dictate factor[-1].shape[2] == 1."
                  f"However, got factor[{n_factors}].shape[2] = {next_rank}."
              )
  
          left_shape.append(current_left_shape)
          right_shape.append(current_right_shape)
  
          rank.append(current_rank)
  
      # Add last rank (boundary condition)
      rank.append(next_rank)
  
      return tuple(left_shape) + tuple(right_shape), tuple(rank)
  
imports: import tensorly
  from .tenalg import _tt_matrix_to_tensor
  from ._factorized_tensor import FactorizedTensor
  import numpy
label_desc: Use image node_id 6 for calling a global function with example usage: _validate_tt_matrix(tt_tensor) and returns: unknown,  tuple