code: def _validate_tt_tensor(tt_tensor):
      factors = tt_tensor
      n_factors = len(factors)
  
      if isinstance(tt_tensor, TTTensor):
          # it's already been validated at creation
          return tt_tensor.shape, tt_tensor.rank
      elif isinstance(tt_tensor, (float, int)):  # 0-order tensor
          return 0, 0
  
      rank = []
      shape = []
      for index, factor in enumerate(factors):
          current_rank, current_shape, next_rank = tl.shape(factor)
  
          # Check that factors are third order tensors
          if not tl.ndim(factor) == 3:
              raise ValueError(
                  "TT expresses a tensor as third 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])[2] != current_rank:
              raise ValueError(
                  "Consecutive factors should have matching ranks\n"
                  " -- e.g. tl.shape(factors[0])[2]) == tl.shape(factors[1])[0])\n"
                  f"However, tl.shape(factor[{index-1}])[2] == {tl.shape(factors[index - 1])[2]} 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}."
              )
  
          shape.append(current_shape)
          rank.append(current_rank)
  
      # Add last rank (boundary condition)
      rank.append(next_rank)
  
      return tuple(shape), tuple(rank)
  
imports: import tensorly
  from ._factorized_tensor import FactorizedTensor
  import numpy
  import warnings
label_desc: Use image node_id 1 for calling a global function with example usage: _validate_tt_tensor(tt_tensor) and returns: tuple,  tuple, tt_tensor,  tt_tensor, int,  int