class_docstr: PARAFAC2 decomposition [1]_ of a third order tensor via alternating least squares (ALS)
  
  Computes a rank-`rank` PARAFAC2 decomposition of the third-order tensor defined by
  `tensor_slices`. The decomposition is on the form :math:`(A [B_i] C)` such that the
  i-th frontal slice, :math:`X_i`, of :math:`X` is given by
  
  .. math::
  
      X_i = B_i diag(a_i) C^T,
  
  where :math:`diag(a_i)` is the diagonal matrix whose nonzero entries are equal to
  the :math:`i`-th row of the :math:`I \times R` factor matrix :math:`A`, :math:`B_i`
  is a :math:`J_i \times R` factor matrix such that the cross product matrix :math:`B_{i_1}^T B_{i_1}`
  is constant for all :math:`i`, and :math:`C` is a :math:`K \times R` factor matrix.
  To compute this decomposition, we reformulate the expression for :math:`B_i` such that
  
  .. math::
  
      B_i = P_i B,
  
  where :math:`P_i` is a :math:`J_i \times R` orthogonal matrix and :math:`B` is a
  :math:`R \times R` matrix.
  
  An alternative formulation of the PARAFAC2 decomposition is that the tensor element
  :math:`X_{ijk}` is given by
  
  .. math::
  
      X_{ijk} = \sum_{r=1}^R A_{ir} B_{ijr} C_{kr},
  
  with the same constraints hold for :math:`B_i` as above.
  
  Parameters
  ----------
  rank : int
      Number of components.
  n_iter_max : int, optional
      (Default: 2000) Maximum number of iteration
  
      .. versionchanged:: 0.6.1
  
          Previously, the default maximum number of iterations was 100.
  
  init : {'svd', 'random', CPTensor, Parafac2Tensor}
      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 : bool (optional)
      If True, aggregate the weights of each factor in a 1D-tensor
      of shape (rank, ), which will contain the norms of the factors. Note that
      there may be some inaccuracies in the component weights.
  tol : float, optional
      (Default: 1e-8) Relative reconstruction error decrease tolerance. The
      algorithm is considered to have converged when
      :math:`\left|\| X - \hat{X}_{n-1} \|^2 - \| X - \hat{X}_{n} \|^2\right| < \epsilon \| X - \hat{X}_{n-1} \|^2`.
      That is, when the relative change in sum of squared error is less
      than the tolerance.
  
      .. versionchanged:: 0.6.1
  
          Previously, the stopping condition was
          :math:`\left|\| X - \hat{X}_{n-1} \| - \| X - \hat{X}_{n} \|\right| < \epsilon`.
  
  absolute_tol : float, optional
      (Default: 1e-13) Absolute reconstruction error tolearnce. The algorithm
      is considered to have converged when
      :math:`\left|\| X - \hat{X}_{n-1} \|^2 - \| X - \hat{X}_{n} \|^2\right| < \epsilon_\text{abs}`.
      That is, when the relative sum of squared error is less than the specified tolerance.
      The absolute tolerance is necessary for stopping the algorithm when used on noise-free
      data that follows the PARAFAC2 constraint.
  
      If None, then the machine precision + 1000 will be used.
  nn_modes: None, 'all' or array of integers
      (Default: None) Used to specify which modes to impose non-negativity constraints on.
      We cannot impose non-negativity constraints on the the B-mode (mode 1) with the ALS
      algorithm, so if this mode is among the constrained modes, then a warning will be shown
      (see notes for more info).
  random_state : {None, int, np.random.RandomState}
  verbose : int, optional
      Level of verbosity
  return_errors : bool, optional
      Activate return of iteration errors
  n_iter_parafac : int, optional
      Number of PARAFAC iterations to perform for each PARAFAC2 iteration
  
  Returns
  -------
  Parafac2Tensor : (weight, factors, projection_matrices)
      * 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)
      * projection_matrices : List of projection matrices used to create evolving
          factors.
  
  References
  ----------
  .. [1] Kiers, H.A.L., ten Berge, J.M.F. and Bro, R. (1999),
         PARAFAC2—Part I. A direct fitting algorithm for the PARAFAC2 model.
         J. Chemometrics, 13: 275-294.
  
  Notes
  -----
  This formulation of the PARAFAC2 decomposition is slightly different from the one in [1]_.
  The difference lies in that, here, the second mode changes over the first mode, whereas in
  [1]_, the second mode changes over the third mode. This change allows the function to accept
  both lists of matrices and a single nd-array as input without any mode reordering.
docstr: Decompose an input tensor
  
  Parameters
  ----------
  tensor : tensorly.tensor
  
  Returns
  -------
  self
docstr_tok: ["Decompose","an","input","tensor","Parameters","--","--","--","--","--","tensor",":","tensorly.tensor","Returns","--","--","--","-","self"]
code: def fit_transform(self, tensor):
      """Decompose an input tensor
  
      Parameters
      ----------
      tensor : tensorly.tensor
  
      Returns
      -------
      self
      """
      self.decomposition_, self.errors_ = parafac2(
          tensor,
          rank=self.rank,
          n_iter_max=self.n_iter_max,
          init=self.init,
          svd=self.svd,
          normalize_factors=self.normalize_factors,
          tol=self.tol,
          absolute_tol=self.absolute_tol,
          nn_modes=self.nn_modes,
          random_state=self.random_state,
          verbose=self.verbose,
          return_errors=self.return_errors,
          n_iter_parafac=self.n_iter_parafac,
          linesearch=self.linesearch,
      )
      return self.decomposition_
  
imports: from warnings import warn
  from typing import Iterable
  import tensorly
  from ._base_decomposition import DecompositionMixin
  from tensorly.random import random_parafac2
  from tensorly import backend
  from .None import parafac, non_negative_parafac_hals
  from ..parafac2_tensor import Parafac2Tensor, _validate_parafac2_tensor
  from ..cp_tensor import CPTensor, cp_normalize
  from ..tenalg.svd import svd_interface
label_desc: Use image node_id 2 for calling the Parafac2 obj's underlying member method code with example usage: obj.fit_transform(tensor) and returns: self