class_docstr: Candecomp-Parafac decomposition via Alternating-Least Square
  
  Computes a rank-`rank` decomposition of `tensor` [1]_ such that::
  
      tensor = [|weights; factors[0], ..., factors[-1] |].
  
  Parameters
  ----------
  tensor : ndarray
  rank  : int
      Number of components.
  n_iter_max : int
      Maximum number of iteration
  init : {'svd', 'random'}, optional
      Type of factor matrix initialization. See `initialize_factors`.
  svd : str, default is 'truncated_svd'
      function to use to compute the SVD, acceptable values in tensorly.SVD_FUNS
  normalize_factors : if True, aggregate the weights of each factor in a 1D-tensor
      of shape (rank, ), which will contain the norms of the factors
  tol : float, optional
      (Default: 1e-6) Relative reconstruction error tolerance. The
      algorithm is considered to have found the global minimum when the
      reconstruction error is less than `tol`.
  random_state : {None, int, np.random.RandomState}
  verbose : int, optional
      Level of verbosity
  return_errors : bool, optional
      Activate return of iteration errors
  mask : ndarray
      array of booleans with the same shape as ``tensor`` should be 0 where
      the values are missing and 1 everywhere else. Note:  if tensor is
      sparse, then mask should also be sparse with a fill value of 1 (or
      True). Allows for missing values [2]_
  cvg_criterion : {'abs_rec_error', 'rec_error'}, optional
      Stopping criterion for ALS, works if `tol` is not None.
      If 'rec_error',  ALS stops at current iteration if ``(previous rec_error - current rec_error) < tol``.
      If 'abs_rec_error', ALS terminates when `|previous rec_error - current rec_error| < tol`.
  sparsity : float or int
      If `sparsity` is not None, we approximate tensor as a sum of low_rank_component and sparse_component, where low_rank_component = cp_to_tensor((weights, factors)). `sparsity` denotes desired fraction or number of non-zero elements in the sparse_component of the `tensor`.
  fixed_modes : list, default is None
      A list of modes for which the initial value is not modified.
      The last mode cannot be fixed due to error computation.
  svd_mask_repeats: int
      If using a tensor with masked values, this initializes using SVD multiple times to
      remove the effect of these missing values on the initialization.
  linesearch : bool, default is False
      Whether to perform line search as proposed by Bro [3].
  
  Returns
  -------
  CPTensor : (weight, factors)
      * weights : 1D array of shape (rank, )
  
        * all ones if normalize_factors is False (default),
        * weights of the (normalized) factors otherwise
  
      * factors : List of factors of the CP decomposition element `i ` is of shape
        (tensor.shape[i], rank)
      * sparse_component : nD array of shape tensor.shape. Returns only if `sparsity` is not None.
  
  errors : list
      A list of reconstruction errors at each iteration of the algorithms.
  
  References
  ----------
  .. [1] T.G.Kolda and B.W.Bader, "Tensor Decompositions and Applications",
         SIAM REVIEW, vol. 51, n. 3, pp. 455-500, 2009.
  .. [2] Tomasi, Giorgio, and Rasmus Bro. "PARAFAC and missing values."
         Chemometrics and Intelligent Laboratory Systems 75.2 (2005): 163-180.
  .. [3] R. Bro, "Multi-Way Analysis in the Food Industry: Models, Algorithms, and
         Applications", PhD., University of Amsterdam, 1998
class_docstr_tok: ["Candecomp-Parafac","decomposition","via","Alternating-Least","Square","Computes","a","rank-","`","rank","`","decomposition","of","`","tensor","`","[","1","]","_","such","that",":",":","tensor","=","[","|weights",";","factors","[","0","]",",","...",",","factors","[","-1","]","|","]",".","Parameters","--","--","--","--","--","tensor",":","ndarray","rank",":","int","Number","of","components",".","n_iter_max",":","int","Maximum","number","of","iteration","init",":","{","'svd","'",",","'random","'","}",",","optional","Type","of","factor","matrix","initialization",".","See","`","initialize_factors","`",".","svd",":","str",",","default","is","'truncated_svd'","function","to","use","to","compute","the","SVD",",","acceptable","values","in","tensorly.SVD_FUNS","normalize_factors",":","if","True",",","aggregate","the","weights","of","each","factor","in","a","1D-tensor","of","shape","(","rank",",",")",",","which","will","contain","the","norms","of","the","factors","tol",":","float",",","optional","(","Default",":","1e-6",")","Relative","reconstruction","error","tolerance",".","The","algorithm","is","considered","to","have","found","the","global","minimum","when","the","reconstruction","error","is","less","than","`","tol","`",".","random_state",":","{","None",",","int",",","np.random.RandomState","}","verbose",":","int",",","optional","Level","of","verbosity","return_errors",":","bool",",","optional","Activate","return","of","iteration","errors","mask",":","ndarray","array","of","booleans","with","the","same","shape","as","``","tensor","``","should","be","0","where","the","values","are","missing","and","1","everywhere","else",".","Note",":","if","tensor","is","sparse",",","then","mask","should","also","be","sparse","with","a","fill","value","of","1","(","or","True",")",".","Allows","for","missing","values","[","2","]","_","cvg_criterion",":","{","'abs_rec_error","'",",","'rec_error","'","}",",","optional","Stopping","criterion","for","ALS",",","works","if","`","tol","`","is","not","None",".","If","'rec_error","'",",","ALS","stops","at","current","iteration","if","``","(","previous","rec_error","-","current","rec_error",")","<","tol","``",".","If","'abs_rec_error","'",",","ALS","terminates","when","`","|previous","rec_error","-","current","rec_error|","<","tol","`",".","sparsity",":","float","or","int","If","`","sparsity","`","is","not","None",",","we","approximate","tensor","as","a","sum","of","low_rank_component","and","sparse_component",",","where","low_rank_component","=","cp_to_tensor","(","(","weights",",","factors",")",")",".","`","sparsity","`","denotes","desired","fraction","or","number","of","non-zero","elements","in","the","sparse_component","of","the","`","tensor","`",".","fixed_modes",":","list",",","default","is","None","A","list","of","modes","for","which","the","initial","value","is","not","modified",".","The","last","mode","can","not","be","fixed","due","to","error","computation",".","svd_mask_repeats",":","int","If","using","a","tensor","with","masked","values",",","this","initializes","using","SVD","multiple","times","to","remove","the","effect","of","these","missing","values","on","the","initialization",".","linesearch",":","bool",",","default","is","False","Whether","to","perform","line","search","as","proposed","by","Bro","[","3","]",".","Returns","--","--","--","-","CPTensor",":","(","weight",",","factors",")","*","weights",":","1D","array","of","shape","(","rank",",",")","*","all","ones","if","normalize_factors","is","False","(","default",")",",","*","weights","of","the","(","normalized",")","factors","otherwise","*","factors",":","List","of","factors","of","the","CP","decomposition","element","`","i","`","is","of","shape","(","tensor.shape","[","i","]",",","rank",")","*","sparse_component",":","nD","array","of","shape","tensor.shape",".","Returns","only","if","`","sparsity","`","is","not","None",".","errors",":","list","A","list","of","reconstruction","errors","at","each","iteration","of","the","algorithms",".","References","--","--","--","--","--","..","[","1","]","T.G.Kolda","and","B.W.Bader",",","``","Tensor","Decompositions","and","Applications","''",",","SIAM","REVIEW",",","vol",".","51",",","n.","3",",","pp",".","455-500",",","2009",".","..","[","2","]","Tomasi",",","Giorgio",",","and","Rasmus","Bro",".","``","PARAFAC","and","missing","values",".","''","Chemometrics","and","Intelligent","Laboratory","Systems","75.2","(","2005",")",":","163-180",".","..","[","3","]","R.","Bro",",","``","Multi-Way","Analysis","in","the","Food","Industry",":","Models",",","Algorithms",",","and","Applications","''",",","PhD.",",","University","of","Amsterdam",",","1998"]
code: def __repr__(self):
      return f"Rank-{self.rank} CP decomposition."
  
imports: import numpy
  import warnings
  import tensorly
  from ._base_decomposition import DecompositionMixin
  from ..random import random_cp
  from ..base import unfold
  from ..cp_tensor import cp_to_tensor, CPTensor, cp_norm, cp_normalize, validate_cp_rank
  from ..tenalg.svd import svd_interface
  from ..tenalg import unfolding_dot_khatri_rao
label_desc: Use image node_id 3 for calling the CP obj's underlying member method code with example usage: obj.__repr__() and returns: str, self, str