§
    fŠtj^Y ã                   óX  — d dl Z d dl mZ d dlmZ d dlZd dlmZmZ d dlm	Z	 ddl
mZmZmZmZ ddlmZmZmZ dd	lmZ dd
lmZmZ ddlmZ ddlmZmZmZmZ ddlmZ g d¢Zd=d„Z d„ Z!d„ Z"	 	 	 d>d„Z# e	dd¦  «        	 	 	 d>d„¦   «         Z$d„ Z%d„ Z&d„ Z'd„ Z(d„ Z)d„ Z*d„ Z+ e	dd¦  «        	 	 d?d„¦   «         Z,	 	 d@d „Z-	 	 dAd!„Z. e	d"d#d$d¦  «        d%„ ¦   «         Z/ e	dd¦  «        	 	 dBd&„¦   «         Z0dCd'„Z1 e	d(d)d¦  «        d*„ ¦   «         Zd+„ Z2	 	 dDd.„Z3dEddd/œd0„Z4dEd1„Z5 e	dd¦  «        	 	 dFd2„¦   «         Z6d3e6_7         e	d¦  «        ddddd4œd5„¦   «         Z8 e	d¦  «        	 	 dGd6„¦   «         Z9 e	d7¦  «        	 	 dHd8„¦   «         Z:	 dCd9„Z;dId:„Z< e	d)d(d;¦  «        d<„ ¦   «         Z=dS )Jé    N)Úwarn)Úproduct)Ú
atleast_1dÚ
atleast_2d)Ú_apply_over_batché   )Úget_lapack_funcsÚ_normalize_lapack_dtypeÚ_normalize_lapack_dtype1Ú_compute_lwork)ÚLinAlgErrorÚ_datacopiedÚLinAlgWarning)Ú_asarray_validated)Ú_decompÚ_decomp_svd)Úlevinson)Úfind_det_from_luÚ	bandwidthÚissymmetricÚishermitian)Ú_batched_linalg)ÚsolveÚsolve_triangularÚsolveh_bandedÚsolve_bandedÚsolve_toeplitzÚsolve_circulantÚinvÚdetÚlstsqÚpinvÚpinvhÚmatrix_balanceÚmatmul_toeplitzc                 óÖ   — |dk     rt          d| › d�¦  «        ‚d|k     s|dk    rt          d¦  «        ‚|€dS  |d¦  «        }||k    st          d|d›d	�t          d
¬¦  «         dS dS )zB Check arguments during the different steps of the solution phase r   z$LAPACK reported an illegal value in z-th argument.zMatrix is singular.NÚEzIll-conditioned matrix (rcond=z.6gz): result may not be accurate.é   ©Ú
stacklevel)Ú
ValueErrorr   r   r   )ÚnÚinfoÚlamchÚrcondr'   s        úQ/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/scipy/linalg/_basic.pyÚ_solve_checkr1      s­   € àˆa‚x€xÝÐTÀÀÐTÐTÐTÑUÔUÐUØ	
ˆTŠˆ�U˜a’Z�ZÝÐ/Ñ0Ô0Ð0à€}ØˆØˆˆc‰
Œ
€AØ�QŠJˆJÝð +¨eÐ<ð +ð +ð +å qð	*ñ 	*ô 	*ð 	*ð 	*ð 	*ð ˆJó    c                 óR  — | j         d         }t          | ¦  «        \  }}||cxk    rdk    rn nd}nq|dk    rd}nh|dk    rd}n_|dk    r|dk    r	|dk    rd}nJt          j        | j        t          j        ¦  «        rt          | ¦  «        rd}nt          | ¦  «        rd	}nd
}|||fS )Nr   Údiagonalúlower triangularúupper triangularr   r(   ÚtridiagonalÚ	hermitianÚ	symmetricÚgeneral)Úshaper   ÚnpÚ
issubdtypeÚdtypeÚcomplexfloatingr   r   )Úar,   Ún_belowÚn_aboveÚkinds        r0   Ú_find_matrix_structurerD   /   sÚ   € Ø	Œ�Œ
€AÝ  ‘|”|Ñ€GˆWà�'ÐÐÒÐ˜QÒÐÐÐÐØˆˆØ	�AŠˆØ!ˆˆØ	�AŠˆØ!ˆˆØ	�AŠˆ˜' Qš,˜,¨1¨qª5¨5ØˆˆÝ	Œ�q”w¥Ô 2Ñ	3Ô	3ð ½ÀA¹¼ð ØˆˆÝ	�Q‰Œð Øˆˆàˆà�˜'Ð!Ð!r2   c                 ó
  — g g g }}}t          | ¦  «        D ]x\  }}|d         r|                     |¦  «         |d         dk     r!|                     d|› d|d         › �¦  «         |d         r!|                     d|› d|d         › �¦  «         Œy|rt          d	|› d
�¦  «        ‚|r&t          dd                     |¦  «        › d�¦  «        ‚|r5t          j        dd                     |¦  «        › d�t          d¬¦  «         dS dS )zVFormat/emit errors/warnings from a lowlevel batched routine.

    See inv, solve.
    Úis_singularÚlapack_infor   zslice z emits lapack info=Úis_ill_conditionedz has rcond = r/   z%A singular matrix detected: slice(s) z are singular.zInternal LAPACK errors: ú,ú.z$An ill-conditioned matrix detected: r(   r)   N)Ú	enumerateÚappendr   r+   ÚjoinÚwarningsr   r   )Úerr_lstÚsingularÚ
lapack_errÚill_condÚiÚdcts         r0   Ú_format_emit_errors_warningsrU   E   sl  € ð
 &(¨¨R˜(ˆj€HÝ˜GÑ$Ô$ð Eð E‰ˆˆ3Øˆ}Ôð 	Ø�OŠO˜AÑÔÐØˆ}Ô Ò!Ð!Ø×ÒÐQ qÐQÐQ¸SÀÔ=OÐQÐQÑRÔRÐRØÐ#Ô$ð 	EØ�OŠOÐC QÐCÐC°S¸´\ÐCÐCÑDÔDÐDøàð 
ÝØL°HÐLÐLÐLñ
ô 
ð 	
ð ð MÝÐK°C·H²H¸ZÑ4HÔ4HÐKÐKÐKÑLÔLÐLàð 
Ý„}ØH°3·8²8¸HÑ3EÔ3EÐHÐHÐHÝØð
ñ 
ô 
ð 
ð 
ð 
ð
ð 
r2   FTc                 óØ  — |dv rt          | |||||||¬¦  «        S dddddddd	d	d
d
dddœ                     |d¦  «        }|dk    rt          |› d�¦  «        ‚t          j        t          | |¬¦  «        ¦  «        }	t          j        t          ||¬¦  «        ¦  «        }
t          |	|
¦  «        \  }	}
t          |	|¦  «        \  }	}|	j	        dk     rt          d|	j	        ›�¦  «        ‚|	j
        d         |	j
        d         k    rt          d|	j
        ›�¦  «        ‚t          j        |	j        t          j        ¦  «        r|rt          d¦  «        ‚|	j        d         s&|	j        j        dk    sd}|	                     ¦   «         }	|
j        d         s&|
j        j        dk    sd}|
                     ¦   «         }
|
j	        dk    }|r|
dd…df         }
|	j        dk    }|
j
        d         |	j
        d         k    r!|st          d|	j
        ›d|
j
        ›�¦  «        ‚t          j        |	j
        dd…         |
j
        dd…         ¦  «        }t          j        |	||	j
        dd…         z   ¦  «        }	t          j        |
||
j
        dd…         z   ¦  «        }
|	j        dk    s|
j        dk    r t          j        |
¦  «        }|r|d         }|S |r8|	                     ¦   «         dk    rt/          d¦  «        ‚|
|	z  }|r|d         n|S |o|	j	        dk    o|	j        d         }|o|
j	        dk    o|
j        d         }t1          j        |	|
|||||¦  «        \  }}|rt5          |¦  «         |r|d         }|S )a&  
    Solve the equation ``a @ x = b`` for  ``x``,
    where `a` is a square matrix.

    If the data matrix is known to be a particular type then supplying the
    corresponding string to ``assume_a`` key chooses the dedicated solver.
    The available options are

    =============================  ================================
     diagonal                       'diagonal'
     tridiagonal                    'tridiagonal'
     banded                         'banded'
     upper triangular               'upper triangular'
     lower triangular               'lower triangular'
     symmetric                      'symmetric' (or 'sym')
     hermitian                      'hermitian' (or 'her')
     symmetric positive definite    'positive definite' (or 'pos')
     general                        'general' (or 'gen')
    =============================  ================================

    Array argument(s) of this function may have additional
    "batch" dimensions prepended to the core shape. In this case, the array is treated
    as a batch of lower-dimensional slices; see :ref:`linalg_batch` for details.

    Parameters
    ----------
    a : array_like, shape (..., N, N)
        Square left-hand side matrix or a batch of matrices.
    b : (..., N, NRHS) array_like
        Input data for the right hand side or a batch of right-hand sides.
    lower : bool, default: False
        Ignored unless ``assume_a`` is one of ``'sym'``, ``'her'``, or ``'pos'``.
        If True, the calculation uses only the data in the lower triangle of `a`;
        entries above the diagonal are ignored. If False (default), the
        calculation uses only the data in the upper triangle of `a`; entries
        below the diagonal are ignored.
    overwrite_a : bool, default: False
        Allow overwriting data in `a` (may enhance performance).
    overwrite_b : bool, default: False
        Allow overwriting data in `b` (may enhance performance).
    check_finite : bool, default: True
        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.
    assume_a : str, optional
        Valid entries are described above.
        If omitted or ``None``, checks are performed to identify structure so the
        appropriate solver can be called.
    transposed : bool, default: False
        If True, solve ``a.T @ x == b``. Raises `NotImplementedError`
        for complex `a`.

    Returns
    -------
    x : ndarray, shape (N, NRHS) or (..., N)
        The solution array.

    Raises
    ------
    ValueError
        If size mismatches detected or input a is not square.
    LinAlgError
        If the computation fails because of matrix singularity.
    LinAlgWarning
        If an ill-conditioned input a is detected.
    NotImplementedError
        If transposed is True and input a is a complex matrix.

    Notes
    -----
    If the input b matrix is a 1-D array with N elements, when supplied
    together with an NxN input a, it is assumed as a valid column vector
    despite the apparent size mismatch. This is compatible with the
    numpy.dot() behavior and the returned result is still 1-D array.

    The general, symmetric, Hermitian and positive definite solutions are
    obtained via calling ?GETRF/?GETRS, ?SYSV, ?HESV, and ?POTRF/?POTRS routines of
    LAPACK respectively.

    The datatype of the arrays define which solver is called regardless
    of the values. In other words, even when the complex array entries have
    precisely zero imaginary parts, the complex solver will be called based
    on the data type of the array.

    Examples
    --------
    Given `a` and `b`, solve for `x`:

    >>> import numpy as np
    >>> a = np.array([[3, 2, 0], [1, -1, 0], [0, 5, 1]])
    >>> b = np.array([2, 4, -1])
    >>> from scipy.linalg import solve
    >>> x = solve(a, b)
    >>> x
    array([ 2., -2.,  9.])
    >>> a @ x == b
    array([ True,  True,  True], dtype=bool)

    Batches of matrices are supported, with and without structure detection:

    >>> a = np.arange(12).reshape(3, 2, 2)   # a batch of 3 2x2 matrices
    >>> A = a.transpose(0, 2, 1) @ a    # A is a batch of 3 positive definite matrices
    >>> b = np.ones(2)
    >>> solve(A, b)      # this automatically detects that A is pos.def.
    array([[ 1. , -0.5],
           [ 3. , -2.5],
           [ 5. , -4.5]])
    >>> solve(A, b, assume_a='pos')   # bypass structucture detection
    array([[ 1. , -0.5],
           [ 3. , -2.5],
           [ 5. , -4.5]])
    )Úbanded)ÚlowerÚoverwrite_aÚoverwrite_bÚcheck_finiteÚassume_aÚ
transposedéÿÿÿÿr   é   é   é   é   ée   éÉ   éÓ   )Nr:   Úgenr4   r7   r6   r5   Úposúpositive definiteÚsymr9   Úherr8   Úunknownú% is not a recognized matrix structure©r[   é   ú&Expected at least ndim=2, got a1.ndim=éþÿÿÿú%Expected square matrix, got a1.shape=úWscipy.linalg.solve can currently not solve a^T x = b or a^H x = b for complex matrices.ÚALIGNEDú=Tr   Nzincompatible shapes: a1.shape=z and b1.shape=).r   zA singular matrix detected.ÚF_CONTIGUOUS)Úsolve0Úgetr+   r<   r   r   r   Ú_ensure_dtype_cdszr
   Úndimr;   r=   r>   r?   ÚNotImplementedErrorÚflagsÚ	byteorderÚcopyÚsizeÚbroadcast_shapesÚbroadcast_toÚ
empty_likeÚitemr   r   Ú_solverU   )r@   ÚbrX   rY   rZ   r[   r\   r]   Ú	structureÚa1Úb1Úb_is_1DÚa_is_scalarÚbatch_shapeÚxÚoutrO   s                    r0   r   r   c   sØ  € ðf �:ÐÐåØˆq˜¨;ÀKØ%°ÀZð
ñ 
ô 
ð 	
ð Ø˜QØØØØØ¨#Ø #Ø #ð
ð 
÷ 
‚cˆ(�IÑÔð ð �IÒÐÝ˜HÐKÐKÐKÑLÔLÐLå	ŒÕ)¨!¸,ÐGÑGÔGÑ	HÔ	H€BÝ	ŒÕ)¨!¸,ÐGÑGÔGÑ	HÔ	H€BÝ  BÑ'Ô'�F€BˆÝ-¨b°+Ñ>Ô>�O€Bˆà	„w�‚{€{ÝÐD¸"¼'ÐDÐDÑEÔEÐEØ	„x�„|�r”x ”|Ò#Ð#ÝÐC¸¼ÐCÐCÑDÔDÐDõ 
„}�R”X�rÔ1Ñ2Ô2ð ;°zð ;Ý!ð #:ñ ;ô ;ð 	;ð ŒH�YÔð  2¤8Ô#5¸Ò#<Ð#<ØˆØ�WŠW‰YŒYˆàŒH�YÔð  2¤8Ô#5¸Ò#<Ð#<ØˆØ�WŠW‰YŒYˆð Œg˜Šl€GØð Ø����4�Œ[ˆà”'˜Q’,€Kà	„x�„|�r”x ”|Ò#Ð#¨KÐ#ÝÐL°´ÐLÐLÀÄÐLÐLÑMÔMÐMõ Ô% b¤h¨s°¨s¤m°R´X¸c¸r¸c´]ÑCÔC€KÝ	Œ˜˜[¨2¬8°B°C°C¬=Ñ8Ñ	9Ô	9€BÝ	Œ˜˜[¨2¬8°B°C°C¬=Ñ8Ñ	9Ô	9€Bð 
„w�!‚|€|�r”w !’|�|ÝŒM˜"ÑÔˆØð 	Ø�&”	ˆAØˆàð /Ø�7Š7‰9Œ9˜Š>ˆ>ÝÐ;Ñ<Ô<Ð<à�2‰gˆØ%Ð.ˆs�6Œ{ˆ{¨3Ð.ð ÐO 2¤7¨a¢<ÐO°b´h¸~Ô6N€KØÐO 2¤7¨a¢<ÐO°b´h¸~Ô6N€Kõ !Ô'Ø
ˆB�	˜5 *¨k¸;ñô �J€A€wð ð .Ý$ WÑ-Ô-Ð-àð ØˆfŒIˆØ€Hr2   )r@   rn   )r„   ú1|2c           	      óH  — d}t          t          | d¬¦  «        ¦  «        }	t          t          |d¬¦  «        ¦  «        }
t          |	|
¦  «        \  }	}
|	j        d         }|pt          |	| ¦  «        }|pt          |
|¦  «        }|	j        d         |	j        d         k    rt          d¦  «        ‚||
j        d         k    r |dk    r|
j        dk    st          d¦  «        ‚|
j        dk    r]t          t          j
        d|	j        ¬¦  «        t          j        d|
j        ¬¦  «        ¦  «        j        }t          j        |
|¬¦  «        S |
j        dk    r!|dk    r|
d	d	d	…f         }
n|
d	d	…d	f         }
d
}|dvrt          |› d�¦  «        ‚|dv rt          j        |	¦  «        sd}d\  }}|€t!          |	¦  «        \  }}}|	j        j        dv rt%          dd¬¦  «        }nt%          dd¬¦  «        }|r(d}d}t          j        |	¦  «        rt'          d¦  «        ‚nd}d}|dk    rt)          |	|¦  «        }n˜|dk    rt+          ||	|¦  «        }n€|dk    rR|€t-          |	¦  «        n||f\  }}|r
|	j        ||fn|	||f\  }}}t1          |||¦  «        }t3          |||||¦  «        }n(|dv rt5          |||	|¦  «        }nt7          ||	|¦  «        }dt          j        }}|dv rmt%          d|	|
f¦  «        \  }}} ||	|¬¦  «        \  }}}t;          ||¦  «          ||||
||¬¦  «        \  }}t;          ||¦  «          ||||¬¦  «        \  }}�n0|dv rat%          d |	|
f¦  «        \  }}}t=          |||¦  «        }  ||	|
| |||¬!¦  «        \  }}}}t;          ||¦  «          |||||¬"¦  «        \  }}�nË|d#v rat%          d$|	|
f¦  «        \  }!}"}#t=          |#||¦  «        }  |"|	|
| |||¬!¦  «        \  }}}}t;          ||¦  «          |!||||¬"¦  «        \  }}�nf|dk    rlt          j        |	¦  «        }$|
j        |$z  j        }t          j         |$¦  «        }%|% !                    ¦   «         }&|&dk    r|&n|&|% "                    ¦   «         z  }�nô|dk    r¾|r|	j        n|	}	t          j        |	d%¦  «        t          j        |	d¦  «        t          j        |	d¦  «        })}(}'t%          d&|	|
f¦  «        \  }*}+}, |*|'|(|)¦  «        \  }'}(})}-}.}t;          ||¦  «          |+|'|(|)|-|.|
|¬'¦  «        \  }}t;          ||¦  «          |,|'|(|)|-|.|¦  «        \  }}�n0|dk    rŠt%          d(|	|
f¦  «        \  }/}0t          j#        d|z  |z   dz   |j        d         f|/j        ¬¦  «        }|||d	…d	d	…f<    |/||||
d
|¬)¦  «        \  }}1}}t;          ||¦  «          |0||||1|¦  «        \  }}n |dv rT|d*k    }tI          |	|
|||¬+¦  «        \  }}t;          ||¦  «         t%          d,|	|
f¦  «        }2 |2|	|rd-nd.¬/¦  «        \  }}nHt%          d0|	|
f¦  «        \  }3}4 |4|	|
|||¬1¦  «        \  }}}t;          ||¦  «          |3||¦  «        \  }}t;          ||||¦  «         |r| %                    ¦   «         }|S )2a¨  
    Solve the equation ``a @ x = b`` for  ``x``,
    where `a` is a square matrix.

    If the data matrix is known to be a particular type then supplying the
    corresponding string to ``assume_a`` key chooses the dedicated solver.
    The available options are

    =============================  ================================
     diagonal                       'diagonal'
     tridiagonal                    'tridiagonal'
     banded                         'banded'
     upper triangular               'upper triangular'
     lower triangular               'lower triangular'
     symmetric                      'symmetric' (or 'sym')
     hermitian                      'hermitian' (or 'her')
     symmetric positive definite    'positive definite' (or 'pos')
     general                        'general' (or 'gen')
    =============================  ================================

    Parameters
    ----------
    a : (N, N) array_like
        Square input data
    b : (N, NRHS) array_like
        Input data for the right hand side.
    lower : bool, default: False
        Ignored unless ``assume_a`` is one of ``'sym'``, ``'her'``, or ``'pos'``.
        If True, the calculation uses only the data in the lower triangle of `a`;
        entries above the diagonal are ignored. If False (default), the
        calculation uses only the data in the upper triangle of `a`; entries
        below the diagonal are ignored.
    overwrite_a : bool, default: False
        Allow overwriting data in `a` (may enhance performance).
    overwrite_b : bool, default: False
        Allow overwriting data in `b` (may enhance performance).
    check_finite : bool, default: True
        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.
    assume_a : str, optional
        Valid entries are described above.
        If omitted or ``None``, checks are performed to identify structure so the
        appropriate solver can be called.
    transposed : bool, default: False
        If True, solve ``a.T @ x == b``. Raises `NotImplementedError`
        for complex `a`.

    Returns
    -------
    x : (N, NRHS) ndarray
        The solution array.

    Raises
    ------
    ValueError
        If size mismatches detected or input a is not square.
    LinAlgError
        If the computation fails because of matrix singularity.
    LinAlgWarning
        If an ill-conditioned input a is detected.
    NotImplementedError
        If transposed is True and input a is a complex matrix.

    Notes
    -----
    If the input b matrix is a 1-D array with N elements, when supplied
    together with an NxN input a, it is assumed as a valid column vector
    despite the apparent size mismatch. This is compatible with the
    numpy.dot() behavior and the returned result is still 1-D array.

    The general, symmetric, Hermitian and positive definite solutions are
    obtained via calling ?GESV, ?SYSV, ?HESV, and ?POSV routines of
    LAPACK respectively.

    The datatype of the arrays define which solver is called regardless
    of the values. In other words, even when the complex array entries have
    precisely zero imaginary parts, the complex solver will be called based
    on the data type of the array.

    Examples
    --------
    Given `a` and `b`, solve for `x`:

    >>> import numpy as np
    >>> a = np.array([[3, 2, 0], [1, -1, 0], [0, 5, 1]])
    >>> b = np.array([2, 4, -1])
    >>> from scipy import linalg
    >>> x = linalg.solve(a, b)
    >>> x
    array([ 2., -2.,  9.])
    >>> np.dot(a, x) == b
    array([ True,  True,  True], dtype=bool)

    Frm   r   r   z$Input a needs to be a square matrix.z2Input b has to have same number of rows as input arn   ©r>   NT>   Nrf   rj   rg   ri   rW   r:   r4   r8   r9   r7   r5   r6   rh   rl   >   rj   r8   r9   ©NNÚfFr.   ÚfÚdÚIrr   Ú1r4   r7   rW   >   r5   r6   >   rf   r:   )ÚgeconÚgetrfÚgetrs)rY   )ÚtransrZ   )Únorm)ÚheconÚhesvÚ
hesv_lwork)ÚlworkrX   rY   rZ   )rX   >   ri   r9   )ÚsyconÚsysvÚ
sysv_lworkr^   )ÚgttrfÚgttrsÚgtcon)rZ   )ÚgbsvÚgbcon©Úoverwrite_abrZ   r5   )rX   rZ   r™   ÚtrconÚLÚU)Úuplo)ÚpoconÚposv)rX   rY   rZ   )&r   r   r   rx   r;   r   r+   r~   r   r<   Úeyer>   Úonesr�   ry   ÚiscomplexobjrD   Úcharr	   rz   Ú_matrix_norm_diagonalÚ_matrix_norm_tridiagonalr   ÚTÚ
_to_bandedÚ_matrix_norm_bandedÚ_matrix_norm_triangularÚ_matrix_norm_generalÚinfr1   r   ÚdiagÚabsÚminÚmaxÚzerosÚ_solve_triangularÚravel)5r@   r„   rX   rY   rZ   r[   r\   r]   rˆ   r†   r‡   r,   ÚdtrA   rB   r.   r™   rš   ÚanormÚa2Úabr-   r/   r–   r—   r˜   ÚluÚipvtr‹   r›   rœ   Úhesv_lwrž   rŸ   r    Úsysv_lwÚdiag_aÚ
abs_diag_aÚdiag_minÚdlr“   ÚduÚ_gttrfÚ_gttrsÚ_gtconÚdu2Úipivr¥   r¦   ÚpivÚ_trconr­   r®   s5                                                        r0   rv   rv   3  sy  € ðH €Gõ 
Õ& q°uÐ=Ñ=Ô=Ñ	>Ô	>€BÝ	Õ& q°uÐ=Ñ=Ô=Ñ	>Ô	>€BÝ  BÑ'Ô'�F€BˆØ
Œ�Œ€AàÐ3¥¨R°Ñ!3Ô!3€KØÐ3¥¨R°Ñ!3Ô!3€Kà	„x�„{�b”h˜q”kÒ!Ð!ÝÐ?Ñ@Ô@Ð@àˆBŒH�QŒKÒÐà�Q’�˜2œ7 aš<˜<Ýð 'ñ (ô (ð (ð 
„w�!‚|€|Ý•2”6˜! 2¤8Ð,Ñ,Ô,­b¬g°a¸r¼xÐ.HÑ.HÔ.HÑIÔIÔOˆÝŒ}˜R rÐ*Ñ*Ô*Ð*ð 
„w�!‚|€|Ø�Š6ˆ6Ø�D˜!˜!˜!�G”ˆBˆBà�A�A�A�t�G”ˆBØˆàð Tð Tð Tõ ˜HÐKÐKÐKÑLÔLÐLð Ð'Ð'Ð'µ´ÀÑ0CÔ0CÐ'Øˆà!Ñ€GˆWØÐÝ%;¸BÑ%?Ô%?Ñ"ˆ�'˜7ð
 
„x„}˜ÐÐÝ  °Ð4Ñ4Ô4ˆˆå  °Ð4Ñ4Ô4ˆð ð 	ØˆØˆÝŒ?˜2ÑÔð 	?Ý%ð '>ñ ?ô ?ð ?ð	?ð
 ˆØˆð
 �:ÒÐÝ% b¨,Ñ7Ô7ˆˆØ	�]Ò	"Ð	"Ý(¨¨r°<Ñ@Ô@ˆˆØ	�XÒ	Ð	Ø,3¨O�9 R™=œ=˜=À'È7ÐASÑˆ�Ø<Fð !< ¤ w°Ð 8Ð 8Ø&(¨'°7Ð%;ñ 	ˆˆG�Wå˜ ¨"Ñ-Ô-ˆÝ# G¨W°d¸BÀÑMÔMˆˆØ	Ð=Ð	=Ð	=Ý'¨°$¸¸LÑIÔIˆˆå$ T¨2¨|Ñ<Ô<ˆà•R”Vˆ%€Dð Ð%Ð%Ð%Ý.Ð/JØ02°B¨xñ9ô 9Ñˆˆu�eà˜˜r¨{Ð;Ñ;Ô;‰ˆˆD�$Ý�Q˜ÑÔÐØ�%˜˜D "Ø#°ð>ñ >ô >‰ˆˆ4å�Q˜ÑÔÐØ�e˜B ¨DÐ1Ñ1Ô1‰ˆˆt‰tà	Ð)Ð	)Ð	)Ý/ð 1?ØACÀRÀñ Jô  JÑˆˆt�Wå˜w¨¨5Ñ1Ô1ˆØ ˜D  R¨uØ',Ø-8Ø-8ð:ñ :ô :ÑˆˆD�!�Tõ 	�Q˜ÑÔÐØ�e˜B  e°5Ð9Ñ9Ô9‰ˆˆt‰tà	Ð)Ð	)Ð	)Ý/ð 1?ØACÀRÀñ Jô  JÑˆˆt�Wå˜w¨¨5Ñ1Ô1ˆØ ˜D  R¨uØ',Ø-8Ø-8ð:ñ :ô :ÑˆˆD�!�Tõ 	�Q˜ÑÔÐØ�e˜B  e°5Ð9Ñ9Ô9‰ˆˆt‰tà	�ZÒ	Ð	Ý”˜‘”ˆØŒT�F‰]ÔˆÝ”V˜F‘^”^ˆ
Ø—>’>Ñ#Ô#ˆØ$¨šM˜M��¨x¸*¿.º.Ñ:JÔ:JÑ/Jˆ‰à	�]Ò	"Ð	"ØÐ'ˆRŒTˆT RˆÝ”G˜B ‘O”O¥R¤W¨R°¡^¤^µR´W¸RÀ±^´^ˆrˆAˆÝ!1Ð2MÐPRÐTVÈxÑ!XÔ!XÑˆ�˜Ø%+ V¨B°°2Ñ%6Ô%6Ñ"ˆˆAˆr�3˜˜dÝ�Q˜ÑÔÐØ�&˜˜Q  C¨¨r¸{ÐKÑKÔK‰ˆˆ4Ý�Q˜ÑÔÐØ�f˜R  B¨¨T°5Ñ9Ô9‰ˆˆt‰tà	�XÒ	Ð	Ý&Ð'8¸2¸r¸(ÑCÔC‰ˆˆeåŒX�q˜‘y 7Ñ*¨QÑ.°´¸´Ð<ÀDÄJÐOÑOÔOˆØˆˆ7ˆ8ˆ8�Q�Q�Qˆ;‰Ø˜4 ¨°"°bØ-1¸{ðLñ Lô LÑˆˆC��Då�Q˜ÑÔÐØ�e˜G W¨b°#°uÑ=Ô=‰ˆˆtˆtà	Ð=Ð	=Ð	=ØÐ.Ò.ˆÝ# B¨°%À[Ø*4ð6ñ 6ô 6‰ˆˆ4å�Q˜ÑÔÐÝ! 7¨b°"¨XÑ6Ô6ˆØ�f˜R¨UÐ&; c c¸Ð<Ñ<Ô<‰ˆˆtˆtõ 'Ð'8Ø(*¨B xñ1ô 1‰ˆˆtà�d˜2˜r¨Ø'2Ø'2ð4ñ 4ô 4‰ˆˆAˆtõ 	�Q˜ÑÔÐØ�e˜B Ñ&Ô&‰ˆˆtå��D˜% Ñ'Ô'Ð'àð Ø�GŠG‰IŒIˆà€Hr2   c                 ó¦   — t          j        | ¦  «        }|rt          j        |¦  «        n|}t          j        |¦  «                             ¦   «         S ©N)r<   r»   Úasarray_chkfiniter¼   r¾   )r@   r[   r“   s      r0   r³   r³   G  sA   € õ 	Œ�‰
Œ
€AØ#/Ð6�Ô˜QÑÔÐ°Q€AÝŒ6�!‰9Œ9�=Š=‰?Œ?Ðr2   c           
      óö  — | dk    r|j         }t          j        d¬¦  «        5  t          j        t          j        |¦  «        ¦  «        }|dd …xx         t          j        t          j        |d¦  «        ¦  «        z  cc<   |d d…xx         t          j        t          j        |d¦  «        ¦  «        z  cc<   d d d ¦  «         n# 1 swxY w Y   |rt          j        |¦  «        n|}|                     ¦   «         S )Nr”   Úignore)Úinvalidr   r^   )rµ   r<   Úerrstater¼   r»   rØ   r¾   )rš   r@   r[   r“   s       r0   r´   r´   O  s  € ð ˆs‚{€{ØŒCˆå	Œ˜XÐ	&Ñ	&Ô	&ð )ð )ÝŒF•2”7˜1‘:”:ÑÔˆØ	ˆ!ˆ"ˆ"ˆˆŒ•”�œ  1™œÑ&Ô&Ñ&ˆˆ‰Ø	ˆ#ˆ2ˆ#ˆˆŒ•"”&�œ  B™œÑ(Ô(Ñ(ˆˆ‰ð)ð )ð )ñ )ô )ð )ð )ð )ð )ð )ð )øøøð )ð )ð )ð )ð $0Ð6�Ô˜QÑÔÐ°Q€AØ�5Š5‰7Œ7€Ns   £BCÃCÃCc                 ó~   — |rt          j        |¦  «        n|}t          d|f¦  «        } |||| dk    rdnd¦  «        S )NÚlantrr5   rª   r«   ©r<   rØ   r	   )r…   rš   r@   r[   rÞ   s        r0   r¸   r¸   ]  sP   € Ø#/Ð6�Ô˜QÑÔÐ°Q€AÝ˜W q dÑ+Ô+€EØˆ5��q Ð.@Ò!@Ð!@˜#˜#ÀcÑKÔKÐKr2   c                 óp   — |rt          j        |¦  «        n|}t          d|f¦  «        } ||| ||¦  «        S )NÚlangbrß   )ÚklÚkurš   rÅ   r[   rá   s         r0   r·   r·   c  sC   € Ø%1Ð	9�Ô	˜bÑ	!Ô	!Ð	!°r€BÝ˜W r eÑ,Ô,€EØˆ5��r˜2˜rÑ"Ô"Ð"r2   c                 ól   — |rt          j        |¦  «        n|}t          d|f¦  «        } || |¦  «        S )NÚlangerß   )rš   r@   r[   rå   s       r0   r¹   r¹   i  s=   € Ø#/Ð6�Ô˜QÑÔÐ°Q€AÝ˜W q dÑ+Ô+€EØˆ5��q‰>Œ>Ðr2   c                 óp  — |j         d         }|| z   dz   }t          j        ||f|j        ¬¦  «        }t          j        |¦  «        ||<   t          d|dz   ¦  «        D ]!}t          j        ||¦  «        |||z
  |d …f<   Œ"t          d| dz   ¦  «        D ]#}t          j        || ¦  «        |||z   d | …f<   Œ$|S )Nr   r   r�   )r;   r<   r¿   r>   r»   Úrange)rA   rB   r@   r,   ÚrowsrÅ   rS   s          r0   r¶   r¶   o  sÑ   € Ø	Œ�Œ
€AØ�WÑ˜qÑ €DÝ	Œ�4˜�) 1¤7Ð	+Ñ	+Ô	+€BÝ”'˜!‘*”*€B€w�KÝ�1�g ‘kÑ"Ô"ð ,ð ,ˆÝ œg a¨™mœmˆˆ7�Q‰;˜˜˜ˆ?ÑÐÝ�1�g ‘kÑ"Ô"ð .ð .ˆÝ!œw q¨1¨"™~œ~ˆˆ7�Q‰;˜˜!˜˜ÐÑÐØ€Ir2   c                  ó®  ‡— t          j        | Ž Št          j        ‰t           j        ¦  «        sd„ | D ¦   «         S t          j        ‰t           j        ¦  «        }t          j        ‰¦  «        j        dk    r|rt           j        nt           j        Šn7t          j        ‰¦  «        j        dk    r|rt           j	        nt           j
        Šˆfd„| D ¦   «         S )Nc              3   óT   K  — | ]#}|                      t          j        ¦  «        V — Œ$d S r×   )Úastyper<   Úfloat64)Ú.0Úarrays     r0   ú	<genexpr>z%_ensure_dtype_cdsz.<locals>.<genexpr>�  s0   è è € Ð=Ð=¨U�—’�RœZÑ(Ô(Ð=Ð=Ð=Ð=Ð=Ð=r2   é    é@   c              3   óF   •K  — | ]}|                      ‰d ¬¦  «        V — ŒdS )F©r}   N)rë   )rí   rî   r>   s     €r0   rï   z%_ensure_dtype_cdsz.<locals>.<genexpr>‡  s3   øè è € Ð@Ð@°ˆE�LŠL˜ UˆLÑ+Ô+Ð@Ð@Ð@Ð@Ð@Ð@r2   )r<   Úresult_typer=   Úinexactr?   ÚfinfoÚbitsÚ	complex64Úfloat32Ú
complex128rì   )ÚarraysÚcomplexr>   s     @r0   rx   rx   {  s»   ø€ õ ŒN˜FÐ#€EÝŒ=˜¥¤
Ñ+Ô+ð >Ø=Ð=°fÐ=Ñ=Ô=Ð=ÝŒm˜E¥2Ô#5Ñ6Ô6€GÝ	„x��„Ô˜rÒ!Ð!Ø 'Ð7•”�­R¬ZˆˆÝ	Œ�%‰ŒÔ	 Ò	#Ð	#Ø!(Ð8•”�­b¬jˆØ@Ð@Ð@Ð@¸Ð@Ñ@Ô@Ð@r2   c                 ój  — t          | |¬¦  «        }t          ||¬¦  «        }t          |j        ¦  «        dk    s|j        d         |j        d         k    rt          d¦  «        ‚|j        d         |j        d         k    r t          d|j        › d|j        › d�¦  «        ‚|j        dk    r]t          t          j        d|j        ¬	¦  «        t          j	        d|j        ¬	¦  «        ¦  «        j        }	t          j
        ||	¬	¦  «        S |pt          ||¦  «        }t          ||||||¦  «        \  }
}|
S )
a×  
    Solve the equation ``a @ x = b`` for ``x``, where `a` is a triangular matrix.

    Parameters
    ----------
    a : (M, M) array_like
        A triangular matrix
    b : (M,) or (M, N) array_like
        Right-hand side matrix in ``a x = b``
    lower : bool, optional
        Use only data contained in the lower triangle of `a`.
        Default is to use upper triangle.
    trans : {0, 1, 2, 'N', 'T', 'C'}, optional
        Type of system to solve:

        ========  =========
        trans     system
        ========  =========
        0 or 'N'  a x  = b
        1 or 'T'  a^T x = b
        2 or 'C'  a^H x = b
        ========  =========
    unit_diagonal : bool, optional
        If True, diagonal elements of `a` are assumed to be 1 and
        will not be referenced.
    overwrite_b : bool, optional
        Allow overwriting data in `b` (may enhance 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 : (M,) or (M, N) ndarray
        Solution to the system ``a x = b``.  Shape of return matches `b`.

    Raises
    ------
    LinAlgError
        If `a` is singular

    Notes
    -----
    .. versionadded:: 0.9.0

    Examples
    --------
    Solve the lower triangular system a x = b, where::

             [3  0  0  0]       [4]
        a =  [2  1  0  0]   b = [2]
             [1  0  1  0]       [4]
             [1  1  1  1]       [2]

    >>> import numpy as np
    >>> from scipy.linalg import solve_triangular
    >>> a = np.array([[3, 0, 0, 0], [2, 1, 0, 0], [1, 0, 1, 0], [1, 1, 1, 1]])
    >>> b = np.array([4, 2, 4, 2])
    >>> x = solve_triangular(a, b, lower=True)
    >>> x
    array([ 1.33333333, -0.66666667,  2.66666667, -1.33333333])
    >>> a.dot(x)  # Check the result
    array([ 4.,  2.,  4.,  2.])

    rm   rn   r   r   zexpected square matrixzshapes of a ú and b ú are incompatibler�   )r   Úlenr;   r+   r~   r   r<   r¯   r>   r°   r�   r   rÀ   )r@   r„   r™   rX   Úunit_diagonalrZ   r[   r†   r‡   Údt_nonemptyr‹   Ú_s               r0   r   r   Š  s2  € õL 
˜A¨LÐ	9Ñ	9Ô	9€BÝ	˜A¨LÐ	9Ñ	9Ô	9€Bå
ˆ2Œ8�}„}˜ÒÐ˜RœX aœ[¨B¬H°Q¬KÒ7Ð7ÝÐ1Ñ2Ô2Ð2à	„x�„{�b”h˜q”kÒ!Ð!ÝÐT¨¬ÐTÐT¸¼ÐTÐTÐTÑUÔUÐUð 
„w�!‚|€|Ý&ÝŒF�1˜BœHÐ%Ñ%Ô%¥r¤w¨q¸¼Ð'AÑ'AÔ'Añ
ô 
ä
ð 	õ Œ}˜R {Ð3Ñ3Ô3Ð3àÐ3¥¨R°Ñ!3Ô!3€Kå˜R  U¨E°=À+ÑNÔN�D€A€qØ€Hr2   c                 óT  — ddddœ                      ||¦  «        }t          d| |f¦  «        \  }| j        j        s|dk    r || |||||¬¦  «        \  }}n || j        ||| | |¬¦  «        \  }}|dk    r||fS |dk    rt          d|dz
  › �¦  «        ‚t          d| › d	�¦  «        ‚)
Nr   r   rn   )ÚNrµ   ÚC)Útrtrs)rZ   rX   r™   Úunitdiagz/singular matrix: resolution failed at diagonal úillegal value in z-th argument of internal trtrs)rw   r	   r{   Úf_contiguousrµ   r   r+   )	r†   r‡   r™   rX   r  rZ   r  r‹   r-   s	            r0   rÀ   rÀ   ç  sþ   € ð ˜! !Ð$Ð$×(Ò(¨°Ñ6Ô6€EÝ˜j¨2¨r¨(Ñ3Ô3�F€EØ	„xÔð A ¨¢
 
Ø�%˜˜B¨K¸uØ#¨mð=ñ =ô =‰ˆˆ4ˆ4ð �%˜œ˜b¨kÀUÀØ"'˜i°-ðAñ Aô A‰ˆˆ4ð ˆq‚y€yØ�$ˆwˆØˆa‚x€xÝÐTÈDÐQRÉFÐTÐTÑUÔUÐUÝ
ÐN¨$¨ÐNÐNÐNÑ
OÔ
OÐOr2   c           	      ó8   — | \  }}t          |||||||¬¦  «        S )aØ	  
    Solve the equation ``a @ x = b`` for ``x``, where ``a`` is the banded matrix
    defined by `ab`.

    The matrix a is stored in `ab` using the matrix diagonal ordered form::

        ab[u + i - j, j] == a[i,j]

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

        *    a01  a12  a23  a34  a45
        a00  a11  a22  a33  a44  a55
        a10  a21  a32  a43  a54   *
        a20  a31  a42  a53   *    *

    The documentation is written assuming array arguments are of specified
    "core" shapes. However, array argument(s) of this function may have additional
    "batch" dimensions prepended to the core shape. In this case, the array is treated
    as a batch of lower-dimensional slices; see :ref:`linalg_batch` for details.

    Parameters
    ----------
    (l, u) : (integer, integer)
        Number of non-zero lower and upper diagonals
    ab : (`l` + `u` + 1, M) array_like
        Banded matrix
    b : (M,) or (M, K) array_like
        Right-hand side
    overwrite_ab : bool, optional
        Discard data in `ab` (may enhance performance)
    overwrite_b : bool, optional
        Discard data in `b` (may enhance 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 : (M,) or (M, K) ndarray
        The solution to the system a x = b. Returned shape depends on the
        shape of `b`.

    Examples
    --------
    Solve the banded system a x = b, where::

            [5  2 -1  0  0]       [0]
            [1  4  2 -1  0]       [1]
        a = [0  1  3  2 -1]   b = [2]
            [0  0  1  2  2]       [2]
            [0  0  0  1  1]       [3]

    There is one nonzero diagonal below the main diagonal (l = 1), and
    two above (u = 2). The diagonal banded form of the matrix is::

             [*  * -1 -1 -1]
        ab = [*  2  2  2  2]
             [5  4  3  2  1]
             [1  1  1  1  *]

    >>> import numpy as np
    >>> from scipy.linalg import solve_banded
    >>> ab = np.array([[0,  0, -1, -1, -1],
    ...                [0,  2,  2,  2,  2],
    ...                [5,  4,  3,  2,  1],
    ...                [1,  1,  1,  1,  0]])
    >>> b = np.array([0, 1, 2, 2, 3])
    >>> x = solve_banded((1, 2), ab, b)
    >>> x
    array([-2.37288136,  3.93220339, -4.        ,  4.3559322 , -1.3559322 ])

    )r¨   rZ   r[   )Ú_solve_banded)Úl_and_urÅ   r„   r¨   rZ   r[   ÚnlowerÚnuppers           r0   r   r   û  s9   € ðV Ñ€VˆVÝ˜ ¨¨Q¸\Ø%0¸|ðMñ Mô Mð Mr2   )r  r   )r  r   )rÅ   rn   c           
      ó’  — t          ||d¬¦  «        }t          ||d¬¦  «        }|j        d         |j        d         k    rt          d¦  «        ‚| |z   dz   |j        d         k    r't          d| |z   dz   › d|j        d         › d	�¦  «        ‚|j        dk    r]t	          t          j        d|j        ¬
¦  «        t          j        d|j        ¬
¦  «        ¦  «        j        }	t          j	        ||	¬
¦  «        S |pt          ||¦  «        }|j        d         dk    r&t          j        || ¬¦  «        }
|
||df         z  }
|
S | |cxk    rdk    rfn nc|pt          ||¦  «        }t          d||f¦  «        \  }|ddd …f         }|dd d …f         }|dd d…f         } |||||||||¦  «        \  }}}}}nft          d||f¦  «        \  }t          j        d| z  |z   dz   |j        d         f|j        ¬
¦  «        }||| d …d d …f<    || |||d|¬¦  «        \  }}}}|dk    r|S |dk    rt          d¦  «        ‚t          d| › d�¦  «        ‚)NT)r[   Ú
as_inexactr^   r   ú&shapes of ab and b are not compatible.r   zCinvalid values for the number of lower and upper diagonals: l+u+1 (z) does not equal ab.shape[0] (ú)r�   ró   )Úgtsvrn   )r¥   r§   zsingular matrixr	  z"-th argument of internal gbsv/gtsv)r   r;   r+   r~   r   r<   r¯   r>   r°   r�   r   rî   r	   r¿   r   )r  r  rÅ   r„   r¨   rZ   r[   r†   r‡   rÂ   Úb2r  rÎ   r“   rÍ   rÒ   r‹   r-   r¥   rÄ   rÆ   rÔ   s                         r0   r  r  K  s×  € å	˜B¨\ÀdÐ	KÑ	KÔ	K€BÝ	˜A¨LÀTÐ	JÑ	JÔ	J€Bð 
„x�„|�r”x ”{Ò"Ð"ÝÐAÑBÔBÐBà��˜Ñ˜bœh qœkÒ)Ð)ÝðRØ˜‘ !Ñ#ðRð RØCEÄ8ÈAÄ;ðRð Rð Rñ
ô 
ð 	
ð 
„w�!‚|€|Ý•2”6˜! 2¤8Ð,Ñ,Ô,­b¬g°a¸r¼xÐ.HÑ.HÔ.HÑIÔIÔOˆÝŒ}˜R rÐ*Ñ*Ô*Ð*àÐ3¥¨R°Ñ!3Ô!3€KØ	„x�„|�qÒÐÝŒX�b K Ð1Ñ1Ô1ˆð 	ˆb�˜�ŒmÑˆØˆ	Ø�ÐÐÒÐ˜1ÒÐÐÐÐØ#Ð:¥{°2°rÑ':Ô':ˆÝ  ¨R°¨HÑ5Ô5‰ˆØ��1�2�2�ŒYˆØˆq�!�!�!ˆtŒHˆØ��3�B�3�ŒZˆØ"˜d 2 q¨"¨b°,ÀØ#/°ñ>ô >ÑˆˆQ��A�t�tõ ! ¨R°¨HÑ5Ô5‰ˆÝŒX�q˜‘x &Ñ(¨1Ñ,¨b¬h°q¬kÐ:À$Ä*ÐMÑMÔMˆØˆˆ6ˆ7ˆ7�A�A�Aˆ:‰Ø˜4 ¨°°BÀTØ,7ð9ñ 9ô 9ÑˆˆC��Dàˆq‚y€yØˆØˆa‚x€xÝÐ+Ñ,Ô,Ð,Ý
ÐR¨$¨ÐRÐRÐRÑ
SÔ
SÐSr2   c                 ó€  — t          | |¬¦  «        }t          ||¬¦  «        }|j        d         |j        d         k    rt          d¦  «        ‚|j        dk    r]t	          t          j        d|j        ¬¦  «        t          j        d|j        ¬¦  «        ¦  «        j        }t          j	        ||¬¦  «        S |pt          ||¦  «        }|pt          || ¦  «        }|j        d         dk    ryt          d||f¦  «        \  }	|r|dd	d	…f         j        }
|dd	d…f         }n/|dd	d	…f         j        }
|ddd	…f                              ¦   «         } |	|
|||||¦  «        \  }
}}}n(t          d
||f¦  «        \  } ||||||¬¦  «        \  }}}|dk    rt          |› d�¦  «        ‚|dk     rt          d| › d�¦  «        ‚|S )a  
    Solve the equation ``a @ x = b`` for ``x``,  where ``a`` is the
    Hermitian positive-definite banded matrix defined by `ab`.

    Uses Thomas' Algorithm, which is more efficient than standard LU
    factorization, but should only be used for Hermitian positive-definite
    matrices.

    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), number of upper diagonals,
    ``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 *   *

    Cells marked with * are not used.

    Parameters
    ----------
    ab : (``u`` + 1, M) array_like
        Banded matrix
    b : (M,) or (M, K) array_like
        Right-hand side
    overwrite_ab : bool, optional
        Discard data in `ab` (may enhance performance)
    overwrite_b : bool, optional
        Discard data in `b` (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 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 : (M,) or (M, K) ndarray
        The solution to the system ``a x = b``. Shape of return matches shape
        of `b`.

    Notes
    -----
    In the case of a non-positive definite matrix ``a``, the solver
    `solve_banded` may be used.

    Examples
    --------
    Solve the banded system ``A x = b``, where::

            [ 4  2 -1  0  0  0]       [1]
            [ 2  5  2 -1  0  0]       [2]
        A = [-1  2  6  2 -1  0]   b = [2]
            [ 0 -1  2  7  2 -1]       [3]
            [ 0  0 -1  2  8  2]       [3]
            [ 0  0  0 -1  2  9]       [3]

    >>> import numpy as np
    >>> from scipy.linalg import solveh_banded

    ``ab`` contains the main diagonal and the nonzero diagonals below the
    main diagonal. That is, we use the lower form:

    >>> ab = np.array([[ 4,  5,  6,  7, 8, 9],
    ...                [ 2,  2,  2,  2, 2, 0],
    ...                [-1, -1, -1, -1, 0, 0]])
    >>> b = np.array([1, 2, 2, 3, 3, 3])
    >>> x = solveh_banded(ab, b, lower=True)
    >>> x
    array([ 0.03431373,  0.45938375,  0.05602241,  0.47759104,  0.17577031,
            0.34733894])


    Solve the Hermitian banded system ``H x = b``, where::

            [ 8   2-1j   0     0  ]        [ 1  ]
        H = [2+1j  5     1j    0  ]    b = [1+1j]
            [ 0   -1j    9   -2-1j]        [1-2j]
            [ 0    0   -2+1j   6  ]        [ 0  ]

    In this example, we put the upper diagonals in the array ``hb``:

    >>> hb = np.array([[0, 2-1j, 1j, -2-1j],
    ...                [8,  5,    9,   6  ]])
    >>> b = np.array([1, 1+1j, 1-2j, 0])
    >>> x = solveh_banded(hb, b)
    >>> x
    array([ 0.07318536-0.02939412j,  0.11877624+0.17696461j,
            0.10077984-0.23035393j, -0.00479904-0.09358128j])

    rm   r^   r   r  r   r�   rn   )ÚptsvN)Úpbsv)rX   r¨   rZ   z&th leading minor not positive definiter	  zth argument of internal pbsv)r   r;   r+   r~   r   r<   r¯   r>   r°   r�   r   r	   ÚrealÚconjr   )rÅ   r„   r¨   rZ   rX   r[   r†   r‡   rÂ   r  r“   ÚerÎ   r‹   r-   r  Úcs                    r0   r   r   ~  s  € õR 
˜B¨\Ð	:Ñ	:Ô	:€BÝ	˜A¨LÐ	9Ñ	9Ô	9€Bð 
„x�„|�r”x ”{Ò"Ð"ÝÐAÑBÔBÐBð 
„w�!‚|€|Ý•2”6˜! 2¤8Ð,Ñ,Ô,­b¬g°a¸r¼xÐ.HÑ.HÔ.HÑIÔIÔOˆÝŒ}˜R rÐ*Ñ*Ô*Ð*àÐ3¥¨R°Ñ!3Ô!3€KØÐ6¥;¨r°2Ñ#6Ô#6€Là	„x�„{�aÒÐÝ  ¨R°¨HÑ5Ô5‰ˆØð 	!Ø�1�a�a�a�4””ˆAØ�1�c�r�c�6”
ˆAˆAà�1�a�a�a�4””ˆAØ�1�a�b�b�5”	—’Ñ Ô ˆAØ˜˜a  B¨°lØ)ñ+ô +‰ˆˆ2ˆq�$�$õ ! ¨R°¨HÑ5Ô5‰ˆØ�T˜"˜b¨¸LØ&1ð3ñ 3ô 3‰
ˆˆ1ˆdàˆa‚x€xÝ˜TÐIÐIÐIÑJÔJÐJØˆa‚x€xÝÐP¨d¨UÐPÐPÐPÑQÔQÐQØ€Hr2   c                 ó†   — t          | t          ¦  «        r| n| t          j        | ¦  «        f\  }}t	          ||||¦  «        S )aü	  Solve the equation ``T @ x = b`` for ``x``, where ``T`` is a Toeplitz
    matrix defined by `c_or_cr`.

    The Toeplitz matrix has constant diagonals, with ``c`` as its first column
    and ``r`` as its first row. If ``r`` is not given, ``r == conjugate(c)`` is
    assumed.

    The documentation is written assuming array arguments are of specified
    "core" shapes. However, array argument(s) of this function may have additional
    "batch" dimensions prepended to the core shape. In this case, the array is treated
    as a batch of lower-dimensional slices; see :ref:`linalg_batch` for details.

    Parameters
    ----------
    c_or_cr : array_like or tuple of (array_like, array_like)
        The vector ``c``, or a tuple of arrays (``c``, ``r``). If not
        supplied, ``r = conjugate(c)`` is assumed; in this case, if c[0] is
        real, the Toeplitz matrix is Hermitian. r[0] is ignored; the first row
        of the Toeplitz matrix is ``[c[0], r[1:]]``.
    b : (M,) or (M, K) array_like
        Right-hand side in ``T x = 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
        (result entirely NaNs) if the inputs do contain infinities or NaNs.

    Returns
    -------
    x : (M,) or (M, K) ndarray
        The solution to the system ``T @ x = b``. Shape of return matches shape
        of `b`.

    See Also
    --------
    toeplitz : Toeplitz matrix

    Notes
    -----
    The solution is computed using Levinson-Durbin recursion, which is faster
    than generic least-squares methods, but can be less numerically stable.

    Examples
    --------
    Solve the Toeplitz system ``T @ x = b``, where::

            [ 1 -1 -2 -3]       [1]
        T = [ 3  1 -1 -2]   b = [2]
            [ 6  3  1 -1]       [2]
            [10  6  3  1]       [5]

    To specify the Toeplitz matrix, only the first column and the first
    row are needed.

    >>> import numpy as np
    >>> c = np.array([1, 3, 6, 10])    # First column of T
    >>> r = np.array([1, -1, -2, -3])  # First row of T
    >>> b = np.array([1, 2, 2, 5])

    >>> from scipy.linalg import solve_toeplitz, toeplitz
    >>> x = solve_toeplitz((c, r), b)
    >>> x
    array([ 1.66666667, -1.        , -2.66666667,  2.33333333])

    Check the result by creating the full Toeplitz matrix and
    multiplying it by ``x``.  We should get `b`.

    >>> T = toeplitz(c, r)
    >>> T.dot(x)
    array([ 1.,  2.,  2.,  5.])

    )Ú
isinstanceÚtupler<   Ú	conjugateÚ_solve_toeplitz)Úc_or_crr„   r[   r  Úrs        r0   r   r     sD   € õV ! ­%Ñ0Ô0ÐVˆ7ˆ7°wÅÄÈWÑ@UÔ@UÐ6V�D€A€qÝ˜1˜a  LÑ1Ô1Ð1r2   )r  r   )r#  r   c                 óÆ  ‡‡— t          | |f‰|d¬¦  «        \  }} Š}}‰j        dk    rt          j        ‰¦  «        S t          j        |ddd…         | f¦  «        Š‰€t          d¦  «        ‚‰j        dk    r&t          ‰t          j        ‰¦  «        ¦  «        \  }}nCt          j	        ˆˆfd„t          ‰j        d         ¦  «        D ¦   «         ¦  «        } |j        |Ž }|S )NT)Úkeep_b_shaper   r^   z)illegal value, `b` is a required argumentr   c           
      ót   •— g | ]4}t          ‰t          j        ‰d d …|f         ¦  «        ¦  «        d         ‘Œ5S )Nr   )r   r<   Úascontiguousarray)rí   rS   r„   Úvalss     €€r0   ú
<listcomp>z#_solve_toeplitz.<locals>.<listcomp>l  sO   ø€ ð 9ð 9ð 9Ø!"õ & d­BÔ,@ÀÀ1À1À1ÀaÀ4ÄÑ,IÔ,IÑJÔJÈ1ÔMð 9ð 9ð 9r2   )Ú_validate_args_for_toeplitz_opsr~   r<   r�   Úconcatenater+   ry   r   r'  Úcolumn_stackrç   r;   Úreshape)	r  r#  r„   r[   r>   Úb_shaper‹   r  r(  s	     `     @r0   r!  r!  Z  s  øø€ å=Ø	
ˆAˆ��<¨dð4ñ 4ô 4Ñ€A€qˆ!ˆU�Gð 	„v�‚{€{ÝŒ}˜QÑÔÐõ Œ>˜1˜R  "˜Wœ: q˜/Ñ*Ô*€DØ€yÝÐDÑEÔEÐEà„v�‚{€{Ý˜�bÔ2°1Ñ5Ô5Ñ6Ô6‰ˆˆ1ˆ1åŒOð 9ð 9ð 9ð 9ð 9Ý&+¨A¬G°A¬JÑ&7Ô&7ð9ñ 9ô 9ñ :ô :ˆàˆAŒI�wÐˆà€Hr2   c                 ó�   — |}|dk     r
||j         z  }d|cxk    r|j         k     rn n|j        |         S t          d| › d�¦  «        ‚)Nr   ú'zaxis' entry is out of bounds)ry   r;   r+   )Úanamer@   ÚaxisÚaxs       r0   Ú_get_axis_lenr4  s  se   € Ø	€BØ	ˆA‚v€vØ
ˆaŒf‰ˆØˆBÐÐÒÐ�”ÒÐÐÐÐØŒw�rŒ{ÐÝ
Ð<˜Ð<Ð<Ð<Ñ
=Ô
=Ð=r2   Úraiser^   c                 óB  — t          j        | ¦  «        } t          d| |¦  «        }t          j        |¦  «        }t          d||¦  «        }||k    r t          d| j        › d|j        › d�¦  «        ‚|j        dk    r]t          t          j        d| j        ¬¦  «        t          j	        d|j        ¬¦  «        ¦  «        j        }	t          j
        ||	¬¦  «        S t           j                             t          j        | |d	¦  «        d	¬
¦  «        }
t          j        |
¦  «        }|€z|                     d	¬
¦  «        |z  t          j        t           j        ¦  «        j        z  }|j        dk    r|                     |j        dz   ¦  «        }nt          j        |¦  «        }||k    }t          j        |¦  «        }|r|dk    rt)          d¦  «        ‚d|
|<   t           j                             t          j        ||d	¦  «        d	¬
¦  «        }||
z  }|r#t          j        |t,          ¬¦  «        |z  }d||<   t           j                             |d	¬
¦  «        }t          j        | ¦  «        st          j        |¦  «        s|j        }|d	k    rt          j        |d	|¦  «        }|S )aÉ  Solve the equation ``C @ x = b`` for ``x``, where ``C`` is a
    circulant matrix defined by `c`.

    `C` is the circulant matrix associated with the vector `c`.

    The system is solved by doing division in Fourier space. The
    calculation is::

        x = ifft(fft(b) / fft(c))

    where `fft` and `ifft` are the fast Fourier transform and its inverse,
    respectively. For a large vector `c`, this is *much* faster than
    solving the system with the full circulant matrix.

    Parameters
    ----------
    c : array_like
        The coefficients of the circulant matrix.
    b : array_like
        Right-hand side matrix in ``a x = b``.
    singular : str, optional
        This argument controls how a near singular circulant matrix is
        handled.  If `singular` is "raise" and the circulant matrix is
        near singular, a `LinAlgError` is raised. If `singular` is
        "lstsq", the least squares solution is returned. Default is "raise".
    tol : float, optional
        If any eigenvalue of the circulant matrix has an absolute value
        that is less than or equal to `tol`, the matrix is considered to be
        near singular. If not given, `tol` is set to::

            tol = abs_eigs.max() * abs_eigs.size * np.finfo(np.float64).eps

        where `abs_eigs` is the array of absolute values of the eigenvalues
        of the circulant matrix.
    caxis : int
        When `c` has dimension greater than 1, it is viewed as a collection
        of circulant vectors. In this case, `caxis` is the axis of `c` that
        holds the vectors of circulant coefficients.
    baxis : int
        When `b` has dimension greater than 1, it is viewed as a collection
        of vectors. In this case, `baxis` is the axis of `b` that holds the
        right-hand side vectors.
    outaxis : int
        When `c` or `b` are multidimensional, the value returned by
        `solve_circulant` is multidimensional. In this case, `outaxis` is
        the axis of the result that holds the solution vectors.

    Returns
    -------
    x : ndarray
        Solution to the system ``C x = b``.

    Raises
    ------
    LinAlgError
        If the circulant matrix associated with `c` is near singular.

    See Also
    --------
    circulant : circulant matrix

    Notes
    -----
    For a 1-D vector `c` with length `m`, and an array `b`
    with shape ``(m, ...)``,

        solve_circulant(c, b)

    returns the same result as

        solve(circulant(c), b)

    where `solve` and `circulant` are from `scipy.linalg`.

    .. versionadded:: 0.16.0

    Examples
    --------
    >>> import numpy as np
    >>> from scipy.linalg import solve_circulant, solve, circulant, lstsq

    >>> c = np.array([2, 2, 4])
    >>> b = np.array([1, 2, 3])
    >>> solve_circulant(c, b)
    array([ 0.75, -0.25,  0.25])

    Compare that result to solving the system with `scipy.linalg.solve`:

    >>> solve(circulant(c), b)
    array([ 0.75, -0.25,  0.25])

    A singular example:

    >>> c = np.array([1, 1, 0, 0])
    >>> b = np.array([1, 2, 3, 4])

    Calling ``solve_circulant(c, b)`` will raise a `LinAlgError`.  For the
    least square solution, use the option ``singular='lstsq'``:

    >>> solve_circulant(c, b, singular='lstsq')
    array([ 0.25,  1.25,  2.25,  1.25])

    Compare to `scipy.linalg.lstsq`:

    >>> x, resid, rnk, s = lstsq(circulant(c), b)
    >>> x
    array([ 0.25,  1.25,  2.25,  1.25])

    A broadcasting example:

    Suppose we have the vectors of two circulant matrices stored in an array
    with shape (2, 5), and three `b` vectors stored in an array with shape
    (3, 5).  For example,

    >>> c = np.array([[1.5, 2, 3, 0, 0], [1, 1, 4, 3, 2]])
    >>> b = np.arange(15).reshape(-1, 5)

    We want to solve all combinations of circulant matrices and `b` vectors,
    with the result stored in an array with shape (2, 3, 5). When we
    disregard the axes of `c` and `b` that hold the vectors of coefficients,
    the shapes of the collections are (2,) and (3,), respectively, which are
    not compatible for broadcasting. To have a broadcast result with shape
    (2, 3), we add a trivial dimension to `c`: ``c[:, np.newaxis, :]`` has
    shape (2, 1, 5). The last dimension holds the coefficients of the
    circulant matrices, so when we call `solve_circulant`, we can use the
    default ``caxis=-1``. The coefficients of the `b` vectors are in the last
    dimension of the array `b`, so we use ``baxis=-1``. If we use the
    default `outaxis`, the result will have shape (5, 2, 3), so we'll use
    ``outaxis=-1`` to put the solution vectors in the last dimension.

    >>> x = solve_circulant(c[:, np.newaxis, :], b, baxis=-1, outaxis=-1)
    >>> x.shape
    (2, 3, 5)
    >>> np.set_printoptions(precision=3)  # For compact output of numbers.
    >>> x
    array([[[-0.118,  0.22 ,  1.277, -0.142,  0.302],
            [ 0.651,  0.989,  2.046,  0.627,  1.072],
            [ 1.42 ,  1.758,  2.816,  1.396,  1.841]],
           [[ 0.401,  0.304,  0.694, -0.867,  0.377],
            [ 0.856,  0.758,  1.149, -0.412,  0.831],
            [ 1.31 ,  1.213,  1.603,  0.042,  1.286]]])

    Check by solving one pair of `c` and `b` vectors (cf. ``x[1, 1, :]``):

    >>> solve_circulant(c[1], b[1, :])
    array([ 0.856,  0.758,  1.149, -0.412,  0.831])

    r  r„   zShapes of c rþ   rÿ   r   r(   r�   r^   ©r2  N© )r   r5  znear singular circulant matrix.r   )r<   r   r4  r+   r;   r~   r   Úaranger>   r°   r�   ÚfftÚmoveaxisr¼   r¾   rö   rì   Úepsr-  Úanyr   Ú	ones_likeÚboolÚifftr±   r  )r  r„   rP   ÚtolÚcaxisÚbaxisÚoutaxisÚncÚnbrÂ   ÚfcÚabs_fcÚ
near_zerosÚis_near_singularÚfbÚqÚmaskr‹   s                     r0   r   r   |  sk  € õl 	Œ�aÑÔ€AÝ	�s˜A˜uÑ	%Ô	%€BÝ
Œ�aÑÔ€AÝ	�s˜A˜uÑ	%Ô	%€BØ	ˆR‚x€xÝÐR¨¬ÐRÐR¸¼ÐRÐRÐRÑSÔSÐSð 	„v�‚{€{Ý�RœY q°´Ð8Ñ8Ô8ÝœW Q¨a¬gÐ6Ñ6Ô6ñ8ô 8Ü8=ð 	åŒ}˜Q bÐ)Ñ)Ô)Ð)å	Œ�Š•B”K  5¨"Ñ-Ô-°BˆÑ	7Ô	7€BÝŒV�B‰ZŒZ€FØ
€{à�jŠj˜bˆjÑ!Ô! BÑ&­¬µ"´*Ñ)=Ô)=Ô)AÑAˆØŒ9˜Š?ˆ?Ø—+’+˜cœi¨$Ñ.Ñ/Ô/ˆCˆCå”- Ñ$Ô$ˆCà˜3’€JÝ”v˜jÑ)Ô)ÐØð Ø�wÒÐÝÐ?Ñ@Ô@Ð@ð ˆBˆz‰Nå	Œ�Š•B”K  5¨"Ñ-Ô-°BˆÑ	7Ô	7€Bà
ˆR‰€Aàð õ Œ|˜A¥TÐ*Ñ*Ô*¨ZÑ7ˆØˆˆ$‰å
Œ�Š�A˜BˆÑÔ€AÝŒO˜AÑÔð ¥"¤/°!Ñ"4Ô"4ð ØŒFˆØ�"‚}€}ÝŒK˜˜2˜wÑ'Ô'ˆØ€Hr2   )r\   rX   c          
      ó¨  — t          | |¬¦  «        }|j        dk     rt          d|j        ›�¦  «        ‚|j        d         |j        d         k    rt          d|j        ›�¦  «        ‚|j        dk    rCt          t          j        d|j        ¬¦  «        ¦  «        j        }t          j	        ||¬¦  «        S t          ||¦  «        \  }}|j        d	         s&|j        j        d
k    sd}|                     ¦   «         }|o|j        dk    o|j        d         }ddddddddddœ	|         }t          j        ||||¦  «        \  }}	|	rt!          |	¦  «         |S )a.  
    Compute the inverse of a matrix.

    If the data matrix is known to be a particular type then supplying the
    corresponding string to ``assume_a`` key chooses the dedicated solver.
    The available options are

    =============================  ================================
     general                        'general' (or 'gen')
     diagonal                       'diagonal'
     upper triangular               'upper triangular'
     lower triangular               'lower triangular'
     symmetric positive definite    'pos'
     symmetric                      'sym'
     Hermitian                      'her'
    =============================  ================================

    For the 'pos' option, only the triangle of the input matrix specified in
    the `lower` argument is used, and the other triangle is not referenced.
    Likewise, an explicit `assume_a='diagonal'` means that off-diagonal elements
    are not referenced.

    Array argument(s) of this function may have additional
    "batch" dimensions prepended to the core shape. In this case, the array is treated
    as a batch of lower-dimensional slices; see :ref:`linalg_batch` for details.

    Parameters
    ----------
    a : array_like, shape (..., M, M)
        Square matrix (or a batch of matrices) to be inverted.
    overwrite_a : bool, optional
        Discard data in `a` (may improve performance). Default is False.
    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.
    assume_a : str, optional
        Valid entries are described above.
        If omitted or ``None``, checks are performed to identify structure so the
        appropriate solver can be called.
    lower : bool, optional
        Ignored unless `assume_a` is one of 'sym', 'her', or 'pos'. If True, the
        calculation uses only the data in the lower triangle of `a`; entries above the
        diagonal are ignored. If False (default), the calculation uses only the data in
        the upper triangle of `a`; entries below the diagonal are ignored.

    Returns
    -------
    ainv : ndarray
        Inverse of the matrix `a`.

    Raises
    ------
    LinAlgError
        If `a` is singular.
    ValueError
        If `a` is not square, or not 2D.

    Examples
    --------
    >>> import numpy as np
    >>> from scipy import linalg
    >>> a = np.array([[1., 2.], [3., 4.]])
    >>> linalg.inv(a)
    array([[-2. ,  1. ],
           [ 1.5, -0.5]])
    >>> np.dot(a, linalg.inv(a))
    array([[ 1.,  0.],
           [ 0.,  1.]])

    Notes
    -----

    The input array ``a`` may represent a single matrix or a collection (a.k.a.
    a "batch") of square matrices. For example, if ``a.shape == (4, 3, 2, 2)``, it is
    interpreted as a ``(4, 3)``-shaped batch of :math:`2\times 2` matrices.

    This routine checks the condition number of the `a` matrix and emits a
    `LinAlgWarning` for ill-conditioned inputs.

    rm   rn   ro   r^   rp   rq   r   r�   rs   rt   Tru   r_   ra   rb   rc   rd   re   )	Nr:   rf   r4   r6   r5   rg   ri   rj   )r   ry   r+   r;   r~   r   r<   r¯   r>   r�   r
   r{   r|   r}   r   Ú_invrU   )
r@   rY   r[   r\   rX   r†   rÂ   r…   Úinv_arO   s
             r0   r   r   I  sz  € õd 
˜A¨LÐ	9Ñ	9Ô	9€Bà	„w�‚{€{ÝÐD¸"¼'ÐDÐDÑEÔEÐEØ	„x�„|�r”x ”|Ò#Ð#ÝÐC¸¼ÐCÐCÑDÔDÐDð 
„w�!‚|€|Ý•”˜ ¤Ð*Ñ*Ô*Ñ+Ô+Ô1ˆÝŒ}˜R rÐ*Ñ*Ô*Ð*õ .¨b°+Ñ>Ô>�O€BˆàŒH�YÔð  2¤8Ô#5¸Ò#<Ð#<ØˆØ�WŠW‰YŒYˆð ÐO 2¤7¨a¢<ÐO°b´h¸~Ô6N€Kð Ø˜QØØØØØØð	ð 	ð ô	€Iõ %Ô)¨"¨i¸ÀeÑLÔL�N€Eˆ7àð .Ý$ WÑ-Ô-Ð-à€Lr2   c                 óV  — |rt          j        | ¦  «        nt          j        | ¦  «        }|j        dk     rt	          d¦  «        ‚|j        d         |j        d         k    rt	          d|j        › d�¦  «        ‚t          ||¦  «        \  }}t          |j        Ž dk    r_|j        j	        dvrt           j
        nt           j        }|j        dk    r |d	¦  «        S t          j        |j        d
d…         |¬¦  «        S |j        dd
…         dk    re|d         }|j        dk    r|d         }|j        j	        dv r|S |j        j	        dk    r|                     d¦  «        n|                     d¦  «        S t          || ¦  «        s|s|                     d¬¦  «        }|j        d         r|j        d         s|                     d¬¦  «        }|j        dk    rKt#          |¦  «        }t          j        |¦  «        rt          j
        |¦  «        nt          j        |¦  «        S |j        j	        }|dv r|                     ¦   «         rdnd}t          j        |j        d
d…         |¬¦  «        }t+          d„ |j        d
d…         D ¦   «         Ž D ]}t#          ||         ¦  «        ||<   Œ|S )a˜	  
    Compute the determinant of a matrix

    The determinant is a scalar that is a function of the associated square
    matrix coefficients. The determinant value is zero for singular matrices.

    Array argument(s) of this function may have additional
    "batch" dimensions prepended to the core shape. In this case, the array is treated
    as a batch of lower-dimensional slices; see :ref:`linalg_batch` for details.

    Parameters
    ----------
    a : (..., M, M) array_like
        Input array to compute determinants for.
    overwrite_a : bool, optional
        Allow overwriting data in a (may enhance 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
    -------
    det : (...) float or complex
        Determinant of `a`. For stacked arrays, a scalar is returned for each
        (m, m) slice in the last two dimensions of the input. For example, an
        input of shape (p, q, m, m) will produce a result of shape (p, q). If
        all dimensions are 1 a scalar is returned regardless of ndim.

    Notes
    -----
    The determinant is computed by performing an LU factorization of the
    input with LAPACK routine 'getrf', and then calculating the product of
    diagonal entries of the U factor.

    Even if the input array is single precision (float32 or complex64), the
    result will be returned in double precision (float64 or complex128) to
    prevent overflows.

    Examples
    --------
    >>> import numpy as np
    >>> from scipy import linalg
    >>> a = np.array([[1,2,3], [4,5,6], [7,8,9]])  # A singular matrix
    >>> linalg.det(a)
    0.0
    >>> b = np.array([[0,2,3], [4,5,6], [7,8,9]])
    >>> linalg.det(b)
    3.0
    >>> # An array with the shape (3, 2, 2, 2)
    >>> c = np.array([[[[1., 2.], [3., 4.]],
    ...                [[5., 6.], [7., 8.]]],
    ...               [[[9., 10.], [11., 12.]],
    ...                [[13., 14.], [15., 16.]]],
    ...               [[[17., 18.], [19., 20.]],
    ...                [[21., 22.], [23., 24.]]]])
    >>> linalg.det(c)  # The resulting shape is (3, 2)
    array([[-2., -2.],
           [-2., -2.],
           [-2., -2.]])
    >>> linalg.det(c[0, 0])  # Confirm the (0, 0) slice, [[1, 2], [3, 4]]
    -2.0
    rn   z1The input array must be at least two-dimensional.r^   rp   zALast 2 dimensions of the array must be square but received shape rJ   r   ÚFDç      ð?N)r;   r>   )r   r   ).r   r   r8  ÚdDr’   r“   ÚDr  )ÚorderÚC_CONTIGUOUSÚ	WRITEABLEr‘   r�   c                 ó,   — g | ]}t          |¦  «        ‘ŒS r8  )rç   )rí   r‹   s     r0   r)  zdet.<locals>.<listcomp>@  s   € Ð9Ð9Ð9 a�˜q™œÐ9Ð9Ð9r2   )r<   rØ   Úasarrayry   r+   r;   r   r½   r>   r²   rì   rú   r°   rë   r   r}   r{   r   Ú	isrealobjÚislowerÚemptyr   )r@   rY   r[   r†   Údtypr    Ú
dtype_charÚinds           r0   r    r    È  s­  € ðF %1Ð	C�Ô	˜aÑ	 Ô	 Ð	 µb´jÀ±m´m€BØ	„w�‚{€{ÝÐLÑMÔMÐMØ	„x�„|�r”x ”|Ò#Ð#Ýð <Ø02´ð<ð <ð <ñ =ô =ð 	=õ /¨r°;Ñ?Ô?�O€Bˆõ ˆBŒH€~˜ÒÐØœXœ]°$Ð6Ð6�rŒzˆz½B¼MˆØŒ7�aŠ<ˆ<Ø�4˜‘9”9Ðå”7 ¤¨#¨2¨#¤°dÐ;Ñ;Ô;Ð;ð 
„x���„}˜ÒÐØ�	Œ]ˆØŒ7�aŠ<ˆ<Ø�B”ˆBàŒ8Œ=˜DÐ Ð ØˆIØ!#¤¤°#Ò!5Ð!5ˆr�yŠy˜‰~Œ~ˆ~¸2¿9º9ÀS¹>¼>ÐIõ �r˜1ÑÔð $Øð 	$à—’˜s�Ñ#Ô#ˆBð ŒH�^Ô$ð  ¨¬°+Ô)>ð  Ø�WŠW˜3ˆWÑÔˆà	„w�!‚|€|Ý˜rÑ"Ô"ˆå#%¤<°Ñ#4Ô#4ÐL•”
˜3‘”�½"¼-ÈÑ:LÔ:LÐMð ””€JØ�TÐÐØ&×.Ò.Ñ0Ô0Ð9�S�S°cˆ
å
Œ(�2”8˜C˜R˜C”=¨
Ð
3Ñ
3Ô
3€CÝÐ9Ð9¨2¬8°C°R°C¬=Ð9Ñ9Ô9Ð:ð -ð -ˆÝ# B s¤GÑ,Ô,ˆˆC‰ˆØ€Jr2   c           
      ó^  — t          | |¬¦  «        }t          ||¬¦  «        }t          |j        ¦  «        dk    rt          d¦  «        ‚|j        \  }	}
t          |j        ¦  «        dk    r|j        d         }nd}|	|j        d         k    r!t          d|	› d|j        d         › d�¦  «        ‚|	dk    s|
dk    r‘t	          j        |
f|j        dd	…         z   t	          j        ||¦  «        ¬
¦  «        }|
dk    r%t          j                             |d¬¦  «        dz  }nt	          j	        d¦  «        }||dt	          j	        d¦  «        fS |}|€t          j        }|dvrt          d|› d�¦  «        ‚t          ||› d�f||f¦  «        \  }}|j        j        dk    rdnd}|	|
k     ret          |j        ¦  «        dk    r)t	          j        |
|f|j        ¬
¦  «        }||d	|	…d	d	…f<   n"t	          j        |
|j        ¬
¦  «        }||d	|	…<   |}|pt          || ¦  «        }|pt          ||¦  «        }|€t	          j        |j        ¦  «        j        }|dv �r2|dk    r,t%          ||	|
||¦  «        } |||||||¬¦  «        \  }}}}}}nc|dk    r]|r-t%          ||	|
||¦  «        \  }} ||||||dd¦  «        \  }}}}n.t%          ||	|
||¦  «        \  }}} |||||||dd¦  «        \  }}}}|dk    rt'          d¦  «        ‚|dk     rt          d| › d|› �¦  «        ‚t	          j        g |j        ¬
¦  «        }|	|
k    rE|d	|
…         }||
k    r3t	          j        t	          j        ||
d	…         ¦  «        dz  d¬¦  «        }|}||||fS |dk    r¡t%          ||	|
||¦  «        }t	          j        |j        d         dft          j        ¬
¦  «        } ||||||dd¦  «        \  }}}}}|dk     rt          d| › d�¦  «        ‚|	|
k    r|d	|
…         }|}|t	          j        g |j        ¦  «        |d	fS d	S )a  
    Compute least-squares solution to the equation ``a @ x = b``.

    Compute a vector x such that the 2-norm ``|b - A x|`` is minimized.

    Parameters
    ----------
    a : (M, N) array_like
        Left-hand side array
    b : (M,) or (M, K) array_like
        Right hand side array
    cond : float, optional
        Cutoff for 'small' singular values; used to determine effective
        rank of a. Singular values smaller than
        ``cond * largest_singular_value`` are considered zero.
    overwrite_a : bool, optional
        Discard data in `a` (may enhance performance). Default is False.
    overwrite_b : bool, optional
        Discard data in `b` (may enhance performance). Default is False.
    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.
    lapack_driver : str, optional
        Which LAPACK driver is used to solve the least-squares problem.
        Options are ``'gelsd'``, ``'gelsy'``, ``'gelss'``. Default
        (``'gelsd'``) is a good choice.  However, ``'gelsy'`` can be slightly
        faster on many problems.  ``'gelss'`` was used historically.  It is
        generally slow but uses less memory.

        .. versionadded:: 0.17.0

    Returns
    -------
    x : (N,) or (N, K) ndarray
        Least-squares solution.
    residues : (K,) ndarray or float
        Square of the 2-norm for each column in ``b - a x``, if ``M > N`` and
        ``rank(A) == n`` (returns a scalar if ``b`` is 1-D). Otherwise a
        (0,)-shaped array is returned.
    rank : int
        Effective rank of `a`.
    s : (min(M, N),) ndarray or None
        Singular values of `a`. The condition number of ``a`` is
        ``s[0] / s[-1]``.

    Raises
    ------
    LinAlgError
        If computation does not converge.

    ValueError
        When parameters are not compatible.

    See Also
    --------
    scipy.optimize.nnls : linear least squares with non-negativity constraint

    Notes
    -----
    When ``'gelsy'`` is used as a driver, `residues` is set to a (0,)-shaped
    array and `s` is always ``None``.

    Examples
    --------
    >>> import numpy as np
    >>> from scipy.linalg import lstsq
    >>> import matplotlib.pyplot as plt

    Suppose we have the following data:

    >>> x = np.array([1, 2.5, 3.5, 4, 5, 7, 8.5])
    >>> y = np.array([0.3, 1.1, 1.5, 2.0, 3.2, 6.6, 8.6])

    We want to fit a quadratic polynomial of the form ``y = a + b*x**2``
    to this data.  We first form the "design matrix" M, with a constant
    column of 1s and a column containing ``x**2``:

    >>> M = x[:, np.newaxis]**[0, 2]
    >>> M
    array([[  1.  ,   1.  ],
           [  1.  ,   6.25],
           [  1.  ,  12.25],
           [  1.  ,  16.  ],
           [  1.  ,  25.  ],
           [  1.  ,  49.  ],
           [  1.  ,  72.25]])

    We want to find the least-squares solution to ``M.dot(p) = y``,
    where ``p`` is a vector with length 2 that holds the parameters
    ``a`` and ``b``.

    >>> p, res, rnk, s = lstsq(M, y)
    >>> p
    array([ 0.20925829,  0.12013861])

    Plot the data and the fitted curve.

    >>> plt.plot(x, y, 'o', label='data')
    >>> xx = np.linspace(0, 9, 101)
    >>> yy = p[0] + p[1]*xx**2
    >>> plt.plot(xx, yy, label='least squares fit, $y = a + bx^2$')
    >>> plt.xlabel('x')
    >>> plt.ylabel('y')
    >>> plt.legend(framealpha=1, shadow=True)
    >>> plt.grid(alpha=0.25)
    >>> plt.show()

    rm   rn   zInput array a should be 2Dr   r   z=Shape mismatch: a and b should have the same number of rows (z != z).Nr�   r7  )r   )ÚgelsdÚgelsyÚgelsszLAPACK driver "z" is not foundÚ_lworkr’   TF)rd  rb  rd  )rY   rZ   rb  z,SVD did not converge in Linear Least Squaresr	  z-th argument of internal rc  z-th argument of internal gelsy)r   r   r;   r+   r<   r¿   Úcommon_typeÚlinalgrš   r]  r!   Údefault_lapack_driverr	   r>   rC   r   rö   r<  r   r   rZ  Úsumr¼   Úint32rî   )r@   r„   ÚcondrY   rZ   r[   Úlapack_driverr†   r‡   Úmr,   Únrhsr‹   ÚresiduesÚdriverÚlapack_funcÚlapack_lworkÚ	real_datar  rž   ÚvÚsÚrankÚworkr-   ÚiworkÚrworkÚresidsÚx1ÚjptvÚjs                                  r0   r!   r!   F  s/  € õ` 
˜A¨LÐ	9Ñ	9Ô	9€BÝ	˜A¨LÐ	9Ñ	9Ô	9€BÝ
ˆ2Œ8�}„}˜ÒÐÝÐ5Ñ6Ô6Ð6ØŒ8�D€A€qÝ
ˆ2Œ8�}„}˜ÒÐØŒx˜Œ{ˆˆàˆØˆBŒH�QŒKÒÐÝð =Ø&'ð=ð =Ø-/¬X°a¬[ð=ð =ð =ñ >ô >ð 	>àˆA‚v€v��a’�ÝŒH�a�T˜BœH Q R RœLÑ(µ´¸rÀ2Ñ0FÔ0FÐGÑGÔGˆØ�Š6ˆ6Ý”y—~’~ b¨q�~Ñ1Ô1°1Ñ4ˆHˆHå”x ‘~”~ˆHØ�(˜A�rœx¨™~œ~Ð-Ð-à€FØ€~ÝÔ,ˆØÐ0Ð0Ð0ÝÐA¨6ÐAÐAÐAÑBÔBÐBå 0°&Ø4:Ð1BÐ1BÐ1Bð2Dà24°b°ñ!;ô !;Ñ€K�ð %Ô*Ô/°3Ò6Ð6��¸U€Iàˆ1‚u€uõ ˆrŒx‰=Œ=˜AÒÐÝ”˜1˜d˜)¨;Ô+<Ð=Ñ=Ô=ˆBØˆBˆr�ˆr�1�1�1ˆu‰IˆIå”˜! ;Ô#4Ð5Ñ5Ô5ˆBØˆBˆr�ˆr‰FØˆàÐ3¥¨R°Ñ!3Ô!3€KØÐ3¥¨R°Ñ!3Ô!3€Kà€|ÝŒx˜Ô)Ñ*Ô*Ô.ˆàÐ#Ð#Ñ#Ø�WÒÐÝ" <°°A°t¸TÑBÔBˆEØ(3¨°B¸¸DÀ%Ø@KØ@Kð)Mñ )Mô )MÑ%ˆAˆq�!�T˜4  ð �wÒÐØð CÝ-¨l¸A¸qÀ$ÈÑMÔM‘��uØ#. ;¨r°2°uØ/4°d¸EÀ5ñ$Jô $JÑ ��1�d˜D˜Dõ '5°\À1ÀaØ59¸4ñ'Aô 'AÑ#��u˜eà#. ;¨r°2°u¸eÀUØ/3°U¸Eñ$Cô $CÑ ��1�d˜Dà�!Š8ˆ8ÝÐLÑMÔMÐMØ�!Š8ˆ8ÝØS T EÐSÐSÀMÐSÐSñô ð õ ”˜B a¤gÐ.Ñ.Ô.ˆØˆqŠ5ˆ5Ø�2�A�2”ˆBØ�qŠyˆyÝœ¥¤ q¨¨¨¤u¡¤¨qÑ 0°qÐ9Ñ9Ô9�ØˆAØ�&˜$ Ð!Ð!à	�7Ò	Ð	Ý˜|¨Q°°4¸Ñ>Ô>ˆÝŒx˜œ !œ aÐ(µ´Ð9Ñ9Ô9ˆØ)˜k¨"¨b°$¸Ø*/°¸ñ?ô ?Ñˆˆ1ˆa��tà�!Š8ˆ8ÝÐV°$°ÐVÐVÐVÑWÔWÐWØˆqŠ5ˆ5Ø�2�A�2”ˆBØˆAØ•"”(˜2˜qœwÑ'Ô'¨¨tÐ3Ð3ð 
Ð	r2   rb  )ÚatolÚrtolÚreturn_rankr[   c                ó6  — t          | |¬¦  «        } t          j        | dd¬¦  «        \  }}}|j        j                             ¦   «         }t          j        |d¬¦  «        }	|€dn|}|€.t          | j        ¦  «        t          j	        |¦  «        j
        z  n|}|dk     s|dk     rt          d¦  «        ‚||	|z  z   }
t          j        ||
k    ¦  «        }|dd…d|…f         }||d|…         z  }||d|…         z                       ¦   «         j        }|r||fS |S )aI  
    Compute the (Moore-Penrose) pseudo-inverse of a matrix.

    Calculate a generalized inverse of a matrix using its
    singular-value decomposition ``U @ S @ V`` in the economy mode and picking
    up only the columns/rows that are associated with significant singular
    values.

    If ``s`` is the maximum singular value of ``a``, then the
    significance cut-off value is determined by ``atol + rtol * s``. Any
    singular value below this value is assumed insignificant.

    Parameters
    ----------
    a : (M, N) array_like
        Matrix to be pseudo-inverted.
    atol : float, optional
        Absolute threshold term, default value is 0.

        .. versionadded:: 1.7.0

    rtol : float, optional
        Relative threshold term, default value is ``max(M, N) * eps`` where
        ``eps`` is the machine precision value of the datatype of ``a``.

        .. versionadded:: 1.7.0

    return_rank : bool, optional
        If True, return the effective rank of the matrix.
    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
    -------
    B : (N, M) ndarray
        The pseudo-inverse of matrix `a`.
    rank : int
        The effective rank of the matrix. Returned if `return_rank` is True.

    Raises
    ------
    LinAlgError
        If SVD computation does not converge.

    See Also
    --------
    pinvh : Moore-Penrose pseudoinverse of a hermitian matrix.

    Notes
    -----
    If ``A`` is invertible then the Moore-Penrose pseudoinverse is exactly
    the inverse of ``A`` [1]_. If ``A`` is not invertible then the
    Moore-Penrose pseudoinverse computes the ``x`` solution to ``Ax = b`` such
    that ``||Ax - b||`` is minimized [1]_.

    References
    ----------
    .. [1] Penrose, R. (1956). On best approximate solutions of linear matrix
           equations. Mathematical Proceedings of the Cambridge Philosophical
           Society, 52(1), 17-19. doi:10.1017/S0305004100030929

    Examples
    --------

    Given an ``m x n`` matrix ``A`` and an ``n x m`` matrix ``B`` the four
    Moore-Penrose conditions are:

    1. ``ABA = A`` (``B`` is a generalized inverse of ``A``),
    2. ``BAB = B`` (``A`` is a generalized inverse of ``B``),
    3. ``(AB)* = AB`` (``AB`` is hermitian),
    4. ``(BA)* = BA`` (``BA`` is hermitian) [1]_.

    Here, ``A*`` denotes the conjugate transpose. The Moore-Penrose
    pseudoinverse is a unique ``B`` that satisfies all four of these
    conditions and exists for any ``A``. Note that, unlike the standard
    matrix inverse, ``A`` does not have to be a square matrix or have
    linearly independent columns/rows.

    As an example, we can calculate the Moore-Penrose pseudoinverse of a
    random non-square matrix and verify it satisfies the four conditions.

    >>> import numpy as np
    >>> from scipy import linalg
    >>> rng = np.random.default_rng()
    >>> A = rng.standard_normal((9, 6))
    >>> B = linalg.pinv(A)
    >>> np.allclose(A @ B @ A, A)  # Condition 1
    True
    >>> np.allclose(B @ A @ B, B)  # Condition 2
    True
    >>> np.allclose((A @ B).conj().T, A @ B)  # Condition 3
    True
    >>> np.allclose((B @ A).conj().T, B @ A)  # Condition 4
    True

    rm   F)Úfull_matricesr[   ç        ©ÚinitialNú&atol and rtol values must be positive.)r   r   Úsvdr>   r²   rX   r<   r¾   r;   rö   r<  r+   ri  r  rµ   )r@   r~  r  r€  r[   Úuru  ÚvhÚtÚmaxSÚvalrv  ÚBs                r0   r"   r"     s)  € õH 	˜1¨<Ð8Ñ8Ô8€AÝŒ˜q°ÀEÐJÑJÔJ�H€A€qˆ"Ø	ŒŒ×ÒÑÔ€AÝŒ6�!˜RÐ Ñ Ô €Dà�ˆ2ˆ2 4€DØ.2¨l�3ˆqŒw‰<Œ<�"œ( 1™+œ+œ/Ñ)Ð)À€DàˆrŠ	ˆ	�t˜b’y�yÝÐAÑBÔBÐBà
�˜‘Ñ
€CÝŒ6�!�c’'‰?Œ?€Dà	ˆ!ˆ!ˆ!ˆUˆdˆUˆ(Œ€AØˆˆ5ˆDˆ5Œ�M€AØ	
ˆR���ŒY‰×ÒÑÔÔ €Aàð Ø�$ˆwˆàˆr2   c                 óX  — t          | |¬¦  «        } t          j        | |dd¬¦  «        \  }}|j        j                             ¦   «         }t          j        t          j        |¦  «        d¬¦  «        }	|€dn|}|€.t          | j	        ¦  «        t          j
        |¦  «        j        z  n|}|dk     s|dk     rt          d¦  «        ‚||	|z  z   }
t          |¦  «        |
k    }d	||         z  }|dd…|f         }||z  |                     ¦   «         j        z  }|r|t          |¦  «        fS |S )
au  
    Compute the (Moore-Penrose) pseudo-inverse of a Hermitian matrix.

    Calculate a generalized inverse of a complex Hermitian/real symmetric
    matrix using its eigenvalue decomposition and including all eigenvalues
    with 'large' absolute value.

    Parameters
    ----------
    a : (N, N) array_like
        Real symmetric or complex hermetian matrix to be pseudo-inverted

    atol : float, optional
        Absolute threshold term, default value is 0.

        .. versionadded:: 1.7.0

    rtol : float, optional
        Relative threshold term, default value is ``N * eps`` where
        ``eps`` is the machine precision value of the datatype of ``a``.

        .. versionadded:: 1.7.0

    lower : bool, optional
        Whether the pertinent array data is taken from the lower or upper
        triangle of `a`. (Default: lower)
    return_rank : bool, optional
        If True, return the effective rank of the matrix.
    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
    -------
    B : (N, N) ndarray
        The pseudo-inverse of matrix `a`.
    rank : int
        The effective rank of the matrix.  Returned if `return_rank` is True.

    Raises
    ------
    LinAlgError
        If eigenvalue algorithm does not converge.

    See Also
    --------
    pinv : Moore-Penrose pseudoinverse of a matrix.

    Examples
    --------

    For a more detailed example see `pinv`.

    >>> import numpy as np
    >>> from scipy.linalg import pinvh
    >>> rng = np.random.default_rng()
    >>> a = rng.standard_normal((9, 6))
    >>> a = np.dot(a, a.T)
    >>> B = pinvh(a)
    >>> np.allclose(a, a @ B @ a)
    True
    >>> np.allclose(B, B @ a @ B)
    True

    rm   FÚev)rX   r[   rp  rƒ  r„  Nr†  rS  )r   r   Úeighr>   r²   rX   r<   r¾   r¼   r;   rö   r<  r+   r  rµ   r   )r@   r~  r  rX   r€  r[   ru  rˆ  rŠ  r‹  rŒ  Úabove_cutoffÚpsigma_diagr�  s                 r0   r#   r#   ‘  s+  € õJ 	˜1¨<Ð8Ñ8Ô8€AÝŒ<˜ °UÀ4ÐHÑHÔH�D€A€qØ	ŒŒ×ÒÑÔ€AÝŒ6•"”&˜‘)”) RÐ(Ñ(Ô(€Dà�ˆ2ˆ2 4€DØ.2¨l�3ˆqŒw‰<Œ<�"œ( 1™+œ+œ/Ñ)Ð)À€DàˆrŠ	ˆ	�t˜b’y�yÝÐAÑBÔBÐBà
�˜‘Ñ
€CÝ˜‘F”F˜S’L€Là˜˜,œÑ'€KØ	ˆ!ˆ!ˆ!ˆ\ˆ/Ô€Aà	
ˆ[‰˜AŸFšF™HœHœJÑ&€Aàð Ø•#�kÑ"Ô"Ð"Ð"àˆr2   )ÚArn   c                 ó  — t          j        t          | d¬¦  «        ¦  «        } t          j        | j        Ž st          d¦  «        ‚| j        dk    r¯t          t          j        d| j	        ¬¦  «        ¦  «        \  }}t          j
        | |j	        ¬¦  «        }|rJt          j        | t          | ¦  «        ¬¦  «        }t          j        t          | ¦  «        ¦  «        }	|||	ffS |t          j
        | |j	        ¬¦  «        fS t          d| f¦  «        }
 |
| |||¬	¦  «        \  }}}}}|dk     rt          d
| › d�¦  «        ‚t          j        |t          ¬¦  «        }|||dz   …         |||dz   …<   |                     t"          d¬¦  «        dz
  }| j        d         }t          j        |¦  «        }	||k     rIt%          ||dz   d…         ddd…         d¦  «        D ]$\  }}||z
  |k    rŒ|	||z
  |g         |	|||z
  g<   Œ%|dk    r3t%          |d|…         ¦  «        D ]\  }}||k    rŒ|	||g         |	||g<   Œ|r|||	ffS t          j
        |	¦  «        }t          j        |¦  «        ||	<   |t          j        |¦  «        |dd…f         fS )a#  
    Compute a diagonal similarity transformation for row/column balancing.

    The balancing tries to equalize the row and column 1-norms by applying
    a similarity transformation such that the magnitude variation of the
    matrix entries is reflected to the scaling matrices.

    Moreover, if enabled, the matrix is first permuted to isolate the upper
    triangular parts of the matrix and, again if scaling is also enabled,
    only the remaining subblocks are subjected to scaling.

    Parameters
    ----------
    A : (n, n) array_like
        Square data matrix for the balancing.
    permute : bool, optional
        The selector to define whether permutation of A is also performed
        prior to scaling.
    scale : bool, optional
        The selector to turn on and off the scaling. If False, the matrix
        will not be scaled.
    separate : bool, optional
        This switches from returning a full matrix of the transformation
        to a tuple of two separate 1-D permutation and scaling arrays.
    overwrite_a : bool, optional
        This is passed to xGEBAL directly. Essentially, overwrites the result
        to the data. It might increase the space efficiency. See LAPACK manual
        for details. This is False by default.

    Returns
    -------
    B : (n, n) ndarray
        Balanced matrix
    T : (n, n) ndarray
        A possibly permuted diagonal matrix whose nonzero entries are
        integer powers of 2 to avoid numerical truncation errors.
    scale, perm : (n,) ndarray
        If ``separate`` keyword is set to True then instead of the array
        ``T`` above, the scaling and the permutation vectors are given
        separately as a tuple without allocating the full array ``T``.

    Notes
    -----
    The balanced matrix satisfies the following equality

    .. math::
        B = T^{-1} A T

    The scaling coefficients are approximated to the nearest power of 2
    to avoid round-off errors.

    This algorithm is particularly useful for eigenvalue and matrix
    decompositions and in many cases it is already called by various
    LAPACK routines.

    The algorithm is based on the well-known technique of [1]_ and has
    been modified to account for special cases. See [2]_ for details
    which have been implemented since LAPACK v3.5.0. Before this version
    there are corner cases where balancing can actually worsen the
    conditioning. See [3]_ for such examples.

    The code is a wrapper around LAPACK's xGEBAL routine family for matrix
    balancing.

    .. versionadded:: 0.19.0

    References
    ----------
    .. [1] B.N. Parlett and C. Reinsch, "Balancing a Matrix for
       Calculation of Eigenvalues and Eigenvectors", Numerische Mathematik,
       Vol.13(4), 1969, :doi:`10.1007/BF02165404`
    .. [2] R. James, J. Langou, B.R. Lowery, "On matrix balancing and
       eigenvector computation", 2014, :arxiv:`1401.5766`
    .. [3] D.S. Watkins. A case where balancing is harmful.
       Electron. Trans. Numer. Anal, Vol.23, 2006.

    Examples
    --------
    >>> import numpy as np
    >>> from scipy import linalg
    >>> x = np.array([[1,2,0], [9,1,0.01], [1,2,10*np.pi]])

    >>> y, permscale = linalg.matrix_balance(x)
    >>> np.abs(x).sum(axis=0) / np.abs(x).sum(axis=1)
    array([ 3.66666667,  0.4995005 ,  0.91312162])

    >>> np.abs(y).sum(axis=0) / np.abs(y).sum(axis=1)
    array([ 1.2       ,  1.27041742,  0.92658316])  # may vary

    >>> permscale  # only powers of 2 (0.5 == 2^(-1))
    array([[  0.5,   0. ,  0. ],  # may vary
           [  0. ,   1. ,  0. ],
           [  0. ,   0. ,  1. ]])

    Trm   z/The data matrix for balancing should be square.r   rn   r�   ©r;   Úgebal)ÚscaleÚpermuterY   zHxGEBAL exited with the internal error "illegal value in argument number z8.". See LAPACK documentation for the xGEBAL error codes.r   Fró   Nr^   )r<   r   r   Úequalr;   r+   r~   r$   r¯   r>   r�   r>  r   r9  r	   Úfloatrë   ÚintrK   r»   )r“  r˜  r—  ÚseparaterY   Úb_nÚt_nr�  ÚscalingÚpermr–  ÚloÚhiÚpsr-   r,   r`  r‹   Úiperms                      r0   r$   r$   ï  sä  € õF 	ŒÕ(¨¸Ð>Ñ>Ô>Ñ?Ô?€AåŒ8�Q”WÐð LÝÐJÑKÔKÐKð 	„v�‚{€{Ý!¥"¤&¨°!´'Ð":Ñ":Ô":Ñ;Ô;‰ˆˆSÝŒM˜! 3¤9Ð-Ñ-Ô-ˆØð 	&Ý”l 1­C°©F¬FÐ3Ñ3Ô3ˆGÝ”9�S ™VœVÑ$Ô$ˆDØ�w �oÐ%Ð%Ø•"”- ¨¬Ð3Ñ3Ô3Ð3Ð3å˜g¨¨Ñ-Ô-€EØ˜% ¨¸Ø,7ð9ñ 9ô 9Ñ€A€rˆ2ˆr�4ð ˆa‚x€xÝð LØ?C¸eðLð Lð Lñ Mô Mð 	Mõ
 Œl˜2¥UÐ+Ñ+Ô+€GØ˜"˜R ™T˜'”{€GˆBˆr�!‰tˆGÑð 
�Š•3˜UˆÑ	#Ô	# aÑ	'€BØ	Œ�Œ
€AÝŒ9�Q‰<Œ<€Dð 
ˆA‚v€vÝ  2 a¡4 5 5¤	¨$¨$¨B¨$¤°Ñ3Ô3ð 	0ð 	0‰FˆC�Ø�‰u˜ŠzˆzØØ# Q s¡U¨A JÔ/ˆD�!�Q�s‘U�ÑÐà	ˆA‚v€vÝ  3 B 3¤Ñ(Ô(ð 	,ð 	,‰FˆC�Ø�aŠxˆxØØ! 3¨ (œ^ˆD�!�S�‰NˆNàð "Ø�7˜D�/Ð!Ð!õ ŒM˜$ÑÔ€EÝ”)˜A‘,”,€Eˆ$�Kà�bŒg�gÑÔ˜u a a a˜xÔ(Ð(Ð(r2   c                 óN  ‡
— t          | t          ¦  «        r(| \  }}t          ||¬¦  «        }t          ||¬¦  «        }n%t          | |¬¦  «        }|                     ¦   «         }|€t	          d¦  «        ‚t          ||¬¦  «        }|j        }|j        d         |j        d         k    }|r|s|j        d         |j        d         k    rt	          d¦  «        ‚t          j        |¦  «        p't          j        |¦  «        pt          j        |¦  «        }	|	rt          j        nt          j	        Š
ˆ
fd„|||fD ¦   «         \  }}}|j
        dk    r|s|                     dd¦  «        }n9|j
        dk    r.|                     |j        d         |j        dk    rdnd¦  «        }|||‰
|fS )	aè  Validate arguments and format inputs for toeplitz functions

    Parameters
    ----------
    c_or_cr : array_like or tuple of (array_like, array_like)
        The vector ``c``, or a tuple of arrays (``c``, ``r``). Whatever the
        actual shape of ``c``, it will be converted to a 1-D array. If not
        supplied, ``r = conjugate(c)`` is assumed; in this case, if c[0] is
        real, the Toeplitz matrix is Hermitian. r[0] is ignored; the first row
        of the Toeplitz matrix is ``[c[0], r[1:]]``. Whatever the actual shape
        of ``r``, it will be converted to a 1-D array.
    b : (M,) or (M, K) array_like
        Right-hand side in ``T x = b``.
    check_finite : bool
        Whether to check that the input matrices contain only finite numbers.
        Disabling may give a performance gain, but may result in problems
        (result entirely NaNs) if the inputs do contain infinities or NaNs.
    keep_b_shape : bool
        Whether to convert a (M,) dimensional b into a (M, 1) dimensional
        matrix.
    enforce_square : bool, optional
        If True (default), this verifies that the Toeplitz matrix is square.

    Returns
    -------
    r : array
        1d array corresponding to the first row of the Toeplitz matrix.
    c: array
        1d array corresponding to the first column of the Toeplitz matrix.
    b: array
        (M,), (M, 1) or (M, K) dimensional array, post validation,
        corresponding to ``b``.
    dtype: numpy datatype
        ``dtype`` stores the datatype of ``r``, ``c`` and ``b``. If any of
        ``r``, ``c`` or ``b`` are complex, ``dtype`` is ``np.complex128``,
        otherwise, it is ``np.float``.
    b_shape: tuple
        Shape of ``b`` after passing it through ``_asarray_validated``.

    rm   Nz`b` must be an array, not None.r   zIncompatible dimensions.c              3   óD   •K  — | ]}t          j        |‰¬ ¦  «        V — ŒdS )r�   N)r<   rZ  )rí   rS   r>   s     €r0   rï   z2_validate_args_for_toeplitz_ops.<locals>.<genexpr>É  s2   øè è € Ð=Ð=¨a�rŒz˜! 5Ð)Ñ)Ô)Ð=Ð=Ð=Ð=Ð=Ð=r2   r   r^   )r  r  r   r   r+   r;   r<   r±   rú   rì   ry   r-  r~   )r"  r„   r[   r%  Úenforce_squarer  r#  r.  Úis_not_squareÚis_cmplxr>   s             @r0   r*  r*  Š  s¨  ø€ õV �'�5Ñ!Ô!ð Ø‰ˆˆ1Ý˜q¨|Ð<Ñ<Ô<ˆÝ˜q¨|Ð<Ñ<Ô<ˆˆå˜w°\ÐBÑBÔBˆØ�KŠK‰MŒMˆà€yÝÐ:Ñ;Ô;Ð;å˜1¨<Ð8Ñ8Ô8€AØŒg€Gà”G˜A”J !¤'¨!¤*Ò,€MØð 5˜=ð 5¨Q¬W°Q¬Z¸1¼7À1¼:Ò-EÐ-EÝÐ3Ñ4Ô4Ð4åŒ˜qÑ!Ô!ÐM¥R¤_°QÑ%7Ô%7ÐM½2¼?È1Ñ;MÔ;M€HØ%Ð5�BŒMˆM­2¬:€EØ=Ð=Ð=Ð=°A°q¸!°9Ð=Ñ=Ô=�G€A€qˆ!à„v�‚{€{˜<€{Ø�IŠI�b˜!ÑÔˆˆØ	
Œ�1ŠˆØ�IŠI�a”g˜a”j¨¬°ª
¨
 " "¸Ñ:Ô:ˆàˆa��E˜7Ð"Ð"r2   c                 ó¨   — ddl m }m}m}m} t	          | t
          ¦  «        r| n| t          j        | ¦  «        f\  }}	t          |	||||||||¦	  «	        S )a|  Efficient Toeplitz Matrix-Matrix Multiplication using FFT

    This function returns the matrix multiplication between a Toeplitz
    matrix and a dense matrix.

    The Toeplitz matrix has constant diagonals, with c as its first column
    and r as its first row. If r is not given, ``r == conjugate(c)`` is
    assumed.

    The documentation is written assuming array arguments are of specified
    "core" shapes. However, array argument(s) of this function may have additional
    "batch" dimensions prepended to the core shape. In this case, the array is treated
    as a batch of lower-dimensional slices; see :ref:`linalg_batch` for details.

    Parameters
    ----------
    c_or_cr : array_like or tuple of (array_like, array_like)
        The vector ``c``, or a tuple of arrays (``c``, ``r``). If not
        supplied, ``r = conjugate(c)`` is assumed; in this case, if c[0] is
        real, the Toeplitz matrix is Hermitian. r[0] is ignored; the first row
        of the Toeplitz matrix is ``[c[0], r[1:]]``.
    x : (M,) or (M, K) array_like
        Matrix with which to multiply.
    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
        (result entirely NaNs) if the inputs do contain infinities or NaNs.
    workers : int, optional
        To pass to scipy.fft.fft and ifft. Maximum number of workers to use
        for parallel computation. If negative, the value wraps around from
        ``os.cpu_count()``. See scipy.fft.fft for more details.

    Returns
    -------
    T @ x : (M,) or (M, K) ndarray
        The result of the matrix multiplication ``T @ x``. Shape of return
        matches shape of `x`.

    See Also
    --------
    toeplitz : Toeplitz matrix
    solve_toeplitz : Solve a Toeplitz system using Levinson Recursion

    Notes
    -----
    The Toeplitz matrix is embedded in a circulant matrix and the FFT is used
    to efficiently calculate the matrix-matrix product.

    Because the computation is based on the FFT, integer inputs will
    result in floating point outputs.  This is unlike NumPy's `matmul`,
    which preserves the data type of the input.

    This is partly based on the implementation that can be found in [1]_,
    licensed under the MIT license. More information about the method can be
    found in reference [2]_. References [3]_ and [4]_ have more reference
    implementations in Python.

    .. versionadded:: 1.6.0

    References
    ----------
    .. [1] Jacob R Gardner, Geoff Pleiss, David Bindel, Kilian
       Q Weinberger, Andrew Gordon Wilson, "GPyTorch: Blackbox Matrix-Matrix
       Gaussian Process Inference with GPU Acceleration" with contributions
       from Max Balandat and Ruihan Wu. Available online:
       https://github.com/cornellius-gp/gpytorch

    .. [2] J. Demmel, P. Koev, and X. Li, "A Brief Survey of Direct Linear
       Solvers". In Z. Bai, J. Demmel, J. Dongarra, A. Ruhe, and H. van der
       Vorst, editors. Templates for the Solution of Algebraic Eigenvalue
       Problems: A Practical Guide. SIAM, Philadelphia, 2000. Available at:
       http://www.netlib.org/utk/people/JackDongarra/etemplates/node384.html

    .. [3] R. Scheibler, E. Bezzam, I. Dokmanic, Pyroomacoustics: A Python
       package for audio room simulations and array processing algorithms,
       Proc. IEEE ICASSP, Calgary, CA, 2018.
       https://github.com/LCAV/pyroomacoustics/blob/pypi-release/
       pyroomacoustics/adaptive/util.py

    .. [4] Marano S, Edwards B, Ferrari G and Fah D (2017), "Fitting
       Earthquake Spectra: Colored Noise and Incomplete Data", Bulletin of
       the Seismological Society of America., January, 2017. Vol. 107(1),
       pp. 276-291.

    Examples
    --------
    Multiply the Toeplitz matrix T with matrix x::

            [ 1 -1 -2 -3]       [1 10]
        T = [ 3  1 -1 -2]   x = [2 11]
            [ 6  3  1 -1]       [2 11]
            [10  6  3  1]       [5 19]

    To specify the Toeplitz matrix, only the first column and the first
    row are needed.

    >>> import numpy as np
    >>> c = np.array([1, 3, 6, 10])    # First column of T
    >>> r = np.array([1, -1, -2, -3])  # First row of T
    >>> x = np.array([[1, 10], [2, 11], [2, 11], [5, 19]])

    >>> from scipy.linalg import toeplitz, matmul_toeplitz
    >>> matmul_toeplitz((c, r), x)
    array([[-20., -80.],
           [ -7.,  -8.],
           [  9.,  85.],
           [ 33., 218.]])

    Check the result by creating the full Toeplitz matrix and
    multiplying it by ``x``.

    >>> toeplitz(c, r) @ x
    array([[-20, -80],
           [ -7,  -8],
           [  9,  85],
           [ 33, 218]])

    The full matrix is never formed explicitly, so this routine
    is suitable for very large Toeplitz matrices.

    >>> n = 1000000
    >>> matmul_toeplitz([1] + [0]*(n-1), np.ones(n))
    array([1., 1., 1., ..., 1., 1., 1.], shape=(1000000,))

    rn   )r:  r@  ÚrfftÚirfft)	r:  r@  r«  r¬  r  r  r<   r   Ú_matmul_toepltiz)
r"  r‹   r[   Úworkersr:  r@  r«  r¬  r  r#  s
             r0   r%   r%   Ó  sr   € ð~ -Ð,Ð,Ð,Ð,Ð,Ð,Ð,Ð,Ð,Ð,Ð,Ý  ­%Ñ0Ô0ÐVˆ7ˆ7°wÅÄÈWÑ@UÔ@UÐ6V�D€A€qå˜A˜q ! W¨l¸CÀÀtÈUÑSÔSÐSr2   )r‹   r�   c	                 óî  — t          || f||dd¬¦  «        \  } }}}	}
|j        \  }}t          |¦  «        }t          | ¦  «        }||z   dz
  }t          |
¦  «        dk    r|fn||f}|j        dk    rt	          j        ||¬¦  «        S t	          j        || ddd…         f¦  «        }t	          j        |¦  «        st	          j        |¦  «        rO ||d|¬¦  «                             dd¦  «        } |||d|¬¦  «        } |||z  d|¬¦  «        d |…d d …f         }nO ||d|¬¦  «                             dd¦  «        } |||d|¬¦  «        } |||z  d||¬	¦  «        d |…d d …f         } |j        |Ž S )
NF)r%  r§  r   r   r•  r^   )r2  r®  )r,   r2  r®  )r2  r®  r,   )	r*  r;   r   r~   r<   r�   r+  r±   r-  )r#  r  r‹   r®  r[   r:  r@  r«  r¬  r>   Úx_shaper,   rm  ÚT_nrowsÚT_ncolsÚpÚreturn_shapeÚembedded_colÚfft_matÚfft_xÚmat_times_xs                        r0   r­  r­  X	  så  € å=¸qÀ!¸fÀaÈØKPØMRðTñ Tô TÑ€A€qˆ!ˆU�Gð Œ7�D€A€qå�!‰fŒf€GÝ�!‰fŒf€GØ�'Ñ˜AÑ€AÝ!$ W¡¤°Ò!2Ð!2�G�:�:¸À!¸€Lð 	„v�‚{€{ÝŒ}˜Q lÐ3Ñ3Ô3Ð3å”> 1 a¨¨1¨R¨¤j /Ñ2Ô2€Lå	„�|Ñ$Ô$ð ?­¬¸Ñ(:Ô(:ð ?Ø�#�l¨°GÐ<Ñ<Ô<×DÒDÀRÈÑKÔKˆØ��A˜ ¨GÐ4Ñ4Ô4ˆà�d˜7 5™=¨qØ#*ð,ñ ,ô ,Ø,4¨W¨H°a°a°a¨Kô9ˆˆð �$�|¨!°WÐ=Ñ=Ô=×EÒEÀbÈ!ÑLÔLˆØ��Q˜! !¨WÐ5Ñ5Ô5ˆà�e˜G E™M°Ø$+¨qð2ñ 2ô 2Ø2:°7°(¸A¸A¸A°+ô?ˆð ˆ;Ô Ð-Ð-r2   r�   )FFFTNF)r   FFFT)r   FFF)FFT)FFFT)T)r5  Nr^   r   r   )FT)NFFTN)NNTFT)TTFF)FN)>rN   r   Ú	itertoolsr   Únumpyr<   r   r   Úscipy._lib._utilr   Úlapackr	   r
   r   r   Ú_miscr   r   r   r   r   Ú r   r!  r   Ú_cythonized_array_utilsr   r   r   r   r   Ú__all__r1   rD   rU   r   rv   r³   r´   r¸   r·   r¹   r¶   rx   r   rÀ   r   r  r   r   r4  r   r   r    r!   rh  r"   r#   r$   r*  r%   r­  r8  r2   r0   ú<module>rÁ     si  ðð €€€Ø Ð Ð Ð Ð Ð Ø Ð Ð Ð Ð Ð Ø Ð Ð Ð Ø (Ð (Ð (Ð (Ð (Ð (Ð (Ð (Ø .Ð .Ð .Ð .Ð .Ð .ðð ð ð ð ð ð ð ð ð ð ð ð ;Ð :Ð :Ð :Ð :Ð :Ð :Ð :Ð :Ð :Ø 'Ð 'Ð 'Ð 'Ð 'Ð 'Ø "Ð "Ð "Ð "Ð "Ð "Ð "Ð "Ø %Ð %Ð %Ð %Ð %Ð %ð3ð 3ð 3ð 3ð 3ð 3ð 3ð 3ð 3ð 3ð 3ð 3à Ð Ð Ð Ð Ð ðAð Að A€ð*ð *ð *ð *ð "ð "ð "ð,
ð 
ð 
ð< */Ø9=ØðMð Mð Mð Mð` Ð�8˜\Ñ*Ô*Ø*/Ø9=ØðPð Pð Pñ +Ô*ðPðfð ð ðð ð ðLð Lð Lð#ð #ð #ðð ð ð	ð 	ð 	ðAð Að Að Ð�8˜\Ñ*Ô*Ø?DØ59ðXð Xð Xñ +Ô*ðXðx CHØ"'ðPð Pð Pð Pð( BGØ"ðMMð MMð MMð MMð` Ð�= -°¸LÑIÔIð/Tð /Tñ JÔIð/Tðd Ð�8˜\Ñ*Ô*ØFKØ#ðIð Ið Iñ +Ô*ðIðXL2ð L2ð L2ð L2ð^ Ð�8˜X |Ñ4Ô4ðð ñ 5Ô4ðð0>ð >ð >ð 15Ø/0ðIð Ið Ið IðZz¸TÈð zð zð zð zð zð~zð zð zð zð| Ð�8˜\Ñ*Ô*Ø:?Ø+/ðH4ð H4ð H4ñ +Ô*ðH4ðV &€Ô ð Ð�8ÑÔØ˜t°ÀTð xð xð xð xñ Ôðxðv Ð�8ÑÔØ;@ØðZð Zð Zñ ÔðZðz Ð�8ÑÔØ9>Ø$ðW)ð W)ð W)ñ ÔðW)ðv 48ðF#ð F#ð F#ð F#ðRBTð BTð BTð BTðJ Ð�8˜X |Ñ4Ô4ð.ð .ñ 5Ô4ð.ð .ð .r2   