Ë
    âQ(héw  ã                   óB  — d dl mZmZmZ d dlZd dlmZ d dlmZm	Z	m
Z
mZmZmZ d dlmZmZmZmZ d dlmZ d dlZd dlZddlmZ d	Z	 d dlmZ  ej:                  «       ag d¢Z G d„ de «      Z!d„ Z"d„ Z#dd„Z$	 	 dd„Z%	 	 dd„Z&d„ Z'	 	 dd„Z(d„ Z)d„ Z*y# e$ r d
ZY ŒOw xY w)é    )ÚwarnÚcatch_warningsÚsimplefilterN)Úasarray)ÚissparseÚSparseEfficiencyWarningÚ	csr_arrayÚ	csc_arrayÚ	eye_arrayÚdiags_array)Úis_pydata_spmatrixÚconvert_pydata_sparse_to_scipyÚget_index_dtypeÚsafely_cast_index_arrays)ÚLinAlgErroré   )Ú_superluFT)	Ú
use_solverÚspsolveÚspluÚspiluÚ
factorizedÚMatrixRankWarningÚspsolve_triangularÚis_sptriangularÚspbandwidthc                   ó   — e Zd Zy)r   N)Ú__name__Ú
__module__Ú__qualname__© ó    úb/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/scipy/sparse/linalg/_dsolve/linsolve.pyr   r      s   „ Ør"   r   c                  ó†   — d| v r| d   t         _        t         j                  rd| v rt        j                  | d   ¬«       yyy)aq	  
    Select default sparse direct solver to be used.

    Parameters
    ----------
    useUmfpack : bool, optional
        Use UMFPACK [1]_, [2]_, [3]_, [4]_. over SuperLU. Has effect only
        if ``scikits.umfpack`` is installed. Default: True
    assumeSortedIndices : bool, optional
        Allow UMFPACK to skip the step of sorting indices for a CSR/CSC matrix.
        Has effect only if useUmfpack is True and ``scikits.umfpack`` is
        installed. Default: False

    Notes
    -----
    The default sparse solver is UMFPACK when available
    (``scikits.umfpack`` is installed). This can be changed by passing
    useUmfpack = False, which then causes the always present SuperLU
    based solver to be used.

    UMFPACK requires a CSR/CSC matrix to have sorted column/row indices. If
    sure that the matrix fulfills this, pass ``assumeSortedIndices=True``
    to gain some speed.

    References
    ----------
    .. [1] T. A. Davis, Algorithm 832:  UMFPACK - an unsymmetric-pattern
           multifrontal method with a column pre-ordering strategy, ACM
           Trans. on Mathematical Software, 30(2), 2004, pp. 196--199.
           https://dl.acm.org/doi/abs/10.1145/992200.992206

    .. [2] T. A. Davis, A column pre-ordering strategy for the
           unsymmetric-pattern multifrontal method, ACM Trans.
           on Mathematical Software, 30(2), 2004, pp. 165--195.
           https://dl.acm.org/doi/abs/10.1145/992200.992205

    .. [3] T. A. Davis and I. S. Duff, A combined unifrontal/multifrontal
           method for unsymmetric sparse matrices, ACM Trans. on
           Mathematical Software, 25(1), 1999, pp. 1--19.
           https://doi.org/10.1145/305658.287640

    .. [4] T. A. Davis and I. S. Duff, An unsymmetric-pattern multifrontal
           method for sparse LU factorization, SIAM J. Matrix Analysis and
           Computations, 18(1), 1997, pp. 140--158.
           https://doi.org/10.1137/S0895479894246905T.

    Examples
    --------
    >>> import numpy as np
    >>> from scipy.sparse.linalg import use_solver, spsolve
    >>> from scipy.sparse import csc_array
    >>> R = np.random.randn(5, 5)
    >>> A = csc_array(R)
    >>> b = np.random.randn(5)
    >>> use_solver(useUmfpack=False) # enforce superLU over UMFPACK
    >>> x = spsolve(A, b)
    >>> np.allclose(A.dot(x), b)
    True
    >>> use_solver(useUmfpack=True) # reset umfPack usage to default
    Ú
useUmfpackÚassumeSortedIndices)r&   N)r%   ÚuÚumfpackÚ	configure)Úkwargss    r#   r   r       sC   € ð| �vÑØ˜lÑ+Œ
ŒÜ‡|‚|Ð-°Ñ7Ü×Ñ¨fÐ5JÑ.KÖLð 8€|r"   c                 ó  — t         j                  t         j                  fdt         j                  t         j                  fdt         j                  t         j                  fdt         j                  t         j                  fdi}t        t         | j                  j                  «      }t        t         | j                  j                  j                  «      }	 |||f   }|d	   d
z   }t        j                  | «      }t        j                  | j                  t         j                  ¬«      |_        t        j                  | j                  t         j                  ¬«      |_        ||fS # t        $ r}d|› d|› d�}t        |«      |‚d}~ww xY w)z8Get umfpack family string given the sparse matrix dtype.ÚdiÚziÚdlÚzlz]only float64 or complex128 matrices with int32 or int64 indices are supported! (got: matrix: z, indices: ú)Nr   Úl©Údtype)ÚnpÚfloat64Úint32Ú
complex128Úint64Úgetattrr3   ÚnameÚindicesÚKeyErrorÚ
ValueErrorÚcopyr   Úindptr)ÚAÚ	_familiesÚf_typeÚi_typeÚfamilyÚeÚmsgÚA_news           r#   Ú_get_umf_familyrH   c   s,  € ô 
�‰”R—X‘XÐ Ü	�‰œŸ™Ð! 4Ü	�‰”R—X‘XÐ Ü	�‰œŸ™Ð! 4ð	€Iô ”R˜Ÿ™Ÿ™Ó&€Fô ”R˜Ÿ™Ÿ™×-Ñ-Ó.€Fð%Ø˜F FÐ+Ñ,ˆð �A‰Y˜‰_€FÜ�I‰I�a‹L€EÜ—:‘:˜aŸh™h¬b¯h©hÔ7€E„LÜ—J‘J˜qŸy™y´·±Ô9€E„Mà�5ˆ=Ðøô ò %ð7Ø7=°h¸kÈ&ÈÐQRðTˆä˜‹o 1Ð$ûð%ús   ÃE& Å&	F	Å/FÆF	c           
      óÀ
  — t        |«      }|r|j                  nd}t        | «      } t        |«      }t        | «      r| j                  dv st        | «      } t        dt        d¬«       t        |«      }|st        |«      }|j                  dk(  xs# |j                  dk(  xr |j                  d   dk(  }| j                  «        | j                  «       } t        j                  | j                  |j                  «      }| j                  |k7  r| j!                  |«      } |j                  |k7  r|j!                  |«      }| j                  \  }	}
|	|
k7  rt#        d|	|
f› d�«      ‚|	|j                  d	   k7  r)t#        d
| j                  › d|j                  d	   › d�«      ‚t%        t&        d«      st(         t&        _        |xr t&        j*                  }|r¸|r¶|r|j-                  «       }n|}t        || j                  ¬«      j/                  «       }t(        rt1        d«      ‚| j                  j2                  dvrt#        d«      ‚t5        | «      \  }} t7        j8                  |«      }|j;                  t6        j<                  | |d¬«      }|S |r|r|j-                  «       }d}|sô| j                  dk(  rd}nd	}| j>                  j!                  t        j@                  d¬«      }| jB                  j!                  t        j@                  d¬«      }tE        |¬«      }tG        jH                  |
| jJ                  | jL                  |||||¬«      \  }}|d	k7  r1t        dtN        d¬«       |jQ                  t        jR                  «       |r|j/                  «       }|S tU        | «      }|j                  dk(  s(t        |«      st        dt        d¬«       t        |«      }g }g }g }tW        |j                  d   «      D ]Â  }|dd…|f   j-                  «       j/                  «       } ||«      }t        jX                  |«      }|j                  d	   }|j[                  |«       |j[                  t        j\                  ||t^        ¬«      «       |j[                  t        j                  ||   | j                  ¬«      «       ŒÄ t        j`                  |«      }tc        te        |j                  «      ¬«      }t        j`                  ||¬«      }t        j`                  ||¬«      } | j                  ||| ff|j                  | j                  ¬«      }|r|jg                  |«      }|S )a  Solve the sparse linear system Ax=b, where b may be a vector or a matrix.

    Parameters
    ----------
    A : ndarray or sparse array or matrix
        The square matrix A will be converted into CSC or CSR form
    b : ndarray or sparse array or matrix
        The matrix or vector representing the right hand side of the equation.
        If a vector, b.shape must be (n,) or (n, 1).
    permc_spec : str, optional
        How to permute the columns of the matrix for sparsity preservation.
        (default: 'COLAMD')

        - ``NATURAL``: natural ordering.
        - ``MMD_ATA``: minimum degree ordering on the structure of A^T A.
        - ``MMD_AT_PLUS_A``: minimum degree ordering on the structure of A^T+A.
        - ``COLAMD``: approximate minimum degree column ordering [1]_, [2]_.

    use_umfpack : bool, optional
        if True (default) then use UMFPACK for the solution [3]_, [4]_, [5]_,
        [6]_ . This is only referenced if b is a vector and
        ``scikits.umfpack`` is installed.

    Returns
    -------
    x : ndarray or sparse array or matrix
        the solution of the sparse linear equation.
        If b is a vector, then x is a vector of size A.shape[1]
        If b is a matrix, then x is a matrix of size (A.shape[1], b.shape[1])

    Notes
    -----
    For solving the matrix expression AX = B, this solver assumes the resulting
    matrix X is sparse, as is often the case for very sparse inputs.  If the
    resulting X is dense, the construction of this sparse result will be
    relatively expensive.  In that case, consider converting A to a dense
    matrix and using scipy.linalg.solve or its variants.

    References
    ----------
    .. [1] T. A. Davis, J. R. Gilbert, S. Larimore, E. Ng, Algorithm 836:
           COLAMD, an approximate column minimum degree ordering algorithm,
           ACM Trans. on Mathematical Software, 30(3), 2004, pp. 377--380.
           :doi:`10.1145/1024074.1024080`

    .. [2] T. A. Davis, J. R. Gilbert, S. Larimore, E. Ng, A column approximate
           minimum degree ordering algorithm, ACM Trans. on Mathematical
           Software, 30(3), 2004, pp. 353--376. :doi:`10.1145/1024074.1024079`

    .. [3] T. A. Davis, Algorithm 832:  UMFPACK - an unsymmetric-pattern
           multifrontal method with a column pre-ordering strategy, ACM
           Trans. on Mathematical Software, 30(2), 2004, pp. 196--199.
           https://dl.acm.org/doi/abs/10.1145/992200.992206

    .. [4] T. A. Davis, A column pre-ordering strategy for the
           unsymmetric-pattern multifrontal method, ACM Trans.
           on Mathematical Software, 30(2), 2004, pp. 165--195.
           https://dl.acm.org/doi/abs/10.1145/992200.992205

    .. [5] T. A. Davis and I. S. Duff, A combined unifrontal/multifrontal
           method for unsymmetric sparse matrices, ACM Trans. on
           Mathematical Software, 25(1), 1999, pp. 1--19.
           https://doi.org/10.1145/305658.287640

    .. [6] T. A. Davis and I. S. Duff, An unsymmetric-pattern multifrontal
           method for sparse LU factorization, SIAM J. Matrix Analysis and
           Computations, 18(1), 1997, pp. 140--158.
           https://doi.org/10.1137/S0895479894246905T.


    Examples
    --------
    >>> import numpy as np
    >>> from scipy.sparse import csc_array
    >>> from scipy.sparse.linalg import spsolve
    >>> A = csc_array([[3, 2, 0], [1, -1, 0], [0, 5, 1]], dtype=float)
    >>> B = csc_array([[2, 0], [-1, 0], [2, 0]], dtype=float)
    >>> x = spsolve(A, B)
    >>> np.allclose(A.dot(x).toarray(), B.toarray())
    True
    N©ÚcscÚcsrz.spsolve requires A be CSC or CSR matrix formaté   ©Ú
stacklevelr   z!matrix must be square (has shape r0   r   z!matrix - rhs dimension mismatch (z - r'   r2   úScikits.umfpack not installed.ÚdDú\convert matrix data to double, please, using .astype(), or set linsolve.useUmfpack.u = FalseT©ÚautoTransposeFrK   )r>   )ÚColPerm)ÚoptionszMatrix is exactly singularzCspsolve is more efficient when sparse b is in the CSC matrix format)Úmaxval)Úshaper3   )4r   Ú	__class__r   r   Úformatr
   r   r   r   ÚndimrX   Úsum_duplicatesÚ	_asfptyper4   Úpromote_typesr3   Úastyper=   Úhasattrr%   ÚnoScikitr'   ÚtoarrayÚravelÚRuntimeErrorÚcharrH   r(   ÚUmfpackContextÚlinsolveÚ	UMFPACK_Ar;   Úintcr?   Údictr   ÚgssvÚnnzÚdatar   ÚfillÚnanr   ÚrangeÚflatnonzeroÚappendÚfullÚintÚconcatenater   ÚmaxÚfrom_scipy_sparse)!r@   ÚbÚ
permc_specÚuse_umfpackÚis_pydata_sparseÚpydata_sparse_clsÚb_is_sparseÚb_is_vectorÚresult_dtypeÚMÚNÚb_vecÚ
umf_familyÚumfÚxÚflagr;   r?   rV   ÚinfoÚ
AfactsolveÚ	data_segsÚrow_segsÚcol_segsÚjÚbjÚxjÚwÚsegment_lengthÚsparse_dataÚ	idx_dtypeÚ
sparse_rowÚ
sparse_cols!                                    r#   r   r   …   s�  € ôd *¨!Ó,ÐÙ'7˜Ÿš¸TÐÜ& qÓ)€AÜ& qÓ)€Aä�QŒK˜AŸH™H¨Ñ6Ü�a‹LˆÜÐ=Ü$°õ	4ô ˜1“+€KÙÜ�A‹JˆØ—F‘F˜a‘KÒE Q§V¡V¨q¡[Ò%D°Q·W±W¸Q±ZÀ1±_€Kð ×ÑÔØ	�‰‹€AÜ×#Ñ# A§G¡G¨Q¯W©WÓ5€LØ‡w�w�,ÒØ�H‰H�\Ó"ˆØ‡w�w�,ÒØ�H‰H�\Ó"ˆð �7‰7�D€A€qØ	ˆQŠÜÐ<¸aÀ¸V¸HÀAÐFÓGÐGàˆA�G‰G�A‰J‚ÜÐ<¸Q¿W¹W¸IÀSÈÏÉÐQRÉÈÐTUÐVÓWÐWä”:˜sÔ#Ü#�|Œ
ŒàÒ.¤*§,¡,€Ká‘{ÙØ—I‘I“K‰EàˆEÜ˜ Q§W¡WÔ-×3Ñ3Ó5ˆåÜÐ?Ó@Ð@à�7‰7�<‰<˜tÑ#Üð Eó Fð Fô (¨Ó*‰ˆ
�AÜ×$Ñ$ ZÓ0ˆØ�L‰Lœ×*Ñ*¨A¨uØ'+ð ó -ˆðp €Hñk ™;Ø—	‘	“ˆAØˆKáØ�x‰x˜5Ò Ø‘à�à—i‘i×&Ñ&¤r§w¡w°UÐ&Ó;ˆGØ—X‘X—_‘_¤R§W¡W°5�_Ó9ˆFÜ :Ô.ˆGÜ—m‘m A q§u¡u¨a¯f©f°g¸vØ$% t°Wô>‰GˆAˆtà�qŠyÜÐ1Ô3DÐQRÕSØ—‘”r—v‘v”ÙØ—G‘G“I�ðD €Hô? $ A›ˆJà—H‘H Ò%Ô);¸AÔ)>Üð 3ä,¸õ<ô ˜a“L�ð ˆIØˆHØˆHÜ˜1Ÿ7™7 1™:Ó&ò C�Ø’q˜!�t‘W—_‘_Ó&×,Ñ,Ó.�Ù “^�Ü—N‘N 2Ó&�Ø!"§¡¨¡�Ø—‘ Ô"Ø—‘¤§¡¨¸ÄÔ EÔFØ× Ñ ¤§¡¨B¨q©E¸¿¹Ô!AÕBðCô Ÿ.™.¨Ó3ˆKÜ'¬s°1·7±7«|Ô<ˆIÜŸ™¨¸	ÔBˆJÜŸ™¨¸	ÔBˆJØ—‘˜[¨:°zÐ*BÐCØ!"§¡°·±ð ó 9ˆAñ  Ø%×7Ñ7¸Ó:�à€Hr"   c           
      ól  — t        | «      r0t        | «      }|dœd„}| j                  «       j                  «       } nt        }t        | «      r| j                  dk(  st	        | «      } t        dt        d¬«       | j                  «        | j                  «       } | j                  \  }}	||	k7  rt        d«      ‚t        | t        j                  d«      \  }
}t!        ||||¬	«      }|�|j#                  |«       |d
   dk(  rd|d<   t%        j&                  |	| j(                  | j*                  |
||d|¬«      S )aÝ  
    Compute the LU decomposition of a sparse, square matrix.

    Parameters
    ----------
    A : sparse array or matrix
        Sparse array to factorize. Most efficient when provided in CSC
        format. Other formats will be converted to CSC before factorization.
    permc_spec : str, optional
        How to permute the columns of the matrix for sparsity preservation.
        (default: 'COLAMD')

        - ``NATURAL``: natural ordering.
        - ``MMD_ATA``: minimum degree ordering on the structure of A^T A.
        - ``MMD_AT_PLUS_A``: minimum degree ordering on the structure of A^T+A.
        - ``COLAMD``: approximate minimum degree column ordering

    diag_pivot_thresh : float, optional
        Threshold used for a diagonal entry to be an acceptable pivot.
        See SuperLU user's guide for details [1]_
    relax : int, optional
        Expert option for customizing the degree of relaxing supernodes.
        See SuperLU user's guide for details [1]_
    panel_size : int, optional
        Expert option for customizing the panel size.
        See SuperLU user's guide for details [1]_
    options : dict, optional
        Dictionary containing additional expert options to SuperLU.
        See SuperLU user guide [1]_ (section 2.4 on the 'Options' argument)
        for more details. For example, you can specify
        ``options=dict(Equil=False, IterRefine='SINGLE'))``
        to turn equilibration off and perform a single iterative refinement.

    Returns
    -------
    invA : scipy.sparse.linalg.SuperLU
        Object, which has a ``solve`` method.

    See also
    --------
    spilu : incomplete LU decomposition

    Notes
    -----
    This function uses the SuperLU library.

    References
    ----------
    .. [1] SuperLU https://portal.nersc.gov/project/sparse/superlu/

    Examples
    --------
    >>> import numpy as np
    >>> from scipy.sparse import csc_array
    >>> from scipy.sparse.linalg import splu
    >>> A = csc_array([[1., 0., 0.], [5., 0., 2.], [0., -1., 0.]], dtype=float)
    >>> B = splu(A)
    >>> x = np.array([1., 2., 3.], dtype=float)
    >>> B.solve(x)
    array([ 1. , -3. , -1.5])
    >>> A.dot(B.solve(x))
    array([ 1.,  2.,  3.])
    >>> B.solve(A.dot(x))
    array([ 1.,  2.,  3.])
    ©Úclsc                 ó0   — | j                  t        |Ž «      S ©N©rw   r
   ©r—   Úas     r#   Úcsc_construct_funcz splu.<locals>.csc_construct_funcŽ  ó   € Ø×(Ñ(¬°A¨Ó7Ð7r"   rK   ú&splu converted its input to CSC formatrM   rN   úcan only factor square matricesÚSuperLU)ÚDiagPivotThreshrU   Ú	PanelSizeÚRelaxrU   ÚNATURALTÚSymmetricModeF©r�   ÚilurV   ©r   ÚtypeÚto_scipy_sparseÚtocscr
   r   rZ   r   r   r\   r]   rX   r=   r   r4   ri   rj   Úupdater   Úgstrfrl   rm   )r@   ry   Údiag_pivot_threshÚrelaxÚ
panel_sizerV   ÚA_clsr�   r€   r�   r;   r?   Ú_optionss                r#   r   r   H  s  € ôH ˜!ÔÜ�Q“ˆØ',ô 	8à×ÑÓ×%Ñ%Ó'‰ä&Ðä�QŒK˜AŸH™H¨Ò-Ü�a‹LˆÜÐ5Ü$°õ	4ð ×ÑÔØ	�‰‹€Aà�7‰7�D€A€qØ	ˆQŠÜÐ:Ó;Ð;ä.¨q´"·'±'¸9ÓE�O€GˆVäÐ$5¸zØ(°ô7€HàÐØ�‰˜Ô ð 	�Ñ˜yÒ(Ø$(ˆ�Ñ!ä�>‰>˜!˜QŸU™U A§F¡F¨G°VØ-?Ø#¨Xô7ð 7r"   c	           
      ór  — t        | «      r0t        | «      }	|	dœd„}
| j                  «       j                  «       } nt        }
t        | «      r| j                  dk(  st	        | «      } t        dt        d¬«       | j                  «        | j                  «       } | j                  \  }}||k7  rt        d«      ‚t        | t        j                  d«      \  }}t!        |||||||¬	«      }|�|j#                  |«       |d
   dk(  rd|d<   t%        j&                  || j(                  | j*                  |||
d|¬«      S )aÌ  
    Compute an incomplete LU decomposition for a sparse, square matrix.

    The resulting object is an approximation to the inverse of `A`.

    Parameters
    ----------
    A : (N, N) array_like
        Sparse array to factorize. Most efficient when provided in CSC format.
        Other formats will be converted to CSC before factorization.
    drop_tol : float, optional
        Drop tolerance (0 <= tol <= 1) for an incomplete LU decomposition.
        (default: 1e-4)
    fill_factor : float, optional
        Specifies the fill ratio upper bound (>= 1.0) for ILU. (default: 10)
    drop_rule : str, optional
        Comma-separated string of drop rules to use.
        Available rules: ``basic``, ``prows``, ``column``, ``area``,
        ``secondary``, ``dynamic``, ``interp``. (Default: ``basic,area``)

        See SuperLU documentation for details.

    Remaining other options
        Same as for `splu`

    Returns
    -------
    invA_approx : scipy.sparse.linalg.SuperLU
        Object, which has a ``solve`` method.

    See also
    --------
    splu : complete LU decomposition

    Notes
    -----
    To improve the better approximation to the inverse, you may need to
    increase `fill_factor` AND decrease `drop_tol`.

    This function uses the SuperLU library.

    Examples
    --------
    >>> import numpy as np
    >>> from scipy.sparse import csc_array
    >>> from scipy.sparse.linalg import spilu
    >>> A = csc_array([[1., 0., 0.], [5., 0., 2.], [0., -1., 0.]], dtype=float)
    >>> B = spilu(A)
    >>> x = np.array([1., 2., 3.], dtype=float)
    >>> B.solve(x)
    array([ 1. , -3. , -1.5])
    >>> A.dot(B.solve(x))
    array([ 1.,  2.,  3.])
    >>> B.solve(A.dot(x))
    array([ 1.,  2.,  3.])
    r–   c                 ó0   — | j                  t        |Ž «      S r™   rš   r›   s     r#   r�   z!spilu.<locals>.csc_construct_funcî  rž   r"   rK   z'spilu converted its input to CSC formatrM   rN   r    r¡   )ÚILU_DropRuleÚILU_DropTolÚILU_FillFactorr¢   rU   r£   r¤   rU   r¥   Tr¦   r§   r©   )r@   Údrop_tolÚfill_factorÚ	drop_rulery   r¯   r°   r±   rV   r²   r�   r€   r�   r;   r?   r³   s                   r#   r   r   ±  s(  € ôv ˜!ÔÜ�Q“ˆØ',ô 	8à×ÑÓ×%Ñ%Ó'‰ä&Ðä�QŒK˜AŸH™H¨Ò-Ü�a‹LˆÜÐ6Ü$°õ	4ð ×ÑÔØ	�‰‹€Aà�7‰7�D€A€qØ	ˆQŠÜÐ:Ó;Ð;ä.¨q´"·'±'¸9ÓE�O€GˆVä ¸Ø#.Ø$5¸zØ(°ô7€Hð ÐØ�‰˜Ô ð 	�Ñ˜yÒ(Ø$(ˆ�Ñ!ä�>‰>˜!˜QŸU™U A§F¡F¨G°VØ-?Ø"¨Hô6ð 6r"   c                 óP  ‡ ‡— t        ‰ «      r‰ j                  «       j                  «       Š t        t        d«      st
         t        _        t        j                  r·t
        rt        d«      ‚t        ‰ «      r‰ j                  dk(  st        ‰ «      Š t        dt        d¬«       ‰ j                  «       Š ‰ j                  j                  dvrt!        d«      ‚t#        ‰ «      \  }Š t%        j&                  |«      Š‰j)                  ‰ «       ˆ ˆfd	„}|S t+        ‰ «      j,                  S )
a�  
    Return a function for solving a sparse linear system, with A pre-factorized.

    Parameters
    ----------
    A : (N, N) array_like
        Input. A in CSC format is most efficient. A CSR format matrix will
        be converted to CSC before factorization.

    Returns
    -------
    solve : callable
        To solve the linear system of equations given in `A`, the `solve`
        callable should be passed an ndarray of shape (N,).

    Examples
    --------
    >>> import numpy as np
    >>> from scipy.sparse.linalg import factorized
    >>> from scipy.sparse import csc_array
    >>> A = np.array([[ 3. ,  2. , -1. ],
    ...               [ 2. , -2. ,  4. ],
    ...               [-1. ,  0.5, -1. ]])
    >>> solve = factorized(csc_array(A)) # Makes LU decomposition.
    >>> rhs1 = np.array([1, -2, 0])
    >>> solve(rhs1) # Uses the LU factors.
    array([ 1., -2., -2.])

    r'   rP   rK   rŸ   rM   rN   rQ   rR   c                 ó¨   •— t        j                  dd¬«      5  ‰j                  t        j                  ‰| d¬«      }d d d «       |S # 1 sw Y   S xY w)NÚignore)ÚdivideÚinvalidTrS   )r4   ÚerrstateÚsolver(   rh   )rx   Úresultr@   r„   s     €€r#   rÂ   zfactorized.<locals>.solveL  sN   ø€ Ü—‘ H°hÔ?ñ PàŸ™¤7×#4Ñ#4°a¸È$˜ÓO�÷Pð ˆM÷	Pð ˆMús   ™$AÁA)r   r«   r¬   r`   r%   ra   r'   rd   r   rZ   r
   r   r   r]   r3   re   r=   rH   r(   rf   Únumericr   rÂ   )r@   rƒ   rÂ   r„   s   `  @r#   r   r     sñ   ù€ ô< ˜!ÔØ×ÑÓ×%Ñ%Ó'ˆä”:˜sÔ#Ü#�|Œ
Œä‡|‚|ÝÜÐ?Ó@Ð@ä˜” §¡¨EÒ 1Ü˜!“ˆAÜÐ9Ü(°Qõ8ð �K‰K‹Mˆà�7‰7�<‰<˜tÑ#Üð Eó Fð Fô (¨Ó*‰ˆ
�AÜ×$Ñ$ ZÓ0ˆð 	�‰�AŒõ	ð ˆä�A‹w�}‰}Ðr"   c                 ó  — t        | «      r| j                  «       j                  «       } d}t        | «      r | j                  dk(  r| j
                  } d}| }t        | «      r| j                  dk(  st        dt        d¬«       t        | «      } n|s| j                  «       } | j                  \  }}||k7  rt        d| j                  › d	�«      ‚|r5t        «       5  t        d
t        «       | j                  d«       ddd«       nn| j                  «       }	t!        j"                  |	dk(  «      rt%        d«      ‚d|	z  }
|dk(  r| t'        |
«      z  } n"| j
                  t'        |
«      z  j
                  } | j)                  «        t!        j*                  |«      }|j,                  dvrt        d|j                  › d	�«      ‚||j                  d   k7  r&t        d| j                  › d|j                  › d	�«      ‚t!        j.                  t!        j.                  | j0                  t         j2                  «      |j0                  «      }| j0                  |k7  r| j5                  |«      } |j0                  |k7  r|j5                  |«      }n|s|j                  «       }|r| }t        ||f|¬«      }n!t7        ||d¬«      }| }|j                  d«       t9        j:                  |||j<                  |j>                  |j@                  |jB                  ||j<                  |j>                  |j@                  |jB                  |«      \  }}|rt%        d«      ‚|s2 
jD                  dgdgtG        |j                  «      dz
  z  ¢­Ž }
||
z  }|S # 1 sw Y   �ŒxY w)a—  
    Solve the equation ``A x = b`` for `x`, assuming A is a triangular matrix.

    Parameters
    ----------
    A : (M, M) sparse array or matrix
        A sparse square triangular matrix. Should be in CSR or CSC format.
    b : (M,) or (M, N) array_like
        Right-hand side matrix in ``A x = b``
    lower : bool, optional
        Whether `A` is a lower or upper triangular matrix.
        Default is lower triangular matrix.
    overwrite_A : bool, optional
        Allow changing `A`.
        Enabling gives a performance gain. Default is False.
    overwrite_b : bool, optional
        Allow overwriting data in `b`.
        Enabling gives a performance gain. Default is False.
        If `overwrite_b` is True, it should be ensured that
        `b` has an appropriate dtype to be able to store the result.
    unit_diagonal : bool, optional
        If True, diagonal elements of `a` are assumed to be 1.

        .. versionadded:: 1.4.0

    Returns
    -------
    x : (M,) or (M, N) ndarray
        Solution to the system ``A x = b``. Shape of return matches shape
        of `b`.

    Raises
    ------
    LinAlgError
        If `A` is singular or not triangular.
    ValueError
        If shape of `A` or shape of `b` do not match the requirements.

    Notes
    -----
    .. versionadded:: 0.19.0

    Examples
    --------
    >>> import numpy as np
    >>> from scipy.sparse import csc_array
    >>> from scipy.sparse.linalg import spsolve_triangular
    >>> A = csc_array([[3, 0, 0], [1, -1, 0], [2, 0, 1]], dtype=float)
    >>> B = np.array([[2, 0], [-1, 0], [2, 0]], dtype=float)
    >>> x = spsolve_triangular(A, B)
    >>> np.allclose(A.dot(x), B)
    True
    r�   rL   ÚTrK   z?CSC or CSR matrix format is required. Converting to CSC matrix.rM   rN   z+A must be a square matrix but its shape is ú.r¾   r   Nr   z&A is singular: zero entry on diagonal.)r   rM   z)b must have 1 or 2 dims but its shape is zlThe size of the dimensions of A must be equal to the size of the first dimension of b but the shape of A is z and the shape of b is r2   )r3   rZ   zA is singular.éÿÿÿÿ)$r   r«   r¬   r   rZ   rÆ   r   r   r
   r>   rX   r=   r   r   ÚsetdiagÚdiagonalr4   Úanyr   r   r\   Ú
asanyarrayr[   r^   r3   Úfloat32r_   r   r   Úgstrsrl   rm   r;   r?   ÚreshapeÚlen)r@   rx   ÚlowerÚoverwrite_AÚoverwrite_bÚunit_diagonalÚtransr€   r�   ÚdiagÚinvdiagr   ÚLÚUr…   r‡   s                   r#   r   r   X  s   € ôp ˜!ÔØ×ÑÓ×%Ñ%Ó'ˆà€EÜ�„{�q—x‘x 5Ò(Ø�C‰CˆØˆØ�	ˆä�QŒK˜AŸH™H¨Ò-ÜÐNÜ$°õ	4ä�a‹L‰ÙØ�F‰F‹Hˆð �7‰7�D€A€qØˆA‚vÜØ9¸!¿'¹'¸À!ÐDóFð 	Fñ ÜÓñ 	Ü˜Ô#:Ô;Ø�I‰I�aŒL÷	ð 	ð �z‰z‹|ˆÜ�6‰6�$˜!‘)ÔÜØ8ó:ð :à�D‘&ˆØ�CŠ<Ø”K Ó(Ñ(‰Aà—‘”{ 7Ó+Ñ+×.Ñ.ˆAð ×ÑÔä
�‰�aÓ€Aà‡v�v�VÑÜØ7¸¿¹°yÀÐBóDð 	DàˆA�G‰G�A‰J‚ÜðJà�w‰wˆiÐ.¨q¯w©w¨i°qð:ó
ð 	
ô ×#Ñ#¤B×$4Ñ$4°Q·W±W¼b¿j¹jÓ$IÈ1Ï7É7ÓS€LØ‡w�w�,ÒØ�H‰H�\Ó"ˆØ‡w�w�,ÒØ�H‰H�\Ó"‰ÙØ�F‰F‹HˆáØˆÜ�q˜!�f LÔ1‰ä�a˜|°EÔ:ˆØˆØ	�	‰	�!Œä�n‰n˜UØ §¡ q§v¡v¨q¯y©y¸!¿(¹(Ø §¡ q§v¡v¨q¯y©y¸!¿(¹(Øó �G€A€tñ ÜÐ*Ó+Ð+áØ!�'—/‘/ "ÐB¨¨¬s°1·7±7«|¸aÑ/?Ñ(@ÒBˆØ�‰Kˆà€H÷q	ñ 	ús   Ã"NÎNc                 óÜ  — t        | «      r| j                  dv st        dt        d¬«       t	        | «      } | j                  dk(  r:| j
                  j                  «       dk  | j
                  j                  «       dk\  fS | j                  dk(  r5| j                  \  }}||k  j                  «       ||k\  j                  «       fS | j                  dk(  r@t        d	„ | j                  «       D «       «      t        d
„ | j                  «       D «       «      fS | j                  dk(  rNt        d„ t        | j                  «      D «       «      }t        d„ t        | j                  «      D «       «      }||fS | j                  | j                  }}t        |«      dz
  }d\  }}|dz  ddfD ]E  }|||   ||dz       }|xr ||k\  j                  «       }|xr ||k  j                  «       }|rŒB|rŒE y t!        j"                  t!        j$                  |«      t!        j&                  |«      «      }|}|xr ||k\  j                  «       }|xr ||k  j                  «       }| j                  dk(  r||fS ||fS )aÔ  Returns 2-tuple indicating lower/upper triangular structure for sparse ``A``

    Checks for triangular structure in ``A``. The result is summarized in
    two boolean values ``lower`` and ``upper`` to designate whether ``A`` is
    lower triangular or upper triangular respectively. Diagonal ``A`` will
    result in both being True. Non-triangular structure results in False for both.

    Only the sparse structure is used here. Values are not checked for zeros.

    This function will convert a copy of ``A`` to CSC format if it is not already
    CSR or CSC format. So it may be more efficient to convert it yourself if you
    have other uses for the CSR/CSC version.

    If ``A`` is not square, the portions outside the upper left square of the
    matrix do not affect its triangular structure. You probably want to work
    with the square portion of the matrix, though it is not requred here.

    Parameters
    ----------
    A : SciPy sparse array or matrix
        A sparse matrix preferrably in CSR or CSC format.

    Returns
    -------
    lower, upper : 2-tuple of bool

        .. versionadded:: 1.15.0

    Examples
    --------
    >>> import numpy as np
    >>> from scipy.sparse import csc_array, eye_array
    >>> from scipy.sparse.linalg import is_sptriangular
    >>> A = csc_array([[3, 0, 0], [1, -1, 0], [2, 0, 1]], dtype=float)
    >>> is_sptriangular(A)
    (True, False)
    >>> D = eye_array(3, format='csr')
    >>> is_sptriangular(D)
    (True, True)
    )rK   rL   ÚcooÚdiaÚdokÚlilzCis_sptriangular needs sparse and not BSR format. Converting to CSR.rM   rN   rÜ   r   rÛ   rÝ   c              3   ó,   K  — | ]  \  }}||k  –— Œ y ­wr™   r!   ©Ú.0ÚrÚcs      r#   ú	<genexpr>z"is_sptriangular.<locals>.<genexpr>  s   è ø€ Ò/™d˜a �1˜•6Ñ/ùó   ‚c              3   ó,   K  — | ]  \  }}||k\  –— Œ y ­wr™   r!   rà   s      r#   rä   z"is_sptriangular.<locals>.<genexpr>  s   è ø€ Ò4QÁÀÀ1°Q¸!µVÑ4Qùrå   rÞ   c              3   ó:   K  — | ]  \  }}|D ]	  }||k  –— Œ Œ y ­wr™   r!   ©rá   ÚrowÚcolsÚcols       r#   rä   z"is_sptriangular.<locals>.<genexpr>  ó$   è ø€ ÒR¡9 3¨ÈTÒRÀc�C˜3•JÐR�JÑRùó   ‚c              3   ó:   K  — | ]  \  }}|D ]	  }||k\  –— Œ Œ y ­wr™   r!   rè   s       r#   rä   z"is_sptriangular.<locals>.<genexpr>  rì   rí   r   )TTrÈ   )FFrL   )r   rZ   r   r   r	   Úoffsetsrv   ÚminÚcoordsÚallÚkeysÚ	enumerateÚrowsr?   r;   rÐ   r4   ÚrepeatÚarangeÚdiff)	r@   rõ   rê   rÑ   Úupperr?   r;   r�   rë   s	            r#   r   r   â  s*  € ôR �QŒK˜AŸH™HÐ(RÑRÜÐRÜ$°õ	4ä�a‹Lˆð 	‡x�x�5ÒØ�y‰y�}‰}‹ !Ñ# Q§Y¡Y§]¡]£_¸Ñ%9Ð9Ð9Ø	
�‰�UÒ	Ø—X‘X‰
ˆˆdØ˜‘×!Ñ!Ó# d¨d¡l×%7Ñ%7Ó%9Ð9Ð9Ø	
�‰�UÒ	ÜÑ/ a§f¡f£hÔ/Ó/´Ñ4QÈÏÉËÔ4QÓ1QÐQÐQØ	
�‰�UÒ	ÜÑR´	¸!¿&¹&Ó0AÔRÓRˆÜÑR´	¸!¿&¹&Ó0AÔRÓRˆØ�eˆ|Ðà—h‘h §	¡	ˆG€FÜˆF‹�a‰€Aà�L€Eˆ5à�Q‘˜˜2ˆò  ˆØ�v˜c‘{ 6¨#°©'¡?Ð3ˆØÒ-˜3 $™;×+Ñ+Ó-ˆØÒ-˜3 $™;×+Ñ+Ó-ˆÚšUÙð ô �9‰9”R—Y‘Y˜q“\¤2§7¡7¨6£?Ó3€DØ€DØÒ*�t˜t‘|×(Ñ(Ó*€EØÒ*�t˜t‘|×(Ñ(Ó*€EØ‡x�x�5ÒØ�eˆ|ÐØ�%ˆ<Ðr"   c                 ó"  — t        | «      r| j                  dv st        dt        d¬«       t	        | «      } | j                  dk(  ret        d| j                  j                  «       j                  «        «      t        d| j                  j                  «       j                  «       «      fS | j                  dv rx| j                  | j                  }}t        |«      dz
  }t        j                  t        j                  |«      t        j                  |«      «      |z
  }| j                  d	k(  rƒ| }n| j                  d
k(  r | j                   d   | j                   d   z
  }nP| j                  dk(  rA| j#                  «       D ��cg c]
  \  }}||z
  ‘Œ c}}dgz   }t        |«       t        |«      fS t        t        j                  «      j                  «        d«      t        t        j
                  |«      j                  «       d«      fS c c}}w )ab  Return the lower and upper bandwidth of a 2D numeric array.

    Computes the lower and upper limits on the bandwidth of the
    sparse 2D array ``A``. The result is summarized as a 2-tuple
    of positive integers ``(lo, hi)``. A zero denotes no sub/super
    diagonal entries on that side (tringular). The maximum value
    for ``lo``(``hi``) is one less than the number of rows(cols).

    Only the sparse structure is used here. Values are not checked for zeros.

    Parameters
    ----------
    A : SciPy sparse array or matrix
        A sparse matrix preferrably in CSR or CSC format.

    Returns
    -------
    below, above : 2-tuple of int
        The distance to the farthest non-zero diagonal below/above the
        main diagonal.

        .. versionadded:: 1.15.0

    Examples
    --------
    >>> import numpy as np
    >>> from scipy.sparse.linalg import spbandwidth
    >>> from scipy.sparse import csc_array, eye_array
    >>> A = csc_array([[3, 0, 0], [1, -1, 0], [2, 0, 1]], dtype=float)
    >>> spbandwidth(A)
    (2, 0)
    >>> D = eye_array(3, format='csr')
    >>> spbandwidth(D)
    (0, 0)
    )rK   rL   rÛ   rÜ   rÝ   zCspbandwidth needs sparse format not LIL and BSR. Converting to CSR.rM   rN   rÜ   r   rJ   r   rL   rÛ   rÝ   )r   rZ   r   r   r	   rv   rï   rð   Úitemr?   r;   rÐ   r4   rö   r÷   rø   rñ   ró   )r@   r?   r;   r�   Úgaprâ   rã   s          r#   r   r   2  s’  € ôH �QŒK˜AŸH™HÐ(KÑKÜÐRÜ$°õ	4ä�a‹Lˆð 	‡x�x�5ÒÜ�1�q—y‘y—}‘}“×+Ñ+Ó-Ð-Ó.´°A°q·y±y·}±}³×7KÑ7KÓ7MÓ0NÐNÐNØ‡x�x�>Ñ!ØŸ(™( A§I¡I�ˆÜ�‹K˜!‰OˆÜ�i‰iœŸ	™	 !›¤b§g¡g¨f£oÓ6¸Ñ@ˆØ�8‰8�uÒØ�$‰CØ	
�‰�UÒ	Ø�h‰h�q‰k˜AŸH™H Q™KÑ'‰Ø	
�‰�UÒ	Ø#$§6¡6£8×,™4˜1˜a��A“Ó,°¨sÑ2ˆÜ�C“ˆyœ#˜c›(Ð"Ð"Ü”—‘�s“× Ñ Ó"Ð" AÓ&¬¬B¯F©F°3«K×,<Ñ,<Ó,>ÀÓ(BÐBÐBùó -s   ÆH)NT)NNNNN)NNNNNNNN)TFFF)+Úwarningsr   r   r   Únumpyr4   r   Úscipy.sparser   r   r	   r
   r   r   Úscipy.sparse._sputilsr   r   r   r   Úscipy.linalgr   r>   Ú	threadingÚ r   ra   Úscikits.umfpackr(   ÚImportErrorÚlocalr%   Ú__all__ÚUserWarningr   r   rH   r   r   r   r   r   r   r   r!   r"   r#   ú<module>r	     s×   ðß 7Ñ 7ã Ý ÷H÷ H÷Nó Nå $Û Û å à€ðÝ%ð ˆY�_‰_Ó€
òX€ô	˜ô 	òAMòF óD@ðF 04Ø.2óf7ðR JNØGKó_6òDBðJ INØ%*óGòTMó`7CøðA ò Ø‚Hðús   ÁB ÂBÂB