B
    [                 @   sL   d dl mZ d dlmZ d dlmZ d dlmZ G dd deZe Z	Z
dS )    )print_function)MutableDenseMatrix)Poly)EXc               @   s@   e Zd ZdZdZedd Zdd Zdd Zd	d
 Z	dd Z
dS )MutablePolyDenseMatrixa  
    A mutable matrix of objects from poly module or to operate with them.

    >>> from sympy.polys.polymatrix import PolyMatrix
    >>> from sympy import Symbol, Poly, ZZ
    >>> x = Symbol('x')
    >>> pm1 = PolyMatrix([[Poly(x**2, x), Poly(-x, x)], [Poly(x**3, x), Poly(-1 + x, x)]])
    >>> v1 = PolyMatrix([[1, 0], [-1, 0]])
    >>> pm1*v1
    Matrix([
    [    Poly(x**2 + x, x, domain='ZZ'), Poly(0, x, domain='ZZ')],
    [Poly(x**3 - x + 1, x, domain='ZZ'), Poly(0, x, domain='ZZ')]])

    >>> pm1.ring
    ZZ[x]

    >>> v1*pm1
    Matrix([
    [ Poly(x**2, x, domain='ZZ'), Poly(-x, x, domain='ZZ')],
    [Poly(-x**2, x, domain='ZZ'),  Poly(x, x, domain='ZZ')]])

    >>> pm2 = PolyMatrix([[Poly(x**2, x, domain='QQ'), Poly(0, x, domain='QQ'), Poly(1, x, domain='QQ'),             Poly(x**3, x, domain='QQ'), Poly(0, x, domain='QQ'), Poly(-x**3, x, domain='QQ')]])
    >>> v2 = PolyMatrix([1, 0, 0, 0, 0, 0], ring=ZZ)
    >>> v2.ring
    ZZ
    >>> pm2*v2
    Matrix([[Poly(x**2, x, domain='QQ')]])

    
   c             C   s   | S )N )xr   r   5lib/python3.7/site-packages/sympy/polys/polymatrix.py<lambda>*   s    zMutablePolyDenseMatrix.<lambda>c             O   sr   | dt}tdd | jD rh| jrhtdd | jD }|d }x$tdt|D ]}||| }qRW || _d S )Nringc             s   s   | ]}t |tV  qd S )N)
isinstancer   ).0pr   r   r
   	<genexpr>0   s    z2MutablePolyDenseMatrix.__init__.<locals>.<genexpr>c             S   s   g | ]}|j |j qS r   )domaingens)r   r   r   r   r
   
<listcomp>1   s    z3MutablePolyDenseMatrix.__init__.<locals>.<listcomp>r      )	getr   all_mattuplerangelenZunifyr   )selfargskwargsr   r   ir   r   r
   __init__,   s    zMutablePolyDenseMatrix.__init__c                s   | j | j }}|j |j }}|| }| j }|j}dg| | }	| jdkr|j dkr| j |jxntt|	D ]^}
|
| |
|  }}t|| ||d  }t|||} fddt||D }t||	|
< qlW | j|||	ddS )Nr   r   c             3   s"   | ]\}} | |  V  qd S )Nr   )r   ab)mat	other_matr   r
   r   G   s    z:MutablePolyDenseMatrix._eval_matrix_mul.<locals>.<genexpr>F)copy)rowscolsr   r   r   zipsum	__class__)r   otherZ	self_rowsZ	self_colsZ
other_rowsZ
other_colsZ	other_lenZnew_mat_rowsZnew_mat_colsZnew_matr   rowcolZrow_indicesZcol_indicesZvecr   )r"   r#   r
   _eval_matrix_mul7   s     z'MutablePolyDenseMatrix._eval_matrix_mulc                s*    fdd| j D }| j| j| j|ddS )Nc                s6   g | ].}t |tr*t|   f|j n|  qS r   )r   r   as_exprr   )r   r    )r*   r   r
   r   N   s    z;MutablePolyDenseMatrix._eval_scalar_mul.<locals>.<listcomp>F)r$   )r   r)   r%   r&   )r   r*   r"   r   )r*   r
   _eval_scalar_mulM   s    z'MutablePolyDenseMatrix._eval_scalar_mulc                s*    fdd| j D }| j| j| j|ddS )Nc                s6   g | ].}t |tr*t |  f|j n | qS r   )r   r   r.   r   )r   r    )r*   r   r
   r   R   s    z<MutablePolyDenseMatrix._eval_scalar_rmul.<locals>.<listcomp>F)r$   )r   r)   r%   r&   )r   r*   r"   r   )r*   r
   _eval_scalar_rmulQ   s    z(MutablePolyDenseMatrix._eval_scalar_rmulN)__name__
__module____qualname____doc__Z_class_prioritystaticmethodZ_sympifyr   r-   r/   r0   r   r   r   r
   r   	   s   r   N)Z
__future__r   Zsympy.matrices.denser   Zsympy.polys.polytoolsr   Zsympy.polys.domainsr   r   ZMutablePolyMatrixZ
PolyMatrixr   r   r   r
   <module>   s
   M