code: def validate_tr_rank(tensor_shape, rank="same", rounding="round"):
      """Returns the rank of a Tensor Ring Decomposition
  
      Parameters
      ----------
      tensor_shape : tuple
          shape of the tensor to decompose
      rank : {'same', float, tuple, int}, default is same
          way to determine the rank, by default 'same'
          if 'same': rank is computed to keep the number of parameters (at most) the same
          if float, computes a rank so as to keep rank percent of the original number of parameters
          if int or tuple, just returns rank
      rounding : {'round', 'floor', 'ceil'}
  
      Returns
      -------
      rank : int tuple
          rank of the decomposition
      """
      if rounding == "ceil":
          rounding_fun = np.ceil
      elif rounding == "floor":
          rounding_fun = np.floor
      elif rounding == "round":
          rounding_fun = np.round
      else:
          raise ValueError(
              f"Rounding should be round, floor or ceil, but got {rounding}"
          )
  
      if rank == "same":
          rank = float(1)
  
      n_dim = len(tensor_shape)
      if n_dim == 2:
          warnings.warn(
              "Determining the TR-rank for the trivial case of a matrix"
              f" (order 2 tensor) of shape {tensor_shape}, not a higher-order tensor."
          )
  
      if isinstance(rank, float):
          # Choose the *same* rank for each mode
          n_param_tensor = np.prod(tensor_shape) * rank
  
          # R_k I_k R_{k+1} = R^2 I_k
          solution = int(
              rounding_fun(
                  np.sqrt(n_param_tensor / np.sum(tensor_shape))
              )
          )
          rank = (solution,) * (n_dim + 1)
  
      else:
          # Check user input for potential errors
          n_dim = len(tensor_shape)
          if isinstance(rank, int):
              rank = (rank,) * (n_dim + 1)
          elif n_dim + 1 != len(rank):
              message = (
                  "Provided incorrect number of ranks. "
                  "Should verify len(rank) == tl.ndim(tensor)+1, "
                  f"but len(rank) = {len(rank)} while tl.ndim(tensor)+1 = {n_dim + 1}"
              )
              raise ValueError(message)
  
          # Check first and last rank
          if rank[0] != rank[-1]:
              message = (
                  f"Provided rank[0] == {rank[0]} and rank[-1] == {rank[-1]}"
                  " but boundaring conditions dictatate rank[0] == rank[-1]"
              )
              raise ValueError(message)
  
      return list(rank)
  
imports: import warnings
  import numpy
  import tensorly
  from ._factorized_tensor import FactorizedTensor
label_desc: Use image node_id 6 for calling a global function with example usage: validate_tr_rank(tensor_shape, rank, rounding) and returns: list