
\c           @   s   d  Z  d d l m Z d d l m Z e d d d d d d	  j   d
   Z d   Z d   Z d   Z	 d   Z
 d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d S(   sZ   
Fundamental operations of dense matrices.
The dense matrix is stored as a list of lists

i(   t   range(   t   SymPyDeprecationWarningt   featuret
   densetoolst   issuei1  t   deprecated_since_versions   1.1c         C   s<   | j  } x, t t |    D] } | |  | | 7} q W| S(   sT  
    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

    (   t   zeroR    t   len(   t   matlistt   Kt   resultt   i(    (    s8   lib/python2.7/site-packages/sympy/matrices/densetools.pyt   trace   s    	c         C   s#   g  t  |    D] } t |  ^ q S(   sG  
    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]]

    (   t   zipt   list(   R   R	   t   a(    (    s8   lib/python2.7/site-packages/sympy/matrices/densetools.pyt	   transpose)   s    c         C   s    g  |  D] } t  | |  ^ q S(   s~  
    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
    (   t   conjugate_row(   R   R	   t   row(    (    s8   lib/python2.7/site-packages/sympy/matrices/densetools.pyt	   conjugate=   s    c         C   sX   g  } xK |  D]C } t  | d d  } | d k	 r= |   } n | } | j |  q W| S(   s   
    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(   t   getattrt   Nonet   append(   R   R	   R
   t   rt   conjt   conjrow(    (    s8   lib/python2.7/site-packages/sympy/matrices/densetools.pyR   U   s    c         C   s   t  t |  |  |  S(   sd  
    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	   (    (    s8   lib/python2.7/site-packages/sympy/matrices/densetools.pyt   conjugate_transposen   s    c         C   s*   g  t  |  |  D] \ } } | | ^ q S(   s  
    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]]
    (   R   (   R   t   columnR	   R   t   element(    (    s8   lib/python2.7/site-packages/sympy/matrices/densetools.pyt   augment   s    c         C   s   g  } xr t  |   D]d } | j g   xN t  |   D]@ } | | k r_ | | j | d   q3 | | j | j  q3 Wq W| S(   s   
    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]]
    i   (   R    R   R   (   t   nR	   R
   R   t   j(    (    s8   lib/python2.7/site-packages/sympy/matrices/densetools.pyt   eye   s    c         C   s   |  | S(   s  
    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   (    (    s8   lib/python2.7/site-packages/sympy/matrices/densetools.pyR      s    c         C   sC   g  t  |    D] } t |  ^ q } g  | | D] } | g ^ q0 S(   sK  
    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]]
    (   R   R   (   R   R   t   lt   matcol(    (    s8   lib/python2.7/site-packages/sympy/matrices/densetools.pyt   col   s    %c         C   s!   |  | |  | |  | <|  | <|  S(   sC   
    Returns the matrix with index1 row and index2 row swapped
    (    (   R   t   index1t   index2R	   (    (    s8   lib/python2.7/site-packages/sympy/matrices/densetools.pyt   rowswap   s    c         C   s?   x8 t  t |  |   D]  } | |  | | |  | | <q W|  S(   s%   
    Multiplies index row with k
    (   R    R   (   R   t   indext   kR	   R   (    (    s8   lib/python2.7/site-packages/sympy/matrices/densetools.pyt   rowmul   s    c         C   sQ   g  } xD t  t |  |   D], } |  | | | |  | | |  | | <q W|  S(   sN   
    Adds the index1 row with index2 row which in turn is multiplied by k
    (   R    R   (   R   R$   R%   R(   R	   R
   R   (    (    s8   lib/python2.7/site-packages/sympy/matrices/densetools.pyt   rowadd   s    *c         C   s   t  |  |  |  k S(   sD  
    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	   (    (    s8   lib/python2.7/site-packages/sympy/matrices/densetools.pyt   isHermitian   s    N(   t   __doc__t   sympy.core.compatibilityR    t   sympy.utilities.exceptionsR   t   warnR   R   R   R   R   R   R    R   R#   R&   R)   R*   R+   (    (    (    s8   lib/python2.7/site-packages/sympy/matrices/densetools.pyt   <module>   s&   													
