§
    fŠtj  ã                   ó”   — d Z ddlmZ ddlmZ ddlmZmZmZm	Z	 dgZ
 eddg¬	¦  «         ed
d¦  «        dd„¦   «         ¦   «         ZdS )z+
Solve the orthogonal Procrustes problem.

é    )Ú_apply_over_batché   )Úsvd)Úarray_namespaceÚxp_capabilitiesÚ_asarrayÚis_numpyÚorthogonal_procrustesF)z
dask.arrayz+full_matrices=True is not supported by dask)Újax_jitÚskip_backends)ÚAé   )ÚBr   Tc                 óP  — t          | |¦  «        }t          | ||d¬¦  «        } t          |||d¬¦  «        }| j        dk    rt          d| j        › �¦  «        ‚| j        |j        k    r t          d| j        › d|j        › d�¦  «        ‚t          |¦  «        r4t          |j        |                     | ¦  «        z  j        ¦  «        \  }}}n>|j	                             |j        |                     | ¦  «        z  j        ¦  «        \  }}}||z  }| 
                    |¦  «        }||fS )aW
  
    Compute the matrix solution of the orthogonal (or unitary) Procrustes problem.

    Given matrices `A` and `B` of the same shape, find an orthogonal (or unitary in
    the case of complex input) matrix `R` that most closely maps `A` to `B` using the
    algorithm given in [1]_.

    Parameters
    ----------
    A : (M, N) array_like
        Matrix to be mapped.
    B : (M, N) array_like
        Target matrix.
    check_finite : bool, optional
        Whether to check that the input matrices contain only finite numbers.
        Disabling may give a performance gain, but may result in problems
        (crashes, non-termination) if the inputs do contain infinities or NaNs.

    Returns
    -------
    R : (N, N) ndarray
        The matrix solution of the orthogonal Procrustes problem.
        Minimizes the Frobenius norm of ``(A @ R) - B``, subject to
        ``R.conj().T @ R = I``.
    scale : float
        Sum of the singular values of ``A.conj().T @ B``.

    Raises
    ------
    ValueError
        If the input array shapes don't match or if check_finite is True and
        the arrays contain Inf or NaN.

    Notes
    -----
    Note that unlike higher level Procrustes analyses of spatial data, this
    function only uses orthogonal transformations like rotations and
    reflections, and it does not use scaling or translation.

    References
    ----------
    .. [1] Peter H. Schonemann, "A generalized solution of the orthogonal
           Procrustes problem", Psychometrica -- Vol. 31, No. 1, March, 1966.
           :doi:`10.1007/BF02289451`

    Examples
    --------
    >>> import numpy as np
    >>> from scipy.linalg import orthogonal_procrustes
    >>> A = np.array([[ 2,  0,  1], [-2,  0,  0]])

    Flip the order of columns and check for the anti-diagonal mapping

    >>> R, sca = orthogonal_procrustes(A, np.fliplr(A))
    >>> R
    array([[-5.34384992e-17,  0.00000000e+00,  1.00000000e+00],
           [ 0.00000000e+00,  1.00000000e+00,  0.00000000e+00],
           [ 1.00000000e+00,  0.00000000e+00, -7.85941422e-17]])
    >>> sca
    9.0

    As an example of the unitary Procrustes problem, generate a
    random complex matrix ``A``, a random unitary matrix ``Q``,
    and their product ``B``.

    >>> shape = (4, 4)
    >>> rng = np.random.default_rng(589234981235)
    >>> A = rng.random(shape) + rng.random(shape)*1j
    >>> Q = rng.random(shape) + rng.random(shape)*1j
    >>> Q, _ = np.linalg.qr(Q)
    >>> B = A @ Q

    `orthogonal_procrustes` recovers the unitary matrix ``Q``
    from ``A`` and ``B``.

    >>> R, _ = orthogonal_procrustes(A, B)
    >>> np.allclose(R, Q)
    True

    T)ÚxpÚcheck_finiteÚsubokr   z$expected ndim to be 2, but observed zthe shapes of A and B differ (z vs ú))r   r   ÚndimÚ
ValueErrorÚshaper	   r   ÚTÚconjÚlinalgÚsum)	r   r   r   r   ÚuÚwÚvtÚRÚscales	            úV/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/scipy/linalg/_procrustes.pyr
   r
      s   € õl 
˜˜AÑ	Ô	€Bå��r¨¸DÐAÑAÔA€AÝ��r¨¸DÐAÑAÔA€Aà„v�‚{€{ÝÐHÀÄÐHÐHÑIÔIÐIØ„w�!”'ÒÐÝÐQ¸!¼'ÐQÐQÀqÄwÐQÐQÐQÑRÔRÐRõ
 ��|„|ð 7Ý˜œ˜bŸgšg a™jœjÑ(Ô+Ñ,Ô,‰ˆˆ1ˆbˆbà”9—=’= !¤#¨¯ª°©
¬
Ñ"2Ô!5Ñ6Ô6‰ˆˆ1ˆbØ	ˆB‰€AØ�FŠF�1‰IŒI€EØˆeˆ8€Oó    N)T)Ú__doc__Úscipy._lib._utilr   Ú_decomp_svdr   Úscipy._lib._array_apir   r   r   r	   Ú__all__r
   © r"   r!   ú<module>r)      sÊ   ððð ð
 /Ð .Ð .Ð .Ð .Ð .Ø Ð Ð Ð Ð Ð Ø VÐ VÐ VÐ VÐ VÐ VÐ VÐ VÐ VÐ VÐ VÐ Vð #Ð
#€ð €ØØPÐQðñ ô ð Ð�8˜XÑ&Ô&ðdð dð dñ 'Ô&ñ	ô ð
dð dð dr"   