code: def validate_cp_rank(tensor_shape, rank="same", rounding="round"):
      """Returns the rank of a CP Decomposition
  
      Parameters
      ----------
      tensor_shape : tupe
          shape of the tensor to decompose
      rank : {'same', float, 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, just returns rank
      rounding = {'round', 'floor', 'ceil'}
  
      Returns
      -------
      rank : int
          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 of round, floor or ceil, but got {rounding}"
          )
  
      if rank == "same":
          rank = float(1)
  
      if isinstance(rank, float):
          rank = int(
              rounding_fun(
                  np.prod(tensor_shape) * rank / np.sum(tensor_shape)
              )
          )
      return rank
  
imports: from .None import backend
  from .base import fold, tensor_to_vec
  from ._factorized_tensor import FactorizedTensor
  from .tenalg import khatri_rao, unfolding_dot_khatri_rao
  from .metrics.factors import congruence_coefficient
  import numpy
label_desc: Use image node_id 3 for calling a global function with example usage: validate_cp_rank(tensor_shape, rank, rounding) and returns: rank