code: def _validate_cp_tensor(cp_tensor):
      """Validates a cp_tensor in the form (weights, factors)
  
          Returns the rank and shape of the validated tensor
  
      Parameters
      ----------
      cp_tensor : CPTensor or (weights, factors)
  
      Returns
      -------
      (shape, rank) : (int tuple, int)
          size of the full tensor and rank of the CP tensor
      """
      if isinstance(cp_tensor, CPTensor):
          # it's already been validated at creation
          return cp_tensor.shape, cp_tensor.rank
      elif isinstance(cp_tensor, (float, int)):  # 0-order tensor
          return 0, 0
  
      weights, factors = cp_tensor
  
      if T.ndim(factors[0]) == 2:
          rank = int(T.shape(factors[0])[1])
      elif T.ndim(factors[0]) == 1:
          rank = 1
      else:
          raise ValueError(
              "Got a factor with 3 dimensions but CP factors should be at most 2D, of shape (size, rank)."
          )
  
      shape = []
      for i, factor in enumerate(factors):
          s = T.shape(factor)
          if len(s) == 2:
              current_mode_size, current_rank = s
          else:  # The shape is just (size, ) if rank 1
              current_mode_size, current_rank = *s, 1
  
          if current_rank != rank:
              raise ValueError(
                  "All the factors of a CP tensor should have the same number of column."
                  f"However, factors[0].shape[1]={rank} but factors[{i}].shape[1]={T.shape(factor)[1]}."
              )
          shape.append(current_mode_size)
  
      if weights is not None and T.shape(weights) != (rank,):
          raise ValueError(
              f"Given factors for a rank-{rank} CP tensor but len(weights)={T.shape(weights)}."
          )
  
      return tuple(shape), 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 1 for calling a global function with example usage: _validate_cp_tensor(cp_tensor) and returns: tuple,  rank, cp_tensor,  cp_tensor, int,  int