a
    kh                     @   s   d dl mZ d dlmZ d dlmZ d dlmZmZ d dl	m
Z
 d dlmZ d dlmZ e
edd	d
Zee
ef edddZe
edddZe
ddddZe
ddddZdS )    Eq)Expr)Integer)BooleanAnd)
MatrixExpr)
ShapeError)Union)argsreturnc                  G   sh   t dd | D  \}}tg dd t |dd |dd D dd t |dd |dd D R  S )a  Return the symbolic condition how ``MatAdd``, ``HadamardProduct``
    makes sense.

    Parameters
    ==========

    args
        The list of arguments of matrices to be tested for.

    Examples
    ========

    >>> from sympy import MatrixSymbol, symbols
    >>> from sympy.matrices.expressions._shape import is_matadd_valid

    >>> m, n, p, q = symbols('m n p q')
    >>> A = MatrixSymbol('A', m, n)
    >>> B = MatrixSymbol('B', p, q)
    >>> is_matadd_valid(A, B)
    Eq(m, p) & Eq(n, q)
    c                 s   s   | ]}|j V  qd S Nshape.0arg r   O/var/www/auris/lib/python3.9/site-packages/sympy/matrices/expressions/_shape.py	<genexpr>        z"is_matadd_valid.<locals>.<genexpr>c                 s   s   | ]\}}t ||V  qd S r   r   r   ijr   r   r   r   "   r   N   c                 s   s   | ]\}}t ||V  qd S r   r   r   r   r   r   r   #   r   zipr   r   rowscolsr   r   r   is_matadd_valid
   s    ""r!   c                  G   s>   t dd | D  \}}tdd t |dd |dd D  S )a  Return the symbolic condition how ``MatMul`` makes sense

    Parameters
    ==========

    args
        The list of arguments of matrices and scalar expressions to be tested
        for.

    Examples
    ========

    >>> from sympy import MatrixSymbol, symbols
    >>> from sympy.matrices.expressions._shape import is_matmul_valid

    >>> m, n, p, q = symbols('m n p q')
    >>> A = MatrixSymbol('A', m, n)
    >>> B = MatrixSymbol('B', p, q)
    >>> is_matmul_valid(A, B)
    Eq(n, p)
    c                 s   s   | ]}t |tr|jV  qd S r   )
isinstancer   r   r   r   r   r   r   =   r   z"is_matmul_valid.<locals>.<genexpr>c                 s   s   | ]\}}t ||V  qd S r   r   r   r   r   r   r   >   r   Nr   r   r   r   r   r   r   is_matmul_valid'   s    r#   )r   r   c                C   s   t | j| jS )a  Return the symbolic condition how the matrix is assumed to be square

    Parameters
    ==========

    arg
        The matrix to be tested for.

    Examples
    ========

    >>> from sympy import MatrixSymbol, symbols
    >>> from sympy.matrices.expressions._shape import is_square

    >>> m, n = symbols('m n')
    >>> A = MatrixSymbol('A', m, n)
    >>> is_square(A)
    Eq(m, n)
    )r   r   r    )r   r   r   r   	is_squareA   s    r$   Nc                  G   sj   t dd | D  \}}tttdd |dkr>td| tttdd |dkrftd| dS )	z:Validate matrix shape for addition only for integer valuesc                 s   s   | ]}|j V  qd S r   r   )r   xr   r   r   r   Z   r   z*validate_matadd_integer.<locals>.<genexpr>c                 S   s   t | ttfS r   r"   intr   r%   r   r   r   <lambda>[   r   z)validate_matadd_integer.<locals>.<lambda>r   z!Matrices have mismatching shape: c                 S   s   t | ttfS r   r&   r(   r   r   r   r)   ]   r   N)r   lensetfilterr	   r   r   r   r   validate_matadd_integerX   s
    r-   c                  G   sf   t | dd | dd D ]F\}}|j|j }}t|ttfrt|ttfr||krtd||qdS )z@Validate matrix shape for multiplication only for integer valuesNr   r   zMatrices are not aligned)r   r    r   r"   r'   r   r	   )r   ABr   r   r   r   r   validate_matmul_integera   s    "$r0   )Zsympy.core.relationalr   Zsympy.core.exprr   Zsympy.core.numbersr   Zsympy.logic.boolalgr   r   Z"sympy.matrices.expressions.matexprr   Zsympy.matrices.exceptionsr	   typingr
   r!   r#   r$   r-   r0   r   r   r   r   <module>   s   	