a
    ™¥»aY  ã                   @   s†   d Z g ZddlmZmZmZmZmZ ddlm	Z	 ddl
mZmZmZ ddddddddddddddddd	œZd
d„ Zdd„ Zdd„ ZdS )zrestructuredtext ené    )Ú
asanyarrayÚasarrayÚarrayÚmatrixÚzeros)Úasmatrix)ÚaslinearoperatorÚLinearOperatorÚIdentityOperatorÚfÚdÚFÚD))r   r   )r   r   )r   r   )r   r   )r   r   )r   r   )r   r   )r   r   )r   r   )r   r   )r   r   )r   r   )r   r   )r   r   )r   r   )r   r   c                 C   s$   | dvrd} |dvrd}t | |f S )NÚfdFDr   )Ú_coerce_rules)ÚxÚy© r   úZ/home/yuhw/wc/pochoir/venv/lib/python3.9/site-packages/scipy/sparse/linalg/isolve/utils.pyÚcoerce   s
    r   c                 C   s   | S ©Nr   ©r   r   r   r   Úid   s    r   c                    sÔ  | }t | ƒ} | jd | jd kr0td| jf ƒ‚| jd }tˆ ƒ‰ ˆ j|dfkspˆ j|fksptd | jˆ j¡ƒ‚ˆ jjdvr†ˆ  d¡‰ ‡ fdd„}t| d	ƒr¦| jj}n|  	ˆ ¡jj}t
|ˆ jjƒ}tˆ |d
�‰ ˆ  ¡ ‰ |du rìt||d
�}nFt||d
�}|j|dfk�s*|j|fk�s*td | j|j¡ƒ‚| ¡ }|du �r¨t|dƒ�rP|j}	nt}	t|dƒ�rh|j}
nt}
|	tu �r’|
tu �r’t| j| jd�}nt| j|	|
| jd�}nt |ƒ}| j|jk�rÆtdƒ‚| ||ˆ |fS )a8  Make a linear system Ax=b

    Parameters
    ----------
    A : LinearOperator
        sparse or dense matrix (or any valid input to aslinearoperator)
    M : {LinearOperator, Nones}
        preconditioner
        sparse or dense matrix (or any valid input to aslinearoperator)
    x0 : {array_like, None}
        initial guess to iterative method
    b : array_like
        right hand side

    Returns
    -------
    (A, M, x, b, postprocess)
        A : LinearOperator
            matrix of the linear system
        M : LinearOperator
            preconditioner
        x : rank 1 ndarray
            initial guess
        b : rank 1 ndarray
            right hand side
        postprocess : function
            converts the solution vector to the appropriate
            type and dimensions (e.g. (N,1) matrix)

    r   é   z(expected square matrix, but got shape=%sz(shapes of A {} and b {} are incompatibler   r   c                    s   t ˆ tƒrt| ƒ} |  ˆ j¡S r   )Ú
isinstancer   r   ZreshapeÚshaper   ©Úbr   r   ÚpostprocessP   s    
z make_system.<locals>.postprocessÚdtype)r   Nz)shapes of A {} and x0 {} are incompatibleÚpsolveÚrpsolve)r   r   )ÚmatvecZrmatvecr   z/matrix and preconditioner have different shapes)r   r   Ú
ValueErrorr   Úformatr   ÚcharZastypeÚhasattrr"   r   r   Zravelr   r   r    r   r!   r
   r	   )ÚAÚMZx0r   ZA_ÚNr   Zxtyper   r    r!   r   r   r   Úmake_system    sV    
ÿ


ÿ

ÿr*   N)Z__docformat__Ú__all__Únumpyr   r   r   r   r   Zscipy.sparse.sputilsr   Zscipy.sparse.linalg.interfacer   r	   r
   r   r   r   r*   r   r   r   r   Ú<module>   s   û