o
    oh                     @   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 de
d	efd
dZdee
ef d	efddZde
d	efddZde
d	dfddZde
d	df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       | ]}|j V  qd S Nshape.0arg r   u/var/www/html/construction_image-detection-poc/venv/lib/python3.10/site-packages/sympy/matrices/expressions/_shape.py	<genexpr>        z"is_matadd_valid.<locals>.<genexpr>c                 s       | ]
\}}t ||V  qd S r   r   r   ijr   r   r   r   "       N   c                 s   r   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   =   s    z"is_matmul_valid.<locals>.<genexpr>c                 s   r   r   r   r   r   r   r   r   >   r   Nr   r   r   r!   r   r   r   is_matmul_valid'   s   (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r3td| dS )	z:Validate matrix shape for addition only for integer valuesc                 s   r   r   r   )r   xr   r   r   r   Z   r   z*validate_matadd_integer.<locals>.<genexpr>c                 S      t | ttfS r   r%   intr   r(   r   r   r   <lambda>[       z)validate_matadd_integer.<locals>.<lambda>r   z!Matrices have mismatching shape: c                 S   r)   r   r*   r,   r   r   r   r-   ]   r.   N)r    lensetfilterr	   r!   r   r   r   validate_matadd_integerX   s   r2   c                  G   sf   t | dd | dd D ]#\}}|j|j}}t|ttfr0t|ttfr0||kr0t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   "$r5   )sympy.core.relationalr   sympy.core.exprr   sympy.core.numbersr   sympy.logic.boolalgr   r   "sympy.matrices.expressions.matexprr   sympy.matrices.exceptionsr	   typingr
   r$   r&   r'   r2   r5   r   r   r   r   <module>   s    	