
    (phw                     L   S SK JrJrJr  S SKrS SKJr  S SKJrJ	r	J
r
JrJrJr  S SKJrJrJrJr  S SKJr  S SKrS SKrSSKJr  S	r S SKJr  \R:                  " 5       q/ SQr " S S\ 5      r!S r"S r#SS jr$  SS jr%  SS jr&S r'  SS jr(S r)S r*g! \ a    S
r NTf = f)    )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                       \ rS rSrSrg)r       N)__name__
__module____qualname____firstlineno____static_attributes__r       W/var/www/html/venv/lib/python3.13/site-packages/scipy/sparse/linalg/_dsolve/linsolve.pyr   r      s    r%   r   c                      SU ;   a  U S   [         l        [         R                  (       a  SU ;   a  [        R                  " U S   S9  ggg)a  
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f5J.KL 8|r%   c                    [         R                  [         R                  4S[         R                  [         R                  4S[         R                  [         R                  4S[         R                  [         R                  4S0n[        [         U R                  R                  5      n[        [         U R                  R                  R                  5      n XU4   nUS	   S
-   n[        R                  " U 5      n[         R                  " U R                  [         R                  S9Ul        [         R                  " U R                  [         R                  S9Ul        XG4$ ! [         a  nSU SU S3n[        U5      UeSnAff = f)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getattrr6   nameindicesKeyError
ValueErrorcopyr   indptr)A	_familiesf_typei_typefamilyemsgA_news           r&   _get_umf_familyrK   c   s(    
RXX	!4	RXX	!4	I R&F R--.F%F+, AY_FIIaLE::ahhbhh7ELJJqyy9EM=  %77=hk&QRTo1$%s   E! !
F+F  Fc                 2   [        U5      nU(       a  UR                  OSn[        U 5      n [        U5      n[        U 5      (       a  U R                  S;   d  [        U 5      n [        S[        SS9  [        U5      nU(       d  [        U5      nUR                  S:H  =(       d(    UR                  S:H  =(       a    UR                  S   S:H  nU R                  5         U R                  5       n [        R                  " U R                  UR                  5      nU R                  U:w  a  U R!                  U5      n UR                  U:w  a  UR!                  U5      nU R                  u  pX:w  a  [#        SX4 S35      eXR                  S	   :w  a)  [#        S
U R                   SUR                  S	    S35      e[%        [&        S5      (       d  [(        (       + [&        l        U=(       a    [&        R*                  nU(       a  U(       a  U(       a  UR-                  5       nOUn[        XR                  S9R/                  5       n[(        (       a  [1        S5      eU R                  R2                  S;  a  [#        S5      e[5        U 5      u  p[6        R8                  " U5      nUR;                  [6        R<                  XSS9nU$ U(       a  U(       a  UR-                  5       nSnU(       d  U R                  S:X  a  SnOS	nU R>                  R!                  [        R@                  SS9nU RB                  R!                  [        R@                  SS9n[E        US9n[F        RH                  " XRJ                  U RL                  UUXUS9u  nnUS	:w  a.  [        S[N        SS9  URQ                  [        RR                  5        U(       a  UR/                  5       nU$ [U        U 5      nUR                  S:X  d*  [        U5      (       d  [        S[        SS9  [        U5      n/ n/ n/ n[W        UR                  S   5       H  nUSS2U4   R-                  5       R/                  5       nU" U5      n[        RX                  " U5      nUR                  S	   nUR[                  U5        UR[                  [        R\                  " UU[^        S95        UR[                  [        R                  " UU   U R                  S95        M     [        R`                  " U5      n[c        [e        UR                  5      S9n[        R`                  " UUS9n[        R`                  " UUS9n U R                  UUU 44UR                  U R                  S9nU(       a  URg                  U5      nU$ )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 r3   r   z!matrix - rhs dimension mismatch (z - r*   r5   Scikits.umfpack not installed.dD\convert matrix data to double, please, using .astype(), or set linsolve.useUmfpack.u = FalseTautoTransposeFrN   )rA   )ColPerm)optionszMatrix is exactly singularzCspsolve is more efficient when sparse b is in the CSC matrix format)maxval)shaper6   )4r   	__class__r   r   formatr
   r   r   r   ndimr[   sum_duplicates	_asfptyper7   promote_typesr6   astyper@   hasattrr(   noScikitr*   toarrayravelRuntimeErrorcharrK   r+   UmfpackContextlinsolve	UMFPACK_Ar>   intcrB   dictr   gssvnnzdatar   fillnanr   rangeflatnonzeroappendfullintconcatenater   maxfrom_scipy_sparse)!rC   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>   rB   rY   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QKKAHH6aL=$	4 1+KAJFFaKEQVVq[%DQWWQZ1_K 	A##AGGQWW5Lww,HH\"ww,HH\" 77DA	<aVHAFGGGGAJ<QWWISQRTUVWW:s###|
.*,,K{IIKEEWW-3358?@@77<<t# E F F (*
$$Z0LL**A'+  -p Hk ;		AKxx5 ii&&rwwU&;GXX__RWW5_9F:.GmmAuuaffgv$%W>GAtqy13DQRSrvvGGID H? $AJHH%);A)>)> 3,< aL IHH1771:&q!tW__&,,.^NN2&!"" EF  BqE!AB ' ..3K's177|<I	BJ	BJ[:z*BC!"  9A  %77:Hr%   c                 l   [        U 5      (       a1  [        U 5      nUS.S jnU R                  5       R                  5       n O[        n[        U 5      (       a  U R                  S:X  d  [	        U 5      n [        S[        SS9  U R                  5         U R                  5       n U R                  u  pX:w  a  [        S5      e[        U [        R                  S5      u  p[!        X!XCS	9nUb  UR#                  U5        US
   S:X  a  SUS'   [$        R&                  " XR(                  U R*                  XUSUS9$ )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    U R                  [        U6 5      $ Nrz   r
   r   as     r&   csc_construct_func splu.<locals>.csc_construct_func      ((A77r%   rN   &splu converted its input to CSC formatrP   rQ   can only factor square matricesSuperLU)DiagPivotThreshrX   	PanelSizeRelaxrX   NATURALTSymmetricModeFr   ilurY   r   typeto_scipy_sparsetocscr
   r   r]   r   r   r_   r`   r[   r@   r   r7   rl   rm   updater   gstrfro   rp   )rC   r|   diag_pivot_threshrelax
panel_sizerY   A_clsr   r   r   r>   rB   _optionss                r&   r   r   H  s   H !Q', 	8%%'&QKKAHH-aL5$	4 	A77DA	:;;.q"''9EOG$5(7H  	y($(!>>!UUAFFG-?#X7 7r%   c	                 p   [        U 5      (       a1  [        U 5      n	U	S.S jn
U R                  5       R                  5       n O[        n
[        U 5      (       a  U R                  S:X  d  [	        U 5      n [        S[        SS9  U R                  5         U R                  5       n U R                  u  pX:w  a  [        S5      e[        U [        R                  S5      u  p[!        X1UXTXvS	9nUb  UR#                  U5        US
   S:X  a  SUS'   [$        R&                  " XR(                  U R*                  XU
SUS9$ )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    U R                  [        U6 5      $ r   r   r   s     r&   r   !spilu.<locals>.csc_construct_func  r   r%   rN   z'spilu converted its input to CSC formatrP   rQ   r   r   )ILU_DropRuleILU_DropTolILU_FillFactorr   rX   r   r   rX   r   Tr   r   r   )rC   drop_tolfill_factor	drop_ruler|   r   r   r   rY   r   r   r   r   r>   rB   r   s                   r&   r   r     s   v !Q', 	8%%'&QKKAHH-aL6$	4 	A77DA	:;;.q"''9EOG#.$5(7H   	y($(!>>!UUAFFG-?"H6 6r%   c                   ^ ^ [        T 5      (       a  T R                  5       R                  5       m [        [        S5      (       d  [
        (       + [        l        [        R                  (       a  [
        (       a  [        S5      e[        T 5      (       a  T R                  S:X  d  [        T 5      m [        S[        SS9  T R                  5       m T R                  R                  S;  a  [!        S5      e[#        T 5      u  nm [$        R&                  " U5      mTR)                  T 5        U U4S	 jnU$ [+        T 5      R,                  $ )
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*   rS   rN   r   rP   rQ   rT   rU   c                    > [         R                  " SSS9   TR                  [        R                  TU SS9nS S S 5        U$ ! , (       d  f       W$ = f)Nignore)divideinvalidTrV   )r7   errstatesolver+   rk   )r{   resultrC   r   s     r&   r   factorized.<locals>.solveL  sK    Hh?7#4#4a$O @ M	 @? Ms   !A
A)r   r   r   rc   r(   rd   r*   rg   r   r]   r
   r   r   r`   r6   rh   r@   rK   r+   ri   numericr   r   )rC   r   r   r   s   `  @r&   r   r     s    < !%%':s###|
||8?@@E 1!A9(Q8 KKM77<<t# E F F (*
A$$Z0 	A	 Aw}}r%   c                    [        U 5      (       a  U R                  5       R                  5       n Sn[        U 5      (       a%  U R                  S:X  a  U R
                  n SnU(       + n[        U 5      (       a  U R                  S:X  d  [        S[        SS9  [        U 5      n OU(       d  U R                  5       n U R                  u  pxXx:w  a  [        SU R                   S	35      eU(       a5  [        5          [        S
[        5        U R                  S5        SSS5        OuU R                  5       n	[         R"                  " U	S:H  5      (       a  [%        S5      eSU	-  n
US:X  a  U ['        U
5      -  n O"U R
                  ['        U
5      -  R
                  n U R)                  5         [         R*                  " U5      nUR,                  S;  a  [        SUR                   S	35      eXqR                  S   :w  a&  [        SU R                   SUR                   S	35      e[         R.                  " [         R.                  " U R0                  [         R2                  5      UR0                  5      nU R0                  U:w  a  U R5                  U5      n UR0                  U:w  a  UR5                  U5      nOU(       d  UR                  5       nU(       a  U n[        X4US9nO[7        XSS9nU nUR                  S5        [8        R:                  " UXR<                  UR>                  UR@                  URB                  XR<                  UR>                  UR@                  URB                  U5      u  pU(       a  [%        S5      eU(       d1  W
RD                  " S/S/[G        UR                  5      S-
  -  Q76 n
X-  nU$ ! , (       d  f       GN-= f)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   rO   TrN   z?CSC or CSR matrix format is required. Converting to CSC matrix.rP   rQ   z+A must be a square matrix but its shape is .r   r   Nr   z&A is singular: zero entry on diagonal.)r   rP   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 r5   )r6   r]   zA is singular.)$r   r   r   r   r]   r   r   r   r
   rA   r[   r@   r   r   setdiagdiagonalr7   anyr   r   r_   
asanyarrayr^   ra   r6   float32rb   r   r   gstrsro   rp   r>   rB   reshapelen)rC   r{   loweroverwrite_Aoverwrite_bunit_diagonaltransr   r   diaginvdiagr   LUr   r   s                   r&   r   r   X  s   p !%%'E{{qxx5(CC	QKKAHH-N$	4aLFFH 77DAv9!''!DF 	F #:;IIaL  zz|66$!)8: :D&C<K((A{7++..A 
aAvvV7yBD 	DGGAJJwwi.qwwiq:
 	
 ##B$4$4QWWbjj$I177SLww,HH\"ww,HH\"FFHqfL1aE:			!nnUqvvqyy!((qvvqyy!(( GA *++//"Bs177|a/?(@BKHq s   5"N33
Oc                    [        U 5      (       a  U R                  S;   d  [        S[        SS9  [	        U 5      n U R                  S:X  a:  U R
                  R                  5       S:*  U R
                  R                  5       S:  4$ U R                  S:X  a2  U R                  u  pX!:*  R                  5       X!:  R                  5       4$ U R                  S:X  a@  [        S	 U R                  5        5       5      [        S
 U R                  5        5       5      4$ U R                  S:X  aM  [        S [        U R                  5       5       5      n[        S [        U R                  5       5       5      nX44$ U R                  U R                  pe[        U5      S-
  nSu  p4US-  SS4 HW  nXeU   XXS-       nU=(       a    X:  R                  5       nU=(       a    X:*  R                  5       nU(       a  MN  U(       a  MW    g   [         R"                  " [         R$                  " U5      [         R&                  " U5      5      nUnU=(       a    X!:  R                  5       nU=(       a    X!:*  R                  5       nU R                  S:X  a  XC4$ X44$ )aX  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)
)rN   rO   coodiadoklilzCis_sptriangular needs sparse and not BSR format. Converting to CSR.rP   rQ   r   r   r   r   c              3   .   #    U  H  u  pX!:*  v   M     g 7fr   r   .0rcs      r&   	<genexpr>"is_sptriangular.<locals>.<genexpr>  s     /hda16h   c              3   .   #    U  H  u  pX!:  v   M     g 7fr   r   r   s      r&   r   r     s     4QQVr   r   c              3   B   #    U  H  u  pU  H	  o3U:*  v   M     M     g 7fr   r   r   rowcolscols       r&   r   r          R0A93Tc3JTJ0A   c              3   B   #    U  H  u  pU  H	  o3U:  v   M     M     g 7fr   r   r   s       r&   r   r     r   r   r   )TTr   )FFrO   )r   r]   r   r   r	   offsetsry   mincoordsallkeys	enumeraterowsrB   r>   r   r7   repeatarangediff)	rC   r   r   r   upperrB   r>   r   r   s	            r&   r   r     s   R QKKAHH(RRR$	4aL 	xx5yy}}!#QYY]]_%999	
U	XX
!!#dl%7%7%999	
U	/affh//4Q4Q1QQQ	
U	R	!&&0ARRR	!&&0ARR|hh		GFaALEQ2c{6'?3-3;++--3;++-uUU  99RYYq\2776?3DD*t|((*E*t|((*Exx5|<r%   c                 @   [        U 5      (       a  U R                  S;   d  [        S[        SS9  [	        U 5      n U R                  S:X  ae  [        SU R                  R                  5       R                  5       * 5      [        SU R                  R                  5       R                  5       5      4$ U R                  S;   a{  U R                  U R                  p![        U5      S-
  n[        R                  " [        R                  " U5      [        R                  " U5      5      U-
  nU R                  S	:X  a  U* nOU R                  S
:X  a   U R                   S   U R                   S   -
  nORU R                  S:X  aB  U R#                  5        VVs/ s H	  u  pVXe-
  PM     snnS/-   n[        U5      * [        U5      4$ [        [        R                  " W5      R                  5       * S5      [        [        R
                  " U5      R                  5       S5      4$ s  snnf )a  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)
)rN   rO   r   r   r   zCspbandwidth needs sparse format not LIL and BSR. Converting to CSR.rP   rQ   r   r   rM   r   rO   r   r   )r   r]   r   r   r	   ry   r   r   itemrB   r>   r   r7   r   r   r   r   r   )rC   rB   r>   r   gapr   r   s          r&   r   r   2  s   H QKKAHH(KKR$	4aL 	xx51qyy}}++--.Aqyy}}7K7K7M0NNNxx>!((AIIK!Oii		!bggfo6@88u$C	
U	hhqkAHHQK'	
U	#$668,8418,s2Cy#c(""s  ""A&BFF3K,<,<,>(BBB -s   H)NT)NNNNN)NNNNNNNN)TFFF)+warningsr   r   r   numpyr7   r   scipy.sparser   r   r	   r
   r   r   scipy.sparse._sputilsr   r   r   r   scipy.linalgr   rA   	threading r   rd   scikits.umfpackr+   ImportErrorlocalr(   __all__UserWarningr   r   rK   r   r   r   r   r   r   r   r   r%   r&   <module>r     s    7 7  H HN N $   % __
X	 	AMF D@F 04.2f7R JNGK_6DBJ IN%*GTM`7CA  Hs   B B#"B#