docstr: Generate a single slice along the first mode from the PARAFAC2
  tensor.
  
  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
  ----------
  parafac2_tensor
       weights
          1D array of shape (rank, ) weights of the factors
      factors
          List of factors of the PARAFAC2 decomposition Contains the
          matrices :math:`A`, :math:`B` and :math:`C` described above
      projection_matrices
           List of projection matrices used to create evolving factors.
  
  Returns
  -------
      Full tensor of shape [P[slice_idx].shape[1], C.shape[1]], where
      P is the projection matrices and C is the last factor matrix of
      the Parafac2Tensor.
docstr_tok: ["Generate","a","single","slice","along","the","first","mode","from","the","PARAFAC2","tensor",".","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","--","--","--","--","--","parafac2_tensor","weights","1D","array","of","shape","(","rank",",",")","weights","of","the","factors","factors","List","of","factors","of","the","PARAFAC2","decomposition","Contains","the","matrices",":","math",":","`","A","`",",",":","math",":","`","B","`","and",":","math",":","`","C","`","described","above","projection_matrices","List","of","projection","matrices","used","to","create","evolving","factors",".","Returns","--","--","--","-","Full","tensor","of","shape","[","P","[","slice_idx","]",".shape","[","1","]",",","C.shape","[","1","]","]",",","where","P","is","the","projection","matrices","and","C","is","the","last","factor","matrix","of","the","Parafac2Tensor","."]
code: def parafac2_to_slice(parafac2_tensor, slice_idx, validate=True):
      """Generate a single slice along the first mode from the PARAFAC2
      tensor.
  
      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
      ----------
      parafac2_tensor
           weights
              1D array of shape (rank, ) weights of the factors
          factors
              List of factors of the PARAFAC2 decomposition Contains the
              matrices :math:`A`, :math:`B` and :math:`C` described above
          projection_matrices
               List of projection matrices used to create evolving factors.
  
      Returns
      -------
          Full tensor of shape [P[slice_idx].shape[1], C.shape[1]], where
          P is the projection matrices and C is the last factor matrix of
          the Parafac2Tensor.
      """
      if validate:
          ivy.Parafac2Tensor.validate_parafac2_tensor(parafac2_tensor)
      weights, (A, B, C), projections = parafac2_tensor
      a = A[slice_idx]
      if weights is not None:
          a = a * weights
  
      Ct = ivy.permute_dims(C, (1, 0))
  
      B_i = ivy.dot(projections[slice_idx], B)
      return ivy.dot(B_i * a, Ct)
  
imports: from .base import FactorizedTensor
  import ivy
  from copy import deepcopy
label_desc: Use image node_id 15 for calling the Parafac2Tensor obj's underlying member method code with example usage: obj.parafac2_to_slice(parafac2_tensor, slice_idx, validate) and returns: ivy