B
    [a                 @   s   d Z ddlmZ ddlmZ edddd  dd	 Zd
d Zdd Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd Zdd Zd d! Zd"S )#zZ
Fundamental operations of dense matrices.
The dense matrix is stored as a list of lists

    )range)SymPyDeprecationWarningZ
densetoolsi1  z1.1)ZfeatureZissueZdeprecated_since_versionc             C   s0   |j }x$tt| D ]}|| | | 7 }qW |S )aT  
    Returns the trace of a matrix.

    Examples
    ========

    >>> from sympy.matrices.densetools import trace, eye
    >>> from sympy import ZZ
    >>> a = [
    ... [ZZ(3), ZZ(7), ZZ(4)],
    ... [ZZ(2), ZZ(4), ZZ(5)],
    ... [ZZ(6), ZZ(2), ZZ(3)]]
    >>> b = eye(4, ZZ)
    >>> trace(a, ZZ)
    10
    >>> trace(b, ZZ)
    4

    )zeror   len)matlistKresulti r
   8lib/python3.7/site-packages/sympy/matrices/densetools.pytrace   s    r   c             C   s   dd t |  D S )aG  
    Returns the transpose of a matrix

    Examples
    ========

    >>> from sympy.matrices.densetools import transpose
    >>> from sympy import ZZ
    >>> a = [
    ... [ZZ(3), ZZ(7), ZZ(4)],
    ... [ZZ(2), ZZ(4), ZZ(5)],
    ... [ZZ(6), ZZ(2), ZZ(3)]]
    >>> transpose(a, ZZ)
    [[3, 2, 6], [7, 4, 2], [4, 5, 3]]

    c             S   s   g | ]}t |qS r
   )list).0ar
   r
   r   
<listcomp>:   s    ztranspose.<locals>.<listcomp>)zip)r   r   r
   r
   r   	transpose)   s    r   c                s    fdd| D S )a~  
    Returns the conjugate of a matrix row-wise.

    Examples
    ========

    >>> from sympy.matrices.densetools import conjugate
    >>> from sympy import ZZ
    >>> a = [
    ... [ZZ(3), ZZ(2), ZZ(6)],
    ... [ZZ(7), ZZ(4), ZZ(2)],
    ... [ZZ(4), ZZ(5), ZZ(3)]]
    >>> conjugate(a, ZZ)
    [[3, 2, 6], [7, 4, 2], [4, 5, 3]]

    See Also
    ========

    conjugate_row
    c                s   g | ]}t | qS r
   )conjugate_row)r   row)r   r
   r   r   R   s    zconjugate.<locals>.<listcomp>r
   )r   r   r
   )r   r   	conjugate=   s    r   c          	   C   sH   g }x>| D ]6}y| |  W q
 tk
r>   | | Y q
X q
W |S )z
    Returns the conjugate of a row element-wise

    Examples
    ========

    >>> from sympy.matrices.densetools import conjugate_row
    >>> from sympy import ZZ
    >>> a = [ZZ(3), ZZ(2), ZZ(6)]
    >>> conjugate_row(a, ZZ)
    [3, 2, 6]
    )appendr   AttributeError)r   r   r   rr
   r
   r   r   U   s    
r   c             C   s   t t| ||S )ad  
    Returns the conjugate-transpose of a matrix

    Examples
    ========

    >>> from sympy import ZZ
    >>> from sympy.matrices.densetools import conjugate_transpose
    >>> a = [
    ... [ZZ(3), ZZ(7), ZZ(4)],
    ... [ZZ(2), ZZ(4), ZZ(5)],
    ... [ZZ(6), ZZ(2), ZZ(3)]]
    >>> conjugate_transpose(a, ZZ)
    [[3, 2, 6], [7, 4, 2], [4, 5, 3]]
    )r   r   )r   r   r
   r
   r   conjugate_transposek   s    r   c             C   s   dd t | |D S )a  
    Augments a matrix and a column.

    Examples
    ========

    >>> from sympy.matrices.densetools import augment
    >>> from sympy import ZZ
    >>> a = [
    ... [ZZ(3), ZZ(7), ZZ(4)],
    ... [ZZ(2), ZZ(4), ZZ(5)],
    ... [ZZ(6), ZZ(2), ZZ(3)]]
    >>> b = [
    ... [ZZ(4)],
    ... [ZZ(5)],
    ... [ZZ(6)]]
    >>> augment(a, b, ZZ)
    [[3, 7, 4, 4], [2, 4, 5, 5], [6, 2, 3, 6]]
    c             S   s   g | ]\}}|| qS r
   r
   )r   r   elementr
   r
   r   r      s    zaugment.<locals>.<listcomp>)r   )r   columnr   r
   r
   r   augment~   s    r   c             C   sb   g }xXt | D ]L}|g  x<t | D ]0}||krF|| |d q&|| |j q&W qW |S )z
    Returns an identity matrix of size n.

    Examples
    ========

    >>> from sympy.matrices.densetools import eye
    >>> from sympy import ZZ
    >>> eye(3, ZZ)
    [[1, 0, 0], [0, 1, 0], [0, 0, 1]]
       )r   r   r   )nr   r   r	   jr
   r
   r   eye   s    
r    c             C   s   | | S )a  
    Returns the ith row of a matrix

    Examples
    ========

    >>> from sympy.matrices.densetools import row
    >>> from sympy import ZZ
    >>> a = [
    ... [ZZ(3), ZZ(7), ZZ(4)],
    ... [ZZ(2), ZZ(4), ZZ(5)],
    ... [ZZ(6), ZZ(2), ZZ(3)]]
    >>> row(a, 2)
    [6, 2, 3]
    r
   )r   r	   r
   r
   r   r      s    r   c             C   s$   dd t |  D }dd || D S )aK  
    Returns the ith column of a matrix
    Note: Currently very expensive

    Examples
    ========

    >>> from sympy.matrices.densetools import col
    >>> from sympy import ZZ
    >>> a = [
    ... [ZZ(3), ZZ(7), ZZ(4)],
    ... [ZZ(2), ZZ(4), ZZ(5)],
    ... [ZZ(6), ZZ(2), ZZ(3)]]
    >>> col(a, 1)
    [[7], [4], [2]]
    c             S   s   g | ]}t |qS r
   )r   )r   lr
   r
   r   r      s    zcol.<locals>.<listcomp>c             S   s   g | ]
}|gqS r
   r
   )r   r!   r
   r
   r   r      s    )r   )r   r	   Zmatcolr
   r
   r   col   s    r"   c             C   s   | | | |  | |< | |< | S )zC
    Returns the matrix with index1 row and index2 row swapped
    r
   )r   index1index2r   r
   r
   r   rowswap   s    r%   c             C   s6   x0t t| | D ]}|| | |  | | |< qW | S )z%
    Multiplies index row with k
    )r   r   )r   indexkr   r	   r
   r
   r   rowmul   s    r(   c             C   sF   g }x<t t| | D ](}| | | || | |   | | |< qW | S )zN
    Adds the index1 row with index2 row which in turn is multiplied by k
    )r   r   )r   r#   r$   r'   r   r   r	   r
   r
   r   rowadd   s    (r)   c             C   s   t | || kS )aD  
    Checks whether matrix is hermitian

    Examples
    ========

    >>> from sympy.matrices.densetools import isHermitian
    >>> from sympy import QQ
    >>> a = [
    ... [QQ(2,1), QQ(-1,1), QQ(-1,1)],
    ... [QQ(0,1), QQ(4,1), QQ(-1,1)],
    ... [QQ(0,1), QQ(0,1), QQ(3,1)]]
    >>> isHermitian(a, QQ)
    False
    )r   )r   r   r
   r
   r   isHermitian   s    r*   N)__doc__Zsympy.core.compatibilityr   Zsympy.utilities.exceptionsr   warnr   r   r   r   r   r   r    r   r"   r%   r(   r)   r*   r
   r
   r
   r   <module>   s&   	
