ó
Ë½÷Xc           @` sà   d  Z  d d l m Z m Z m Z d d l m Z m Z d d l m	 Z	 m
 Z
 d d l m Z d d d	 d
 d g Z e e e e d „ Z e e e d „ Z e e e d „ Z e e d „ Z e e e d „ Z e e d „ Z d S(   s!   Cholesky decomposition functions.i    (   t   divisiont   print_functiont   absolute_import(   t   asarray_chkfinitet   asarrayi   (   t   LinAlgErrort   _datacopied(   t   get_lapack_funcst   choleskyt
   cho_factort	   cho_solvet   cholesky_bandedt   cho_solve_bandedc   	   
   C` sö   | r t  |  ƒ } n t |  ƒ } t | j ƒ d k sP | j d | j d k r_ t d ƒ ‚ n  | pq t | |  ƒ } t d | f ƒ \ } | | d | d | d | ƒ\ } } | d k rÌ t d	 | ƒ ‚ n  | d k  rì t d
 | ƒ ‚ n  | | f S(   s,   Common code for cholesky() and cho_factor().i   i    i   s   expected square matrixt   potrft   lowert   overwrite_at   cleans)   %d-th leading minor not positive definites1   illegal value in %d-th argument of internal potrf(   s   potrf(   R   R   t   lent   shapet
   ValueErrorR   R   R   (	   t   aR   R   R   t   check_finitet   a1R   t   ct   info(    (    s;   /tmp/pip-build-7oUkmx/scipy/scipy/linalg/decomp_cholesky.pyt	   _cholesky   s    /$c      
   C` s.   t  |  d | d | d t d | ƒ\ } } | S(   sø  
    Compute the Cholesky decomposition of a matrix.

    Returns the Cholesky decomposition, :math:`A = L L^*` or
    :math:`A = U^* U` of a Hermitian positive-definite matrix A.

    Parameters
    ----------
    a : (M, M) array_like
        Matrix to be decomposed
    lower : bool, optional
        Whether to compute the upper or lower triangular Cholesky
        factorization.  Default is upper-triangular.
    overwrite_a : bool, optional
        Whether to overwrite data in `a` (may improve performance).
    check_finite : bool, optional
        Whether to check that the input matrix contains 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
    -------
    c : (M, M) ndarray
        Upper- or lower-triangular Cholesky factor of `a`.

    Raises
    ------
    LinAlgError : if decomposition fails.

    Examples
    --------
    >>> from scipy import array, linalg, dot
    >>> a = array([[1,-2j],[2j,5]])
    >>> L = linalg.cholesky(a, lower=True)
    >>> L
    array([[ 1.+0.j,  0.+0.j],
           [ 0.+2.j,  1.+0.j]])
    >>> dot(L, L.T.conj())
    array([[ 1.+0.j,  0.-2.j],
           [ 0.+2.j,  5.+0.j]])

    R   R   R   R   (   R   t   True(   R   R   R   R   R   (    (    s;   /tmp/pip-build-7oUkmx/scipy/scipy/linalg/decomp_cholesky.pyR   %   s    +c      
   C` s4   t  |  d | d | d t d | ƒ\ } } | | f S(   s=  
    Compute the Cholesky decomposition of a matrix, to use in cho_solve

    Returns a matrix containing the Cholesky decomposition,
    ``A = L L*`` or ``A = U* U`` of a Hermitian positive-definite matrix `a`.
    The return value can be directly used as the first parameter to cho_solve.

    .. warning::
        The returned matrix also contains random data in the entries not
        used by the Cholesky decomposition. If you need to zero these
        entries, use the function `cholesky` instead.

    Parameters
    ----------
    a : (M, M) array_like
        Matrix to be decomposed
    lower : bool, optional
        Whether to compute the upper or lower triangular Cholesky factorization
        (Default: upper-triangular)
    overwrite_a : bool, optional
        Whether to overwrite data in a (may improve performance)
    check_finite : bool, optional
        Whether to check that the input matrix contains 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
    -------
    c : (M, M) ndarray
        Matrix whose upper or lower triangle contains the Cholesky factor
        of `a`. Other parts of the matrix contain random data.
    lower : bool
        Flag indicating whether the factor is in the lower or upper triangle

    Raises
    ------
    LinAlgError
        Raised if decomposition fails.

    See also
    --------
    cho_solve : Solve a linear set equations using the Cholesky factorization
                of a matrix.

    R   R   R   R   (   R   t   False(   R   R   R   R   R   (    (    s;   /tmp/pip-build-7oUkmx/scipy/scipy/linalg/decomp_cholesky.pyR	   U   s    .c   
   	   C` s  |  \ } } | r- t  | ƒ } t  | ƒ } n t | ƒ } t | ƒ } | j d k sn | j d | j d k r} t d ƒ ‚ n  | j d | j d k r¦ t d ƒ ‚ n  | p¸ t | | ƒ } t d
 | | f ƒ \ } | | | d | d | ƒ\ } }	 |	 d k rt d	 |	 ƒ ‚ n  | S(   s  Solve the linear equations A x = b, given the Cholesky factorization of A.

    Parameters
    ----------
    (c, lower) : tuple, (array, bool)
        Cholesky factorization of a, as given by cho_factor
    b : array
        Right-hand side
    overwrite_b : bool, optional
        Whether to overwrite data in b (may improve performance)
    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
    -------
    x : array
        The solution to the system A x = b

    See also
    --------
    cho_factor : Cholesky factorization of a matrix

    i   i    i   s$   The factored matrix c is not square.s   incompatible dimensions.t   potrsR   t   overwrite_bs1   illegal value in %d-th argument of internal potrs(   s   potrs(   R   R   t   ndimR   R   R   R   (
   t   c_and_lowert   bR   R   R   R   t   b1R   t   xR   (    (    s;   /tmp/pip-build-7oUkmx/scipy/scipy/linalg/decomp_cholesky.pyR
   ˆ   s"    )!c         C` s—   | r t  |  ƒ }  n t |  ƒ }  t d |  f ƒ \ } | |  d | d | ƒ\ } } | d k rs t d | ƒ ‚ n  | d k  r“ t d | ƒ ‚ n  | S(   sÍ  
    Cholesky decompose a banded Hermitian positive-definite matrix

    The matrix a is stored in ab either in lower diagonal or upper
    diagonal ordered form::

        ab[u + i - j, j] == a[i,j]        (if upper form; i <= j)
        ab[    i - j, j] == a[i,j]        (if lower form; i >= j)

    Example of ab (shape of a is (6,6), u=2)::

        upper form:
        *   *   a02 a13 a24 a35
        *   a01 a12 a23 a34 a45
        a00 a11 a22 a33 a44 a55

        lower form:
        a00 a11 a22 a33 a44 a55
        a10 a21 a32 a43 a54 *
        a20 a31 a42 a53 *   *

    Parameters
    ----------
    ab : (u + 1, M) array_like
        Banded matrix
    overwrite_ab : bool, optional
        Discard data in ab (may enhance performance)
    lower : bool, optional
        Is the matrix in the lower form. (Default is upper form)
    check_finite : bool, optional
        Whether to check that the input matrix contains 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
    -------
    c : (u + 1, M) ndarray
        Cholesky factorization of a, in the same banded format as ab

    t   pbtrfR   t   overwrite_abi    s)   %d-th leading minor not positive definites1   illegal value in %d-th argument of internal pbtrf(   s   pbtrf(   R   R   R   R   R   (   t   abR$   R   R   R#   R   R   (    (    s;   /tmp/pip-build-7oUkmx/scipy/scipy/linalg/decomp_cholesky.pyR   ¸   s    )c   	      C` sê   |  \ } } | r- t  | ƒ } t  | ƒ } n t | ƒ } t | ƒ } | j d | j d k rn t d ƒ ‚ n  t d	 | | f ƒ \ } | | | d | d | ƒ\ } } | d k rÆ t d | ƒ ‚ n  | d k  ræ t d | ƒ ‚ n  | S(
   sž  Solve the linear equations A x = b, given the Cholesky factorization of A.

    Parameters
    ----------
    (cb, lower) : tuple, (array, bool)
        `cb` is the Cholesky factorization of A, as given by cholesky_banded.
        `lower` must be the same value that was given to cholesky_banded.
    b : array
        Right-hand side
    overwrite_b : bool, optional
        If True, the function will overwrite the values in `b`.
    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
    -------
    x : array
        The solution to the system A x = b

    See also
    --------
    cholesky_banded : Cholesky factorization of a banded matrix

    Notes
    -----

    .. versionadded:: 0.8.0

    iÿÿÿÿi    s&   shapes of cb and b are not compatible.t   pbtrsR   R   s)   %d-th leading minor not positive definites1   illegal value in %d-th argument of internal pbtrs(   s   pbtrs(   R   R   R   R   R   R   (	   t   cb_and_lowerR    R   R   t   cbR   R&   R"   R   (    (    s;   /tmp/pip-build-7oUkmx/scipy/scipy/linalg/decomp_cholesky.pyR   ð   s      !N(   t   __doc__t
   __future__R    R   R   t   numpyR   R   t   miscR   R   t   lapackR   t   __all__R   R   R   R   R	   R
   R   R   (    (    (    s;   /tmp/pip-build-7oUkmx/scipy/scipy/linalg/decomp_cholesky.pyt   <module>   s   		0308