ó
r™xTc           @   sz   d  d l  m Z d  d l Z d  d l Z d  d l m Z d e j j f d „  ƒ  YZ	 d e
 f d „  ƒ  YZ d d	 „ Z d S(
   iÿÿÿÿ(   t   divisionN(   t   flext   real_bidiagonalc           B   s   e  Z d  „  Z RS(   c         C   s0   t  t |  ƒ j ƒ  |  j s" t ‚ |  j ƒ  d  S(   N(   t   superR   t   computet   has_convergedt   AssertionErrort   sort(   t   self(    (    s?   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/linalg/svd.pyR      s    (   t   __name__t
   __module__R   (    (    (    s?   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/linalg/svd.pyR      s   t   realc           B   s2   e  Z d  Z d Z d d „ Z d „  Z d „  Z RS(   s"   SVD decomposition of a real matrix.

      TODO: fix crashes for n x 1 or 1 x n matrices

      References:
        [1] Tony F. Chan,
            An improved algorithm for computing the singular value
            decomposition,
            ACM Trans. Math. Soft. 8 (1982), no. 1, 72-83.
  i   i   c         C   sK  d d l  m } | j ƒ  \ } } t j ƒ  } | j t j d d ƒ ƒ | }	 t j d | d | ƒ }
 | d k	 r} | |
 _
 n  | |  j | k rpt j j | d | ƒ} | j ƒ  } | rÍ | j ƒ  | } n  t j j | ƒ } | rô | j ƒ  } n  | r	| j ƒ  }	 n  | j ƒ  \ } } t d | d | d	 | j d
 | d |	 |
 j � } | j ƒ  | r!| j | ƒ } q!n±| |  j | k rit j j | d | ƒ} | j ƒ  } | rÀ| j ƒ  | } n  t j j | ƒ } | rç| j ƒ  } n  | rü| j ƒ  }	 n  | j ƒ  \ } } t d | d | d	 | j d
 | d |	 |
 j � } | j ƒ  | r!| j ƒ  j |	 ƒ }	 q!n¸ t j j | ƒ } | r�| j ƒ  } n  | r¥| j ƒ  }	 n  | | k rÏ| j ƒ  \ } } | j } n | j ƒ  \ } } | j } t d | d | d	 | d
 | d |	 |
 j � } | j ƒ  | |	 | |  _ |  _ |  _ | |  _  d S(   sŸ   Compute the decomposition of a (A = U S V^T).
        The matrix a is overwritten in the process.
        The singular values are available in self.sigma.
        The matrices U and V are assembled only if requested, in which case
        they are avalaible in self.u and self.v.
        The argument epsilon is the "precision" to compute the singular
        values with, in the sense of the epsilon machine.
    iÿÿÿÿ(   t   bidiagonal_matrix_kindi    t   accumulate_ut   accumulate_vt   may_accumulate_qt   diagonalt   off_diagonalt   kindt   ut   vN(!   t   scitbx.linalgR   t   focusR   t   doublet   reshapet   gridt   libtbxt
   group_argst   Nonet   epsilont	   crossovert   scitbxt   linalgt   householder_qr_decompositiont   matrix_copy_upper_trianglet   accumulate_q_in_placet   householder_bidiagonalisationR   R   t   matrix_upper_bidiagonalR   t   upper_diagonalt   __dict__R   t   matrix_multiplyt   householder_lq_decompositiont   matrix_copy_lower_trianglet   matrix_transposet   matrix_lower_bidiagonalt   lower_diagonalt   sigmat   _svd(   R   t   aR   R   R   R   t   mt   nR   R   t   common_svd_argst   qrt   rt   qt   bidiagt   dt   ft   svdt   lqt   lR   (    (    s?   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/linalg/svd.pyt   __init__   s„    			
	  		
	
	  		
  		
c         C   s=   |  j  r |  j s t d ƒ ‚ t j j |  j  |  j |  j ƒ S(   s?    Reconstruct the matrix A from its singular values and vectors s   Missing singular vectors(   R   R   R   R   R    t   reconstruct_svdR.   (   R   (    (    s?   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/linalg/svd.pyt   reconstructk   s    c         C   s   |  j  j | ƒ S(   N(   R/   t   numerical_rank(   R   t   delta(    (    s?   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/linalg/svd.pyR@   p   s    g«ªªªªªú?N(   R	   R
   t   __doc__R   R   R=   R?   R@   (    (    (    s?   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/linalg/svd.pyR      s
   
N	g¼‰Ø—²Òœ<c   	      C   s¶   t  |  j ƒ  t t d ƒ } | j } | j } | j } t j | t j | ƒ | k  ƒ j	 ƒ  } | j ƒ  } | j
 | d ƒ d | } | j
 | d ƒ t j j | | | ƒ } | | f S(   Ng¼‰Ø—²Òœ<g      ð?g        (   R   t	   deep_copyt   TrueR   R   R.   R   t   boolt   maxt
   iselectiont   set_selectedR   R    R>   (	   R0   t   is_singular_thresholdt   svd_objR   R   R.   t	   selectiont	   inv_sigmat   ia(    (    s?   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/linalg/svd.pyt   inverse_via_svds   s    			(
(   t
   __future__R    R   R   R   t   scitbx.array_familyR   R    t&   svd_decomposition_of_bidiagonal_matrixR   t   objectR   RN   (    (    (    s?   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/linalg/svd.pyt   <module>   s   e