o
    8Vaa                     @   s   d 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

    )SymPyDeprecationWarningZ
densetoolsi1  z1.1)ZfeatureZissueZdeprecated_since_versionc                 C   s,   |j }tt| D ]
}|| | | 7 }q	|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

    )zerorangelen)matlistKresulti r
   ;/usr/lib/python3/dist-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      g | ]}t |qS r
   list).0ar
   r
   r   
<listcomp>9       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   Q   s    zconjugate.<locals>.<listcomp>r
   r   r
   r   r   	conjugate<   s   r   c                 C   s<   g }| D ]}t |dd}|dur| }n|}|| q|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]
    r   N)getattrappend)r   r   r   rZconjZconjrowr
   r
   r   r   T   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   conjugate_transposem   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   sZ   g }t | D ]$}|g  t | D ]}||kr!|| |d q|| |j qq|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   r   r
   r   r   lr
   r
   r   r      r   zcol.<locals>.<listcomp>c                 S   s   g | ]}|gqS 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   s2   t t| | D ]}|| | |  | | |< q| S )z%
    Multiplies index row with k
    r   r   )r   indexkr   r	   r
   r
   r   rowmul   s   r0   c                 C   s>   t t| | D ]}| | | || | |   | | |< q| 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   rowadd   s   &r1   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   isHermitian   s   r2   N)__doc__Zsympy.utilities.exceptionsr   warnr   r   r   r   r   r"   r&   r   r)   r,   r0   r1   r2   r
   r
   r
   r   <module>   s*    		