o
    tBh                     @   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 i ddddd	d
ddddddddd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)fr   r   )r   dr   )r   Fr   )r   Dr   )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   x/var/www/html/riverr-enterprise-integrations-main/venv/lib/python3.10/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rtd| jf | jd }t   j|dfks8 j|fks8td| j j jjdvrC d  fdd}t| d	rS| jj}n| 	 jj}t
| jj}t |d
    |du rt|drx|j}nt}t|dr|j}	nt}	|tu r|	tu rt| j| jd}nt| j||	| jd}nt |}| j|jkrtd|du rt||d
}
n7t|tr|dkr̈  }|	|}
n$t||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=%sz(shapes of A {} and b {} are incompatibler   r   c                    s   t  tr	t| } |  jS r   )
isinstancer   r   reshapeshaper   br   r   postprocessR   s   
z make_system.<locals>.postprocessdtype)r    Npsolverpsolve)r   r    )matvecrmatvecr    z/matrix and preconditioner have different shapesMbzshapes of A z and x0 z are incompatible)r   r   
ValueErrorr   formatr    charastypehasattrr#   r   r   ravelr!   r   r"   r
   r	   r   r   strcopyr   )AMx0r   A_Nr   xtyper!   r"   r   bCopyr   r   r   make_system    s`   !









r5   N)__docformat____all__numpyr   r   r   r   r   scipy.sparse._sputilsr   scipy.sparse.linalg._interfacer   r	   r
   r   r   r   r5   r   r   r   r   <module>   sF    