code: def _validate_tr_tensor(tr_tensor):
      factors = tr_tensor
      n_factors = len(factors)
  
      if n_factors < 2:
          raise ValueError(
              "A Tensor Ring tensor should be composed of at least two factors."
              f"However, {n_factors} factor was given."
          )
  
      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(
                  "TR expresses a tensor as third order factors (tr-cores).\n"
                  f"However, tl.ndim(factors[{index}]) = {tl.ndim(factor)}"
              )
  
          # Consecutive factors should have matching ranks
          if 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}"
              )
  
          shape.append(current_shape)
          rank.append(current_rank)
  
      # Add last rank (boundary condition)
      rank.append(next_rank)
  
      return tuple(shape), tuple(rank)
  
imports: import warnings
  import numpy
  import tensorly
  from ._factorized_tensor import FactorizedTensor
label_desc: Use image node_id 4 for calling a global function with example usage: _validate_tr_tensor(tr_tensor) and returns: tuple,  tuple