o
    ohs                     @   s$  d dl mZ d dlmZ d dlmZ d dlmZm	Z	m
Z
 d dlmZmZ d dlmZmZ d dlmZ d dlmZmZmZmZ d d	lmZ d d
lmZ d dlmZ d dlmZ d dl m!Z! d dl"m#Z#m$Z$ ddl%m&Z&m'Z'm(Z( ddl)m*Z*m+Z+ ddl,m-Z- G dd de+Z.G dd de.Z/dd Z0dS )    )defaultdict)index)Expr)Kind
NumberKindUndefinedKind)IntegerRational)_sympifySympifyError)S)ZZQQGFEXRAW)DomainMatrix)DMNonInvertibleMatrixError)CoercionFailed)sympy_deprecation_warning)is_sequence)
filldedentas_int   )
ShapeErrorNonSquareMatrixErrorNonInvertibleMatrixError)classof
MatrixBase)
MatrixKindc                   @   sh  e Zd ZU dZeed< dd ZdOddZedd	 Z	ed
d Z
edd Zedd Zdd Zdd Zdd Zedd Zdd Zdd Zdd Zdd Zed efd!d"Zd#d$ Zd%d& Zd'd( Zd)d* Zd+d, Zd-d. Zd/d0 Zd1d2 Zed3d4 Z ed5d6 Z!d7d8 Z"d9d: Z#d;d< Z$d=d> Z%d?d@ Z&dAdB Z'dCdD Z(dPdFdGZ)dHdI Z*dQdKdLZ+dQdMdNZ,dS )R	RepMatrixa<  Matrix implementation based on DomainMatrix as an internal representation.

    The RepMatrix class is a superclass for Matrix, ImmutableMatrix,
    SparseMatrix and ImmutableSparseMatrix which are the main usable matrix
    classes in SymPy. Most methods on this class are simply forwarded to
    DomainMatrix.
    _repc                 C   sJ   t |tszt|}W n ty   t Y S w t |tstS | j|jS N)
isinstancer   r
   r   NotImplementedr    unify_eqselfother r(   l/var/www/html/construction_image-detection-poc/venv/lib/python3.10/site-packages/sympy/matrices/repmatrix.py__eq__5   s   

zRepMatrix.__eq__Nc                 K   s   |dur|r
t d| j|S | j}|j}|s5|jr| S |jr5z|tW S  ty4   Y | S w |j	di |}|jj
rF|t}|S )aG  Convert to a :class:`~.DomainMatrix`.

        Examples
        ========

        >>> from sympy import Matrix
        >>> M = Matrix([[1, 2], [3, 4]])
        >>> M.to_DM()
        DomainMatrix({0: {0: 1, 1: 2}, 1: {0: 3, 1: 4}}, (2, 2), ZZ)

        The :meth:`DomainMatrix.to_Matrix` method can be used to convert back:

        >>> M.to_DM().to_Matrix() == M
        True

        The domain can be given explicitly or otherwise it will be chosen by
        :func:`construct_domain`. Any keyword arguments (besides ``domain``)
        are passed to :func:`construct_domain`:

        >>> from sympy import QQ, symbols
        >>> x = symbols('x')
        >>> M = Matrix([[x, 1], [1, x]])
        >>> M
        Matrix([
        [x, 1],
        [1, x]])
        >>> M.to_DM().domain
        ZZ[x]
        >>> M.to_DM(field=True).domain
        ZZ(x)
        >>> M.to_DM(domain=QQ[x]).domain
        QQ[x]

        See Also
        ========

        DomainMatrix
        DomainMatrix.to_Matrix
        DomainMatrix.convert_to
        DomainMatrix.choose_domain
        construct_domain
        Nz,Options cannot be used with domain parameterr(   )	TypeErrorr    
convert_todomainis_ZZcopyis_QQr   r   choose_domainis_EXr   )r&   r-   kwargsrepdomrep_domr(   r(   r)   to_DMA   s(   +
zRepMatrix.to_DMc                 C   s   |j }t|}|tkr-|jr|}n|jrt}nt}||kr$||}|}|tkr-||}|tkr>t|t	s>t
ddddd ||fS )N+  
                non-Expr objects in a Matrix is deprecated. Matrix represents
                a mathematical matrix. To represent a container of non-numeric
                entities, Use a list of lists, TableForm, NumPy array, or some
                other data structure instead.
                1.9deprecated-non-expr-in-matrix   deprecated_since_versionactive_deprecations_target
stacklevel)r-   r
   r   
is_Integeris_Rationalr   r,   
from_sympyr"   r   r   )clsr4   elementr-   
new_domainr(   r(   r)   _unify_element_sympy   s*   

zRepMatrix._unify_element_sympyc                 C   sr   t dd |D stddddd t|||ft}t dd |D r7t d	d |D r2|t}|S |t}|S )
Nc                 s       | ]}t |tV  qd S r!   )
issubclassr   .0typr(   r(   r)   	<genexpr>       z1RepMatrix._dod_to_DomainMatrix.<locals>.<genexpr>r8   r9   r:      r<   c                 s   rG   r!   )rH   r	   rI   r(   r(   r)   rL      rM   c                 s   rG   r!   )rH   r   rI   r(   r(   r)   rL      rM   )allr   r   r   r,   r   r   )rC   rowscolsdodtypesr4   r(   r(   r)   _dod_to_DomainMatrix   s   

zRepMatrix._dod_to_DomainMatrixc                 C   s^   t t}t|D ]\}}|dkrt||\}}||| |< qttt|}	| ||||	}
|
S Nr   )r   dict	enumeratedivmodsetmaptyperT   )rC   rP   rQ   	flat_listelements_dodnrD   ijrS   r4   r(   r(   r)   _flat_list_to_DomainMatrix   s   z$RepMatrix._flat_list_to_DomainMatrixc           
      C   sX   t t}| D ]\\}}}|dkr||| |< qttt| }| ||||}	|	S rU   )r   rV   itemsrY   rZ   r[   valuesrT   )
rC   rP   rQ   smatr]   r_   r`   rD   rS   r4   r(   r(   r)   _smat_to_DomainMatrix   s   zRepMatrix._smat_to_DomainMatrixc                 C      | j   S r!   )r    to_sympyto_list_flatr&   r(   r(   r)   flat      zRepMatrix.flatc                 C   rf   r!   )r    rg   to_listri   r(   r(   r)   _eval_tolist   rk   zRepMatrix._eval_tolistc                 C   rf   r!   )r    rg   to_dokri   r(   r(   r)   _eval_todok   rk   zRepMatrix._eval_todokc                 C   s   |  | |||S r!   )_fromrepre   )rC   rP   rQ   dokr(   r(   r)   _eval_from_dok   s   zRepMatrix._eval_from_dokc                 C   s   t |  S r!   )list_eval_iter_valuesri   r(   r(   r)   _eval_values   s   zRepMatrix._eval_valuesc                 C   s*   | j }|j}| }|jst|j|}|S r!   )r    r-   iter_valuesis_EXRAWrZ   rg   )r&   r4   Krc   r(   r(   r)   rt      s   zRepMatrix._eval_iter_valuesc                    s6   | j }|j}|j | }|js fdd|D }|S )Nc                 3   s     | ]\}}| |fV  qd S r!   r(   )rJ   r_   vrg   r(   r)   rL   
      z-RepMatrix._eval_iter_items.<locals>.<genexpr>)r    r-   rg   
iter_itemsrw   )r&   r4   rx   rb   r(   rz   r)   _eval_iter_items  s   zRepMatrix._eval_iter_itemsc                 C      |  | j S r!   rp   r    r/   ri   r(   r(   r)   r/        zRepMatrix.copyreturnc                 C   sh   | j j}|ttfv rt}t
|S |tkr0dd |  D }t|dkr*|\}t
|S t}t
|S t	d)Nc                 S   s   h | ]}|j qS r(   )kind)rJ   er(   r(   r)   	<setcomp>  s    z!RepMatrix.kind.<locals>.<setcomp>r   z%Domain should only be ZZ, QQ or EXRAW)r    r-   r   r   r   r   rc   lenr   RuntimeErrorr   )r&   r-   element_kindkindsr(   r(   r)   r     s   	zRepMatrix.kindc                    sJ   d}|   }t|| j| j krtjj  }|p$t fdd| D S )NFc                 3   s    | ]}|j   V  qd S r!   )has)rJ   valuepatternsr(   r)   rL   (  rM   z&RepMatrix._eval_has.<locals>.<genexpr>)	todokr   rP   rQ   r   Zeror   anyrc   )r&   r   zhasrq   r(   r   r)   	_eval_has   s
   zRepMatrix._eval_hasc                    s2   t  fddt jD sdS t   jkS )Nc                 3   s     | ]} ||f d kV  qdS )r   Nr(   rJ   r_   ri   r(   r)   rL   +  r{   z.RepMatrix._eval_is_Identity.<locals>.<genexpr>F)rO   rangerP   r   r   ri   r(   ri   r)   _eval_is_Identity*  s   zRepMatrix._eval_is_Identityc                 C   s    | | j  |}t| dkS rU   )T	applyfuncr   rc   )r&   simpfuncdiffr(   r(   r)   _eval_is_symmetric/  s   zRepMatrix._eval_is_symmetricc                 C   r~   )aB  Returns the transposed SparseMatrix of this SparseMatrix.

        Examples
        ========

        >>> from sympy import SparseMatrix
        >>> a = SparseMatrix(((1, 2), (3, 4)))
        >>> a
        Matrix([
        [1, 2],
        [3, 4]])
        >>> a.T
        Matrix([
        [1, 3],
        [2, 4]])
        )rp   r    	transposeri   r(   r(   r)   _eval_transpose3  s   zRepMatrix._eval_transposec                 C      |  | j|jS r!   )rp   r    vstackr%   r(   r(   r)   _eval_col_joinF     zRepMatrix._eval_col_joinc                 C   r   r!   )rp   r    hstackr%   r(   r(   r)   _eval_row_joinI  r   zRepMatrix._eval_row_joinc                 C   s   |  | j||S r!   )rp   r    extract)r&   rowsListcolsListr(   r(   r)   _eval_extractL  r   zRepMatrix._eval_extractc                 C   s
   t | |S r!   )_getitem_RepMatrix)r&   keyr(   r(   r)   __getitem__O  s   
zRepMatrix.__getitem__c                 C      t ||ft}| |S r!   )r   zerosr   rp   rC   rP   rQ   r4   r(   r(   r)   _eval_zerosR     
zRepMatrix._eval_zerosc                 C   r   r!   )r   eyer   rp   r   r(   r(   r)   	_eval_eyeW  r   zRepMatrix._eval_eyec                 C   s   t | || j|j S r!   r   rp   r    r%   r(   r(   r)   	_eval_add\     zRepMatrix._eval_addc                 C   s   t | || j|j S r!   r   r%   r(   r(   r)   _eval_matrix_mul_  r   zRepMatrix._eval_matrix_mulc                 C   s,   | j |j \}}||}t| ||S r!   )r    unifymul_elementwiser   rp   )r&   r'   selfrepotherrepnewrepr(   r(   r)   _eval_matrix_mul_elementwiseb  s   
z&RepMatrix._eval_matrix_mul_elementwisec                 C   "   |  | j|\}}| ||S r!   )rF   r    rp   	scalarmulr&   r'   r4   r(   r(   r)   _eval_scalar_mulg     zRepMatrix._eval_scalar_mulc                 C   r   r!   )rF   r    rp   
rscalarmulr   r(   r(   r)   _eval_scalar_rmulk  r   zRepMatrix._eval_scalar_rmulc                 C   s   |  | jtS r!   )rp   r    r   absri   r(   r(   r)   	_eval_Abso  s   zRepMatrix._eval_Absc                 C   s4   | j }|j}|ttfv r|  S | |dd S )Nc                 S      |   S r!   )	conjugate)r   r(   r(   r)   <lambda>x  s    z+RepMatrix._eval_conjugate.<locals>.<lambda>)r    r-   r   r   r/   rp   r   )r&   r4   r-   r(   r(   r)   _eval_conjugater  s
   zRepMatrix._eval_conjugateFc                 C   s~   | j t|ddkrdS d}t| jD ]*}t| jD ]"}| ||f |||f |}|du r1  dS |dur;|du r;|}qq|S )a1  Applies ``equals`` to corresponding elements of the matrices,
        trying to prove that the elements are equivalent, returning True
        if they are, False if any pair is not, and None (or the first
        failing expression if failing_expression is True) if it cannot
        be decided if the expressions are equivalent or not. This is, in
        general, an expensive operation.

        Examples
        ========

        >>> from sympy import Matrix
        >>> from sympy.abc import x
        >>> A = Matrix([x*(x - 1), 0])
        >>> B = Matrix([x**2 - x, 0])
        >>> A == B
        False
        >>> A.simplify() == B.simplify()
        True
        >>> A.equals(B)
        True
        >>> A.equals(2)
        False

        See Also
        ========
        sympy.core.expr.Expr.equals
        shapeNFT)r   getattrr   rP   rQ   equals)r&   r'   failing_expressionrvr_   r`   ansr(   r(   r)   r   z  s   zRepMatrix.equalsc              
   C   s   | j st zt|}W n ty   tdw t|dd}z| |}W n ty0   tdw z	| }W | S  t	yQ } zd| d}t
||d}~ww )aZ  
        Returns the inverse of the integer matrix ``M`` modulo ``m``.

        Examples
        ========

        >>> from sympy import Matrix
        >>> A = Matrix(2, 2, [1, 2, 3, 4])
        >>> A.inv_mod(5)
        Matrix([
        [3, 1],
        [4, 2]])
        >>> A.inv_mod(3)
        Matrix([
        [1, 1],
        [0, 1]])

        z%inv_mod: modulus m must be an integerF)	symmetricz(inv_mod: matrix entries must be integerszMatrix is not invertible (mod )N)	is_squarer   r   
ValueErrorr+   r   r7   r   invr   r   	to_Matrix)Mmrx   dMdMiexcmsgr(   r(   r)   inv_mod  s*   

zRepMatrix.inv_mod      ?c                 C   s0   t t|}| jt}|j|d}| |S )u0  LLL-reduced basis for the rowspace of a matrix of integers.

        Performs the Lenstra–Lenstra–Lovász (LLL) basis reduction algorithm.

        The implementation is provided by :class:`~DomainMatrix`. See
        :meth:`~DomainMatrix.lll` for more details.

        Examples
        ========

        >>> from sympy import Matrix
        >>> M = Matrix([[1, 0, 0, 0, -20160],
        ...             [0, 1, 0, 0, 33768],
        ...             [0, 0, 1, 0, 39578],
        ...             [0, 0, 0, 1, 47757]])
        >>> M.lll()
        Matrix([
        [ 10, -3,  -2,  8,  -4],
        [  3, -9,   8,  1, -11],
        [ -3, 13,  -9, -3,  -9],
        [-12, -7, -11,  9,  -1]])

        See Also
        ========

        lll_transform
        sympy.polys.matrices.domainmatrix.DomainMatrix.lll
        delta)r   rB   r
   r    r,   r   lllrp   )r&   r   r   basisr(   r(   r)   r     s   
zRepMatrix.lllc                 C   sF   t t|}| jt}|j|d\}}| |}| |}||fS )u\  LLL-reduced basis and transformation matrix.

        Performs the Lenstra–Lenstra–Lovász (LLL) basis reduction algorithm.

        The implementation is provided by :class:`~DomainMatrix`. See
        :meth:`~DomainMatrix.lll_transform` for more details.

        Examples
        ========

        >>> from sympy import Matrix
        >>> M = Matrix([[1, 0, 0, 0, -20160],
        ...             [0, 1, 0, 0, 33768],
        ...             [0, 0, 1, 0, 39578],
        ...             [0, 0, 0, 1, 47757]])
        >>> B, T = M.lll_transform()
        >>> B
        Matrix([
        [ 10, -3,  -2,  8,  -4],
        [  3, -9,   8,  1, -11],
        [ -3, 13,  -9, -3,  -9],
        [-12, -7, -11,  9,  -1]])
        >>> T
        Matrix([
        [ 10, -3,  -2,  8],
        [  3, -9,   8,  1],
        [ -3, 13,  -9, -3],
        [-12, -7, -11,  9]])

        The transformation matrix maps the original basis to the LLL-reduced
        basis:

        >>> T * M == B
        True

        See Also
        ========

        lll
        sympy.polys.matrices.domainmatrix.DomainMatrix.lll_transform
        r   )r   rB   r
   r    r,   r   lll_transformrp   )r&   r   r   r   	transformBr   r(   r(   r)   r     s   *

zRepMatrix.lll_transformr!   )F)r   )-__name__
__module____qualname____doc__r   __annotations__r*   r7   classmethodrF   rT   ra   re   rj   rm   ro   rr   ru   rt   r}   r/   propertyr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r(   r(   r(   r)   r      s^   
 
O
&



	



)
+"r   c                       s   e Zd ZdZdZdd ZeddddZe f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#d$ Zd%d& Zd'd( Zd)d* Zd+d, Z  ZS )-MutableRepMatrixzCMutable matrix based on DomainMatrix as the internal representationFc                 O   s   | j |i |S r!   )_new)rC   argsr3   r(   r(   r)   __new__-  r   zMutableRepMatrix.__new__Tr/   c                O   s^   |du rt |dkrtd|\}}}n| j|i |\}}}t|}| |||}| |S )NF   zA'copy=False' requires a matrix be initialized as rows,cols,[list])r   r+   _handle_creation_inputsrs   ra   rp   )rC   r/   r   r3   rP   rQ   r\   r4   r(   r(   r)   r   0  s   
zMutableRepMatrix._newc                    s$   t  | }|j\|_|_||_|S r!   )superr   r   rP   rQ   r    )rC   r4   obj	__class__r(   r)   rp   @  s   zMutableRepMatrix._fromrepc                 C   r~   r!   r   ri   r(   r(   r)   r/   G  r   zMutableRepMatrix.copyc                 C   r   r!   r   ri   r(   r(   r)   
as_mutableJ  s   zMutableRepMatrix.as_mutablec                 C   sL   |  ||}|dur$|\}}}| | j|\| _}| jj||| dS dS )a@  

        Examples
        ========

        >>> from sympy import Matrix, I, zeros, ones
        >>> m = Matrix(((1, 2+I), (3, 4)))
        >>> m
        Matrix([
        [1, 2 + I],
        [3,     4]])
        >>> m[1, 0] = 9
        >>> m
        Matrix([
        [1, 2 + I],
        [9,     4]])
        >>> m[1, 0] = [[0, 1]]

        To replace row r you assign to position r*m where m
        is the number of columns:

        >>> M = zeros(4)
        >>> m = M.cols
        >>> M[3*m] = ones(1, m)*2; M
        Matrix([
        [0, 0, 0, 0],
        [0, 0, 0, 0],
        [0, 0, 0, 0],
        [2, 2, 2, 2]])

        And to replace column c you can assign to position c:

        >>> M[2] = ones(m, 1)*4; M
        Matrix([
        [0, 0, 4, 0],
        [0, 0, 4, 0],
        [0, 0, 4, 0],
        [2, 2, 4, 2]])
        N)_setitemrF   r    r4   setitem)r&   r   r   r   r_   r`   r(   r(   r)   __setitem__M  s   (
zMutableRepMatrix.__setitem__c                 C   sH   t | jd d d |f | jd d |d d f | _|  jd8  _d S Nr   )r   r   r    rQ   )r&   colr(   r(   r)   _eval_col_del{     6zMutableRepMatrix._eval_col_delc                 C   sH   t | jd |d d f | j|d d d d f | _|  jd8  _d S r   )r   r   r    rP   )r&   rowr(   r(   r)   _eval_row_del  r   zMutableRepMatrix._eval_row_delc                 C   s8   |  |}| | d d d |f || d d |d f S r!   )r   r   )r&   r   r'   r(   r(   r)   _eval_col_insert     
.z!MutableRepMatrix._eval_col_insertc                 C   s8   |  |}| | d |d d f || |d d d f S r!   )r   r   )r&   r   r'   r(   r(   r)   _eval_row_insert  r   z!MutableRepMatrix._eval_row_insertc                 C   s.   t | jD ]}|| ||f || ||f< qdS )a  In-place operation on col j using two-arg functor whose args are
        interpreted as (self[i, j], i).

        Examples
        ========

        >>> from sympy import eye
        >>> M = eye(3)
        >>> M.col_op(1, lambda v, i: v + 2*M[i, 0]); M
        Matrix([
        [1, 2, 0],
        [0, 1, 0],
        [0, 0, 1]])

        See Also
        ========
        col
        row_op
        Nr   rP   )r&   r`   fr_   r(   r(   r)   col_op  s   zMutableRepMatrix.col_opc                 C   s@   t d| jD ]}| ||f | ||f | ||f< | ||f< qdS )a  Swap the two given columns of the matrix in-place.

        Examples
        ========

        >>> from sympy import Matrix
        >>> M = Matrix([[1, 0], [1, 0]])
        >>> M
        Matrix([
        [1, 0],
        [1, 0]])
        >>> M.col_swap(0, 1)
        >>> M
        Matrix([
        [0, 1],
        [0, 1]])

        See Also
        ========

        col
        row_swap
        r   Nr  r&   r_   r`   kr(   r(   r)   col_swap     ,zMutableRepMatrix.col_swapc                 C   s.   t | jD ]}|| ||f || ||f< qdS )a  In-place operation on row ``i`` using two-arg functor whose args are
        interpreted as ``(self[i, j], j)``.

        Examples
        ========

        >>> from sympy import eye
        >>> M = eye(3)
        >>> M.row_op(1, lambda v, j: v + 2*M[0, j]); M
        Matrix([
        [1, 0, 0],
        [2, 1, 0],
        [0, 0, 1]])

        See Also
        ========
        row
        zip_row_op
        col_op

        Nr   rQ   )r&   r_   r  r`   r(   r(   r)   row_op  s   zMutableRepMatrix.row_opc                 C   s(   t | jD ]}| ||f  |9  < qdS )a  Multiply the given row by the given factor in-place.

        Examples
        ========

        >>> from sympy import eye
        >>> M = eye(3)
        >>> M.row_mult(1,7); M
        Matrix([
        [1, 0, 0],
        [0, 7, 0],
        [0, 0, 1]])

        Nr  )r&   r_   factorr`   r(   r(   r)   row_mult  s   zMutableRepMatrix.row_multc                 C   s4   t | jD ]}| ||f  || ||f  7  < qdS )a  Add k times row s (source) to row t (target) in place.

        Examples
        ========

        >>> from sympy import eye
        >>> M = eye(3)
        >>> M.row_add(0, 2,3); M
        Matrix([
        [1, 0, 0],
        [0, 1, 0],
        [3, 0, 1]])
        Nr  )r&   str  r`   r(   r(   r)   row_add  s   "zMutableRepMatrix.row_addc                 C   s@   t d| jD ]}| ||f | ||f | ||f< | ||f< qdS )a  Swap the two given rows of the matrix in-place.

        Examples
        ========

        >>> from sympy import Matrix
        >>> M = Matrix([[0, 1], [1, 0]])
        >>> M
        Matrix([
        [0, 1],
        [1, 0]])
        >>> M.row_swap(0, 1)
        >>> M
        Matrix([
        [1, 0],
        [0, 1]])

        See Also
        ========

        row
        col_swap
        r   Nr  r  r(   r(   r)   row_swap  r  zMutableRepMatrix.row_swapc                 C   s6   t | jD ]}|| ||f | ||f | ||f< qdS )a  In-place operation on row ``i`` using two-arg functor whose args are
        interpreted as ``(self[i, j], self[k, j])``.

        Examples
        ========

        >>> from sympy import eye
        >>> M = eye(3)
        >>> M.zip_row_op(1, 0, lambda v, u: v + 2*u); M
        Matrix([
        [1, 0, 0],
        [2, 1, 0],
        [0, 0, 1]])

        See Also
        ========
        row
        row_op
        col_op

        Nr  )r&   r_   r  r  r`   r(   r(   r)   
zip_row_op  s   $zMutableRepMatrix.zip_row_opc                 C   s,   t |stdt| | |t| |S )ai  Copy in elements from a list.

        Parameters
        ==========

        key : slice
            The section of this matrix to replace.
        value : iterable
            The iterable to copy values from.

        Examples
        ========

        >>> from sympy import eye
        >>> I = eye(3)
        >>> I[:2, 0] = [1, 2] # col
        >>> I
        Matrix([
        [1, 0, 0],
        [2, 1, 0],
        [0, 0, 1]])
        >>> I[1, :2] = [[3, 4]]
        >>> I
        Matrix([
        [1, 0, 0],
        [3, 4, 0],
        [0, 0, 1]])

        See Also
        ========

        copyin_matrix
        z,`value` must be an ordered iterable, not %s.)r   r+   r[   copyin_matrix)r&   r   r   r(   r(   r)   copyin_list/  s   "zMutableRepMatrix.copyin_listc                 C   s   |  |\}}}}|j}|| || }}	|||	fkr!ttdt|jD ]}
t|jD ]}||
|f | |
| || f< q-q&dS )a  Copy in values from a matrix into the given bounds.

        Parameters
        ==========

        key : slice
            The section of this matrix to replace.
        value : Matrix
            The matrix to copy values from.

        Examples
        ========

        >>> from sympy import Matrix, eye
        >>> M = Matrix([[0, 1], [2, 3], [4, 5]])
        >>> I = eye(3)
        >>> I[:3, :2] = M
        >>> I
        Matrix([
        [0, 1, 0],
        [2, 3, 0],
        [4, 5, 1]])
        >>> I[0, 1] = M
        >>> I
        Matrix([
        [0, 0, 1],
        [2, 2, 3],
        [4, 4, 5]])

        See Also
        ========

        copyin_list
        zXThe Matrix `value` doesn't have the same dimensions as the in sub-Matrix given by `key`.N)
key2boundsr   r   r   r   rP   rQ   )r&   r   r   rlorhiclochir   drdcr_   r`   r(   r(   r)   r  U  s   #zMutableRepMatrix.copyin_matrixc                    sN   t st jt _dS  fddt jD }t| jt _dS )aN  Fill self with the given value.

        Notes
        =====

        Unless many values are going to be deleted (i.e. set to zero)
        this will create a matrix that is slower than a dense matrix in
        operations.

        Examples
        ========

        >>> from sympy import SparseMatrix
        >>> M = SparseMatrix.zeros(3); M
        Matrix([
        [0, 0, 0],
        [0, 0, 0],
        [0, 0, 0]])
        >>> M.fill(1); M
        Matrix([
        [1, 1, 1],
        [1, 1, 1],
        [1, 1, 1]])

        See Also
        ========

        zeros
        ones
        c                    s    i | ]}|t t jqS r(   )rV   fromkeysr   rQ   r   r&   r   r(   r)   
<dictcomp>  s     z)MutableRepMatrix.fill.<locals>.<dictcomp>N)r
   r   r   r   r   r    r   rP   )r&   r   r]   r(   r  r)   fill  s
   zMutableRepMatrix.fill)r   r   r   r   is_zeror   r   r   rp   r/   r   r   r   r   r   r   r  r  r	  r  r  r  r  r  r  r  __classcell__r(   r(   r   r)   r   "  s2    .&/r   c           	   	      s  t |tr|\}}z| jt|t|W S  ttfy   t |tr&|jr.t |tr^|js^|dk du sL|| j	d kdu sL|dk du sL|| j	d kdu rPt
dddlm} || || Y S t |trkt| j| }nt|rpn|g}t |trt| j| }nt|rn|g}| || Y S w | j	\} |  sg | S | jjj}t |t}|r fddt|  | D }njtt|  g}|tkr|jfdd|D }|r|S |d S )	a2  Return portion of self defined by key. If the key involves a slice
    then a list will be returned (if key is a single slice) or a matrix
    (if key was a tuple involving a slice).

    Examples
    ========

    >>> from sympy import Matrix, I
    >>> m = Matrix([
    ... [1, 2 + I],
    ... [3, 4    ]])

    If the key is a tuple that does not involve a slice then that element
    is returned:

    >>> m[1, 0]
    3

    When a tuple key involves a slice, a matrix is returned. Here, the
    first column is selected (all rows, column 0):

    >>> m[:, 0]
    Matrix([
    [1],
    [3]])

    If the slice is not a tuple then it selects from the underlying
    list of elements that are arranged in row order and a list is
    returned if a slice is involved:

    >>> m[0]
    1
    >>> m[::2]
    [1, 3]
    r   Tr   zindex out of boundary)MatrixElementc                    s   g | ]
}j t|  qS r(   )getitemrX   )rJ   r^   )rQ   r4   r(   r)   
<listcomp>  s    z&_getitem_RepMatrix.<locals>.<listcomp>c                    s   g | ]} |qS r(   r(   )rJ   valrz   r(   r)   r"    s    )r"   tupler    getitem_sympyindex_r+   
IndexErrorr   	is_numberr   r   "sympy.matrices.expressions.matexprr   slicer   rP   r   rQ   r   r4   r-   r!  rX   r   rg   )	r&   r   r_   r`   r   rP   r-   is_slicerc   r(   )rQ   r4   rg   r)   r     sL   
$ 



"r   N)1collectionsr   operatorr   r&  sympy.core.exprr   sympy.core.kindr   r   r   sympy.core.numbersr   r	   sympy.core.sympifyr
   r   sympy.core.singletonr   sympy.polys.domainsr   r   r   r   sympy.polys.matricesr   sympy.polys.matrices.exceptionsr   sympy.polys.polyerrorsr   sympy.utilities.exceptionsr   sympy.utilities.iterablesr   sympy.utilities.miscr   r   
exceptionsr   r   r   
matrixbaser   r   r   r   r   r   r   r(   r(   r(   r)   <module>   s6           