B
    ˜‘[‹	  ã               @   sŽ   d dl mZmZ d dlmZmZ d dlmZmZm	Z	m
Z
mZ d dlmZmZ dd„ ZG dd„ deƒZd	d
„ ZeefZe
e	dd„ eeŽ ƒƒZdS )é    )Úprint_functionÚdivision)ÚMulÚsympify)ÚunpackÚflattenÚ	conditionÚexhaustÚdo_one)Ú
MatrixExprÚ
ShapeErrorc              G   s8   | st dƒ‚t| Ž  t| ƒdkr(| d S t| Ž  ¡ S dS )am  
    Return the elementwise (aka Hadamard) product of matrices.

    Examples
    ========

    >>> from sympy.matrices import hadamard_product, MatrixSymbol
    >>> A = MatrixSymbol('A', 2, 3)
    >>> B = MatrixSymbol('B', 2, 3)
    >>> hadamard_product(A)
    A
    >>> hadamard_product(A, B)
    A.*B
    >>> hadamard_product(A, B)[0, 1]
    A[0, 1]*B[0, 1]
    z#Empty Hadamard product is undefinedé   r   N)Ú	TypeErrorÚvalidateÚlenÚHadamardProductÚdoit)Zmatrices© r   úBlib/python3.7/site-packages/sympy/matrices/expressions/hadamard.pyÚhadamard_product   s    r   c                   sH   e Zd ZdZdZ‡ fdd„Zedd„ ƒZdd„ Zd	d
„ Z	dd„ Z
‡  ZS )r   a¼  
    Elementwise product of matrix expressions

    This is a symbolic object that simply stores its argument without
    evaluating it. To actually compute the product, use the function
    ``hadamard_product()``.

    >>> from sympy.matrices import hadamard_product, HadamardProduct, MatrixSymbol
    >>> A = MatrixSymbol('A', 5, 5)
    >>> B = MatrixSymbol('B', 5, 5)
    >>> isinstance(hadamard_product(A, B), HadamardProduct)
    True
    Tc                s<   t tt|ƒƒ}| dd¡}|r&t|Ž  tt| ƒj| f|žŽ S )NÚcheckT)ÚlistÚmapr   Úgetr   Úsuperr   Ú__new__)ÚclsÚargsÚkwargsr   )Ú	__class__r   r   r   2   s
    zHadamardProduct.__new__c             C   s   | j d jS )Nr   )r   Úshape)Úselfr   r   r   r    9   s    zHadamardProduct.shapec                s   t ‡ ‡fdd„| jD ƒŽ S )Nc                s   g | ]}|  ˆ ˆ¡‘qS r   )Ú_entry)Ú.0Úarg)ÚiÚjr   r   ú
<listcomp>>   s    z*HadamardProduct._entry.<locals>.<listcomp>)r   r   )r!   r%   r&   r   )r%   r&   r   r"   =   s    zHadamardProduct._entryc             C   s    ddl m} ttt|| jƒƒŽ S )Nr   )Ú	transpose)Z$sympy.matrices.expressions.transposer(   r   r   r   r   )r!   r(   r   r   r   Ú_eval_transpose@   s    zHadamardProduct._eval_transposec             K   s   t | ƒS )N)Úcanonicalize)r!   Zignoredr   r   r   r   D   s    zHadamardProduct.doit)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Zis_HadamardProductr   Úpropertyr    r"   r)   r   Ú__classcell__r   r   )r   r   r   "   s   r   c              G   sX   t dd„ | D ƒƒstdƒ‚| d }x0| dd … D ] }|j|jkr0td||f ƒ‚q0W d S )Nc             s   s   | ]}|j V  qd S )N)Z	is_Matrix)r#   r$   r   r   r   ú	<genexpr>H   s    zvalidate.<locals>.<genexpr>z Mix of Matrix and Scalar symbolsr   r   z"Matrices %s and %s are not aligned)Úallr   r    r   )r   ÚAÚBr   r   r   r   G   s    r   c             C   s
   t | tƒS )N)Ú
isinstancer   )Úxr   r   r   Ú<lambda>R   s    r7   N)Z
__future__r   r   Z
sympy.corer   r   Zsympy.strategiesr   r   r   r	   r
   Z"sympy.matrices.expressions.matexprr   r   r   r   r   Zrulesr*   r   r   r   r   Ú<module>   s   %
