ó
Ê½÷Xc           @` sW   d  Z  d d l m Z m Z m Z d d l Z d d l m Z d g Z	 e
 d „ Z d S(   s+   
Solve the orthogonal Procrustes problem.

i    (   t   divisiont   print_functiont   absolute_importNi   (   t   svdt   orthogonal_procrustesc         C` sä   | r' t  j |  ƒ }  t  j | ƒ } n t  j |  ƒ }  t  j | ƒ } |  j d k rj t d |  j ƒ ‚ n  |  j | j k r› t d |  j | j f ƒ ‚ n  t | j j |  ƒ j ƒ \ } } } | j | ƒ } | j	 ƒ  } | | f S(   s  
    Compute the matrix solution of the orthogonal Procrustes problem.

    Given matrices A and B of equal shape, find an orthogonal matrix R
    that most closely maps A to B [1]_.
    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.

    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 dot(A, R) - B, subject to
        dot(R.T, R) == I.
    scale : float
        Sum of the singular values of ``dot(A.T, B)``.

    Raises
    ------
    ValueError
        If the input arrays are incompatibly shaped.
        This may also be raised if matrix A or B contains an inf or nan
        and check_finite is True, or if the matrix product AB contains
        an inf or nan.

    Notes
    -----
    .. versionadded:: 0.15.0

    References
    ----------
    .. [1] Peter H. Schonemann, "A generalized solution of the orthogonal
           Procrustes problem", Psychometrica -- Vol. 31, No. 1, March, 1996.

    i   s&   expected ndim to be 2, but observed %ss'   the shapes of A and B differ (%s vs %s)(
   t   npt   asarray_chkfinitet
   asanyarrayt   ndimt
   ValueErrort   shapeR   t   Tt   dott   sum(   t   At   Bt   check_finitet   ut   wt   vtt   Rt   scale(    (    s7   /tmp/pip-build-7oUkmx/scipy/scipy/linalg/_procrustes.pyR      s    0$(   t   __doc__t
   __future__R    R   R   t   numpyR   t
   decomp_svdR   t   __all__t   TrueR   (    (    (    s7   /tmp/pip-build-7oUkmx/scipy/scipy/linalg/_procrustes.pyt   <module>   s
   	