U
    Gvf                     @   sv   d Z g ZddlmZmZmZ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zeros)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krd} |dkrd}t | |f S )NfdFDr
   )_coerce_rules)xy r   E/tmp/pip-unpacked-wheel-96ln3f52/scipy/sparse/linalg/_isolve/utils.pycoerce   s
    r   c                 C   s   | S Nr   r   r   r   r   id   s    r   c                 C   s  | }t | } | jd | jd kr2td| jf | jd }t|}|j|dfksx|j|fksxtd| j d|j d|jjdkr|d}d	d
 }t| dr| jj}n| |jj}t	||jj}t
||d}| }|dkrNt|dr|j}nt}t|dr|j}	nt}	|tkr8|	tkr8t| j| jd}nt| j||	| jd}nt |}| j|jkrltd|dkrt||d}
nvt|tr|dkr| }||}
nLt||d}
|
j|dfks|
j|fkstd| j d|
j d|
 }
| ||
||fS )a  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, str, None}
        initial guess to iterative method.
        ``x0 = 'Mb'`` means using the nonzero initial guess ``M @ b``.
        Default is `None`, which means using the zero initial guess.
    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=zshapes of A z and b z are incompatibler   r
   c                 S   s   | S r   r   r   r   r   r   postprocessQ   s    z make_system.<locals>.postprocessdtype)r   Npsolverpsolve)shaper   )matvecZrmatvecr   z/matrix and preconditioner have different shapesZMbz and x0 )r   r   
ValueErrorr   r   charZastypehasattrr   r   r   Zravelr   r   r   r   r   r   
isinstancestrcopyr   )AMZx0bZA_Nr   Zxtyper   r   r   ZbCopyr   r   r   make_system   sV    !








r(   N)Z__docformat____all__Znumpyr   r   r   r   Zscipy.sparse.linalg._interfacer   r   r   r   r   r   r(   r   r   r   r   <module>   s*           