� ��g�s��<�ddlmZddlmZddlmZddlmZm Z m Z ddl m Z m Z ddlmZmZddlmZddlmZmZmZmZdd lmZdd lmZdd lmZdd lmZdd l m!Z!ddl"m#Z#m$Z$ddl%m&Z&m'Z'm(Z(ddl)m*Z*m+Z+ddl,m-Z-Gd�de+��Z.Gd�de.��Z/d�Z0dS)�)� 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��eZdZUdZeed<d�Zd+d�Zed���Z ed���Z ed���Z ed ���Z d �Z d �Zd �Zed ���Zd�Zd�Zd�Zd�Zedefd���Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zed���Z ed���Z!d�Z"d�Z#d �Z$d!�Z%d"�Z&d#�Z'd$�Z(d,d&�Z)d'�Z*d-d)�Z+d-d*�Z,dS).� 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���t|t��sD t|��}n#t$r tcYSwxYwt|t��stS|j�|j��S�N)� isinstancer!r r �NotImplementedr"�unify_eq��self�others �h/home/asafur/pinokio/api/open-webui.git/app/env/lib/python3.11/site-packages/sympy/matrices/repmatrix.py�__eq__zRepMatrix.__eq__5s}���%��+�+� &� &� �������� &� &� &�%�%�%�%� &�����e�Y�/�/� &�%�%��y�!�!�%�*�-�-�-s �'�;�;Nc ��|�+|rtd���|j�|��S|j}|j}|sa|jr|���S|jr? |�t��S#t$rYnwxYw|���S|j di|��}|jj r|�t��}|S)aGConvert 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 parameter�) � TypeErrorr"� convert_to�domain�is_ZZ�copy�is_QQrr� choose_domain�is_EXr)r)r1�kwargs�rep�dom�rep_doms r+�to_DMzRepMatrix.to_DMAs���V � �� P�� N�O�O�O��9�'�'��/�/� /��i���j�� � "��y� "��x�x�z�z�!��� "���>�>�"�-�-�-��%�����D������x�x�z�z�!�$�#�#�-�-�f�-�-�� �>� � 0��(�(��/�/�G��s�!A;�; B�Bc�l�|j}t|��}|tkr]|jr|}n|jrt }nt}||kr|�|��}|}|tkr|�|��}|tkr(t|t��stdddd���||fS)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) r1r r� is_Integer� is_Rationalrr0� from_sympyr%rr)�clsr8�elementr1� new_domains r+�_unify_element_sympyzRepMatrix._unify_element_sympy�s�������7�#�#�� �U�?�?��!� #�#� � ��$� #�� � �"� � �V�#�#��n�n�Z�0�0��#������$�/�/��8�8�� �U�?�?�:�g�t�#<�#<�?� %�� */�+J�� � � � ��G�|��c�\�td�|D����stdddd���t|||ft��}td�|D����rNtd�|D����r|�t ��}n|�t ��}|S) Nc3�@K�|]}t|t��V��dSr$)� issubclassr��.0�typs r+� <genexpr>z1RepMatrix._dod_to_DomainMatrix.<locals>.<genexpr>�s,����:�:�S�:�c�4�(�(�:�:�:�:�:�:rLr=r>r?�rAc3�@K�|]}t|t��V��dSr$)rOr rPs r+rSz1RepMatrix._dod_to_DomainMatrix.<locals>.<genexpr>�s,����:�:�S�z�#�x�(�(�:�:�:�:�:�:rLc3�@K�|]}t|t��V��dSr$)rOr rPs r+rSz1RepMatrix._dod_to_DomainMatrix.<locals>.<genexpr>�s,����=�=��:�c�7�+�+�=�=�=�=�=�=rL)�allrrrr0rr)rH�rows�cols�dod�typesr8s r+�_dod_to_DomainMatrixzRepMatrix._dod_to_DomainMatrix�s����:�:�E�:�:�:�:�:� � %�� */�+J�� � � � ��3��t� �e�4�4�� �:�:�E�:�:�:� :� :� )��=�=�u�=�=�=�=�=� )��n�n�R�(�(����n�n�R�(�(��� rLc��tt��}t|��D])\}}|dkrt||��\}}||||<�*t t t |����} |�|||| ��} | S�Nr)r�dict� enumerate�divmod�set�map�typer\) rHrXrY� flat_list� elements_dod�nrI�i�jr[r8s r+�_flat_list_to_DomainMatrixz$RepMatrix._flat_list_to_DomainMatrix�s���#�4�(�(� �#�I�.�.� -� -�J�A�w��!�|�|��a������1�%,� �Q���"���C��i�(�(�)�)���&�&�t�T�<��G�G��� rLc�"�tt��}|���D]\\}}}|dkr ||||<�tt t |�������}|�||||��} | Sr^)rr_�itemsrbrcrd�valuesr\) rHrXrY�smatrfrhrirIr[r8s r+�_smat_to_DomainMatrixzRepMatrix._smat_to_DomainMatrix�s���#�4�(�(� �#�z�z�|�|� -� -�O�F�Q��G��!�|�|�%,� �Q���"���C��d�k�k�m�m�,�,�-�-���&�&�t�T�<��G�G��� rLc�X�|j������Sr$)r"�to_sympy� to_list_flat�r)s r+�flatzRepMatrix.flat�s"���y�!�!�#�#�0�0�2�2�2rLc�X�|j������Sr$)r"rq�to_listrss r+� _eval_tolistzRepMatrix._eval_tolist�s"���y�!�!�#�#�+�+�-�-�-rLc�X�|j������Sr$)r"rq�to_dokrss r+� _eval_todokzRepMatrix._eval_todok�s"���y�!�!�#�#�*�*�,�,�,rLc�V�|�|�|||����Sr$)�_fromrepro)rHrXrY�doks r+�_eval_from_dokzRepMatrix._eval_from_dok�s&���|�|�C�5�5�d�D�#�F�F�G�G�GrLc�D�t|�����Sr$)�list�_eval_iter_valuesrss r+� _eval_valueszRepMatrix._eval_values�s���D�*�*�,�,�-�-�-rLc��|j}|j}|���}|jst |j|��}|Sr$)r"r1� iter_values�is_EXRAWrcrq)r)r8�Krms r+r�zRepMatrix._eval_iter_values�s?���i�� �J�����"�"���z� -����V�,�,�F�� rLc���|j}|j}|j�|���}|js�fd�|D��}|S)Nc3�8�K�|]\}}|�|��fV��dSr$r.)rQrh�vrqs �r+rSz-RepMatrix._eval_iter_items.<locals>.<genexpr> s4�����8�8�$�!�Q�a���!���%�8�8�8�8�8�8rL)r"r1rq� iter_itemsr�)r)r8r�rlrqs @r+�_eval_iter_itemszRepMatrix._eval_iter_itemssO����i�� �J���:����� � ���z� 9�8�8�8�8�%�8�8�8�E�� rLc�Z�|�|j�����Sr$�r|r"r3rss r+r3zRepMatrix.copy � ���}�}�T�Y�^�^�-�-�.�.�.rL�returnc��|jj}|ttfvrt}nX|t kr>d�|���D��}t|��dkr|\}nt}ntd���t|��S)Nc��h|] }|j�� Sr.)�kind)rQ�es r+� <setcomp>z!RepMatrix.kind.<locals>.<setcomp>s��3�3�3��Q�V�3�3�3rLrz%Domain should only be ZZ, QQ or EXRAW) r"r1rrrrrm�lenr� RuntimeErrorr)r)r1� element_kind�kindss r+r�zRepMatrix.kinds�����!�� �b�"�X� � �%�L�L� �u�_�_�3�3�T�[�[�]�]�3�3�3�E��5�z�z�Q���!&����,� � ��F�G�G� G��,�'�'�'rLc����d}|���}t|��|j|jzkrt jj��}|p,t�fd�|���D����S)NFc3�,�K�|]}|j��V��dSr$)�has)rQ�value�patternss �r+rSz&RepMatrix._eval_has.<locals>.<genexpr>(s,�����J�J�E�9�5�9�h�/�J�J�J�J�J�JrL) �todokr�rXrYr �Zeror��anyrm)r)r��zhasr}s ` r+� _eval_haszRepMatrix._eval_has so������j�j�l�l�� �s�8�8�t�y���*� *� *��6�:�x�(�D��J�s�J�J�J�J�S�Z�Z�\�\�J�J�J�J�J�JrLc���t�fd�t�j��D����sdSt�������jkS)Nc3�4�K�|]}�||fdkV��dS)rNr.)rQrhr)s �r+rSz.RepMatrix._eval_is_Identity.<locals>.<genexpr>+s/�����=�=�q�4��1��:��?�=�=�=�=�=�=rLF)rW�rangerXr�r�rss`r+�_eval_is_IdentityzRepMatrix._eval_is_Identity*sT����=�=�=�=�E�$�)�,<�,<�=�=�=�=�=� ��5��4�:�:�<�<� � �D�I�-�-rLc��||jz �|��}t|�����dkSr^)�T� applyfuncr�rm)r)�simpfunc�diffs r+�_eval_is_symmetriczRepMatrix._eval_is_symmetric/s6���t�v� �(�(��2�2���4�;�;�=�=�!�!�Q�&�&rLc�Z�|�|j�����S)aBReturns 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]]) )r|r"� transposerss r+�_eval_transposezRepMatrix._eval_transpose3s$��"�}�}�T�Y�0�0�2�2�3�3�3rLc�f�|�|j�|j����Sr$)r|r"�vstackr(s r+�_eval_col_joinzRepMatrix._eval_col_joinF�&���}�}�T�Y�-�-�e�j�9�9�:�:�:rLc�f�|�|j�|j����Sr$)r|r"�hstackr(s r+�_eval_row_joinzRepMatrix._eval_row_joinIr�rLc�^�|�|j�||����Sr$)r|r"�extract)r)�rowsList�colsLists r+� _eval_extractzRepMatrix._eval_extractLs&���}�}�T�Y�.�.�x��B�B�C�C�CrLc�"�t||��Sr$)�_getitem_RepMatrix)r)�keys r+� __getitem__zRepMatrix.__getitem__Os��!�$��,�,�,rLc�d�tj||ft��}|�|��Sr$)r�zerosrr|�rHrXrYr8s r+� _eval_zeroszRepMatrix._eval_zerosRs*��� �$���r�2�2���|�|�C� � � rLc�d�tj||ft��}|�|��Sr$)r�eyerr|r�s r+� _eval_eyezRepMatrix._eval_eyeWs*�����d�|�R�0�0���|�|�C� � � rLc�b�t||���|j|jz��Sr$�rr|r"r(s r+� _eval_addzRepMatrix._eval_add\�)���t�U�#�#�,�,�T�Y���-C�D�D�DrLc�b�t||���|j|jz��Sr$r�r(s r+�_eval_matrix_mulzRepMatrix._eval_matrix_mul_r�rLc��|j�|j��\}}|�|��}t||���|��Sr$)r"�unify�mul_elementwiserr|)r)r*�selfrep�otherrep�newreps r+�_eval_matrix_mul_elementwisez&RepMatrix._eval_matrix_mul_elementwisebsM�� �I�O�O�E�J�7�7�����(�(��2�2���t�U�#�#�,�,�V�4�4�4rLc��|�|j|��\}}|�|�|����Sr$)rKr"r|� scalarmul�r)r*r8s r+�_eval_scalar_mulzRepMatrix._eval_scalar_mulgs;���.�.�t�y�%�@�@� ��U��}�}�S�]�]�5�1�1�2�2�2rLc��|�|j|��\}}|�|�|����Sr$)rKr"r|� rscalarmulr�s r+�_eval_scalar_rmulzRepMatrix._eval_scalar_rmulks;���.�.�t�y�%�@�@� ��U��}�}�S�^�^�E�2�2�3�3�3rLc�f�|�|j�t����Sr$)r|r"r��absrss r+� _eval_AbszRepMatrix._eval_Absos$���}�}�T�Y�0�0��5�5�6�6�6rLc��|j}|j}|ttfvr|���S|�|�d�����S)Nc�*�|���Sr$)� conjugate)r�s r+�<lambda>z+RepMatrix._eval_conjugate.<locals>.<lambda>xs�������rL)r"r1rrr3r|r�)r)r8r1s r+�_eval_conjugatezRepMatrix._eval_conjugatersO���i����� �b�"�X� � ��9�9�;�;� ��=�=����/F�/F�!G�!G�H�H� HrLFc��|jt|dd��krdSd}t|j��D]Q}t|j��D]:}|||f�|||f|��}|durdS|dur|dur|}�;�R|S)a1Applies ``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�rXrY�equals)r)r*�failing_expression�rvrhri�anss r+r�zRepMatrix.equalszs���8 �:�����6�6� 6� 6��5� ���t�y�!�!� � �A��4�9�%�%� � ���1�a�4�j�'�'��a��d� �5G�H�H���%�<�<� �5�5�5���_�_��t����B��  � � rLc��|jst��� t|��}n#t$rt d���wxYwt |d���} |�|��}n#t$rtd���wxYw |���}n(#t$r}d|�d�}t|��|�d}~wwxYw|� ��S)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 integerszMatrix is not invertible (mod �)N) � is_squarerr� ValueErrorr/rr;r�invrr� to_Matrix)�M�mr��dM�dMi�exc�msgs r+�inv_modzRepMatrix.inv_mod�s��(�{� )�&�(�(� (� E��q� � �A�A��� E� E� E��C�D�D� D� E���� �q�E� "� "� "�� I�������B�B��� I� I� I��G�H�H� H� I���� 9��&�&�(�(�C�C��)� 9� 9� 9�7�1�7�7�7�C�*�3�/�/�S� 8����� 9�����}�}���s-�'�A�A,�,B� B� C�)B?�?C��?c���tjt|����}|j�t ��}|�|���}|�|��S)u0LLL-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)rrGr r"r0r�lllr|)r)r�r��basiss r+r�z RepMatrix.lll�sS��:� �h�u�o�o�.�.�� �Y� !� !�"� %� %�����U��#�#���}�}�U�#�#�#rLc��tjt|����}|j�t ��}|�|���\}}|�|��}|�|��}||fS)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�)rrGr r"r0r� lll_transformr|)r)r�r�r�� transform�Br�s r+r�zRepMatrix.lll_transform�su��T� �h�u�o�o�.�.�� �Y� !� !�"� %� %���+�+�%�+�8�8���y� �M�M�%� � �� �M�M�)� $� $���!�t� rLr$)F)r�)-�__name__� __module__� __qualname__�__doc__r�__annotations__r,r;� classmethodrKr\rjrortrwrzr~r�r�r�r3�propertyrr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r.rLr+r!r!s����������6 ���� .� .� .�M�M�M�M�^�$�$��[�$�L����[��2� � ��[� �� � ��[� �3�3�3�.�.�.�-�-�-��H�H��[�H�.�.�.�������/�/�/�� (�j� (� (� (��X� (�K�K�K�.�.�.� '�'�'�4�4�4�&;�;�;�;�;�;�D�D�D�-�-�-��!�!��[�!��!�!��[�!�E�E�E�E�E�E�5�5�5� 3�3�3�4�4�4�7�7�7�I�I�I�'�'�'�'�R)�)�)�V $� $� $� $�D/�/�/�/�/�/rLr!c���eZdZdZdZd�Zedd�d���Ze�fd���Zd�Z d �Z d �Z d �Z d �Z d �Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Z�xZS)�MutableRepMatrixzCMutable matrix based on DomainMatrix as the internal representationFc��|j|i|��Sr$)�_new)rH�argsr7s r+�__new__zMutableRepMatrix.__new__-s���s�x��(��(�(�(rLT�r3c���|dur)t|��dkrtd���|\}}}n |j|i|��\}}}t|��}|�|||��}|�|��S)NF�zA'copy=False' requires a matrix be initialized as rows,cols,[list])r�r/�_handle_creation_inputsr�rjr|)rHr3r r7rXrYrer8s r+r zMutableRepMatrix._new0s��� �5�=�=��4�y�y�A�~�~�� c�d�d�d�$(� !�D�$� � �$?�C�$?��$P��$P�$P� !�D�$� ��Y���I��,�,�T�4��C�C���|�|�C� � � rLc���t���|��}|j\|_|_||_|Sr$)�superrr�rXrYr")rHr8�obj� __class__s �r+r|zMutableRepMatrix._fromrep@s4����g�g�o�o�c�"�"�� �Y����#�(����� rLc�Z�|�|j�����Sr$r�rss r+r3zMutableRepMatrix.copyGr�rLc�*�|���Sr$rrss r+� as_mutablezMutableRepMatrix.as_mutableJs���y�y�{�{�rLc���|�||��}|�L|\}}}|�|j|��\|_}|jj�|||��dSdS)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)�_setitemrKr"r8�setitem)r)r�r�r�rhris r+� __setitem__zMutableRepMatrix.__setitem__Mso��P�]�]�3�� &� &�� �>��K�A�q�%�#�8�8���E�J�J� �D�I�u� �I�M� !� !�!�Q�� .� .� .� .� .� �>rLc��tj|jdd�d|�f|jdd�|dzd�f��|_|xjdzc_dS�Nr)rr�r"rY)r)�cols r+� _eval_col_delzMutableRepMatrix._eval_col_del{sS�� �'�� �!�!�!�D�S�D�&�(9�4�9�Q�Q�Q�s�1�u�v�v�X�;N�O�O�� � � � �Q�� � � � rLc��tj|jd|�dd�f|j|dzd�dd�f��|_|xjdzc_dSr)rr�r"rX)r)�rows r+� _eval_row_delzMutableRepMatrix._eval_row_delsS�� �'�� �$�3�$�q�q�q�&�(9�4�9�S��U�V�V�Q�Q�Q�Y�;O�P�P�� � � � �Q�� � � � rLc��|�|��}|�|dd�d|�f||dd�|d�f��Sr$)r r�)r)r r*s r+�_eval_col_insertz!MutableRepMatrix._eval_col_insert�sI��� � �%� � ���{�{�4����$�3�$��<���Q�Q�Q�s�t�t�V� �=�=�=rLc��|�|��}|�|d|�dd�f|||d�dd�f��Sr$)r r�)r)r#r*s r+�_eval_row_insertz!MutableRepMatrix._eval_row_insert�sI��� � �%� � ���{�{�4����Q�Q�Q��<���S�T�T�!�!�!�V� �=�=�=rLc�f�t|j��D]}||||f|��|||f<�dS)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�rX)r)ri�frhs r+�col_opzMutableRepMatrix.col_op�sJ��(�t�y�!�!� *� *�A���4��1��:�q�)�)�D��A��J�J� *� *rLc�t�td|j��D]!}|||f|||fc|||f<|||f<�"dS)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 rNr*�r)rhri�ks r+�col_swapzMutableRepMatrix.col_swap��W��0�q�$�)�$�$� <� <�A�%)�!�Q�$�Z��a��d�� "�D��A��J��Q��T� � � <� <rLc�f�t|j��D]}||||f|��|||f<�dS)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�rY)r)rhr+ris r+�row_opzMutableRepMatrix.row_op�sJ��,�t�y�!�!� *� *�A���4��1��:�q�)�)�D��A��J�J� *� *rLc�X�t|j��D]}|||fxx|zcc<�dS)aMultiply 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]]) Nr3)r)rh�factorris r+�row_multzMutableRepMatrix.row_mult�sC���t�y�!�!� � �A� ��1��I�I�I�� �I�I�I�I� � rLc�n�t|j��D]}|||fxx||||fzz cc<� dS)aAdd 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]]) Nr3)r)�s�tr/ris r+�row_addzMutableRepMatrix.row_add�sO���t�y�!�!� %� %�A� ��1��I�I�I��4��!��9�� $�I�I�I�I� %� %rLc�t�td|j��D]!}|||f|||fc|||f<|||f<�"dS)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 rNr3r.s r+�row_swapzMutableRepMatrix.row_swap�r1rLc�v�t|j��D]#}||||f|||f��|||f<�$dS)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 Nr3)r)rhr/r+ris r+� zip_row_opzMutableRepMatrix.zip_row_opsR��,�t�y�!�!� 3� 3�A���4��1��:�t�A�q�D�z�2�2�D��A��J�J� 3� 3rLc��t|��stdt|��z���|�|t|��|����S)aiCopy 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.)rr/rd� copyin_matrix)r)r�r�s r+� copyin_listzMutableRepMatrix.copyin_list/sW��D�5�!�!� Z��J�T�RW�[�[�X�Y�Y� Y��!�!�#�z�t�D�z�z�%�'8�'8�9�9�9rLc�*�|�|��\}}}}|j}||z ||z } }||| fkrttd�����t |j��D].} t |j��D]} || | f|| |z| |zf<��/dS)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�rrr�rXrY) r)r�r��rlo�rhi�clo�chir��dr�dcrhris r+rAzMutableRepMatrix.copyin_matrixUs���F"�_�_�S�1�1���S�#�s�� ���s��C�#�I�B�� �R��H� � ��Z�)O�P�P�Q�Q� Q��u�z�"�"� 5� 5�A��5�:�&�&� 5� 5��).�q�!�t���Q��W�a�#�g�%�&�&� 5� 5� 5rLc�����t�����s&tj�jt���_dS��fd�t �j��D��}t|�jt���_dS)aNFill 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�l��i|]0}|t�t�j�������1Sr.)r_�fromkeysr�rY)rQrhr)r�s ��r+� <dictcomp>z)MutableRepMatrix.fill.<locals>.<dictcomp>�s3���`�`�`�!�A�t�}�}�U�4�9�-=�-=�u�E�E�`�`�`rLN)r rr�r�rr"r�rX)r)r�rfs`` r+�fillzMutableRepMatrix.fill�su����>������ F�$�*�4�:�u�=�=�D�I�I�I�`�`�`�`�`�u�UY�U^�O_�O_�`�`�`�L�$�\�4�:�u�E�E�D�I�I�IrL)rrrr�is_zerorrr r|r3rrr!r$r&r(r,r0r4r7r;r=r?rBrArO� __classcell__)rs@r+r r "s��������M�M��G�)�)�)��"� !� !� !� !��[� !�������[�� /�/�/����,/�,/�,/�\������>�>�>�>�>�>�*�*�*�.<�<�<�6*�*�*�4 � � �$%�%�%�$<�<�<�63�3�3�2$:�$:�$:�L-5�-5�-5�^$F�$F�$F�$F�$F�$F�$FrLr c�� � � �t|t���r�|\}} |j�t |��t |����S#t t f$�r1t|t��r|jrt|t��ra|jsZ|dkdus.||j dkdus|dkdus||j dkdurtd���ddl m }||||��cYSt|t��rt|j��|}nt!|��rn|g}t|t��rt|j��|}nt!|��rn|g}|�||��cYSwxYw|j \}� |� zsg|S|jj� � j}t|t��}|r&� � fd�t|� z��|D��}n&� jt-t |��� ���g}|t.kr|j� � fd�|D��}|r|S|dS)a2Return 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] rTrzindex out of boundary)� MatrixElementc�@��g|]}�jt|������Sr.)�getitemra)rQrgrYr8s ��r+� <listcomp>z&_getitem_RepMatrix.<locals>.<listcomp>�s*���U�U�U��k�c�k�6�!�T�?�?�3�U�U�UrLc�&��g|] }�|����Sr.r.)rQ�valrqs �r+rVz&_getitem_RepMatrix.<locals>.<listcomp>�s!���6�6�6��h�h�s�m�m�6�6�6rL)r%�tupler"� getitem_sympy�index_r/� IndexErrorr� is_numberr�r��"sympy.matrices.expressions.matexprrS�slicer�rXrrYr�r8r1rUrarrq) r)r�rhrirSrXr1�is_slicermrYr8rqs @@@r+r�r��s������H�#�u���2����1� &��9�*�*�6�!�9�9�f�Q�i�i�@�@� @���:�&� &� &� &��1�d�#�#� 1�A�K� 1�Z��4�=P�=P� 1�YZ�Yd� 1���U�t�O�O�!�t�z�!�}�*<��)E�)E���U�t�O�O�!�t�z�!�}�*<��)E�)E�$�%<�=�=�=�L�L�L�L�L�L�$�}�T�1�a�0�0�0�0�0��!�U�#�#� ��$�)�$�$�Q�'����Q��� ���C���!�U�#�#� ��$�)�$�$�Q�'����Q��� ���C���<�<��1�%�%� %� %� %�) &����0�Z� ��d��d�{� ��c�7�N��i�m������c�5�)�)�� � ?�U�U�U�U�U�U�4�$�;�=O�=O�PS�=T�U�U�U�F�F�!�c�k�6�&��+�+�t�#<�#<�=�>�F� �U�?�?���H�6�6�6�6�v�6�6�6�F� � ��M��!�9� s�4A�B"F�9BF�FN)1� collectionsr�operatorrr[�sympy.core.exprr�sympy.core.kindrrr�sympy.core.numbersr r �sympy.core.sympifyr r �sympy.core.singletonr �sympy.polys.domainsrrrr�sympy.polys.matricesr�sympy.polys.matrices.exceptionsr�sympy.polys.polyerrorsr�sympy.utilities.exceptionsr�sympy.utilities.iterablesr�sympy.utilities.miscrr� exceptionsrrr� matrixbaserrr�rr!r r�r.rLr+�<module>rqs��#�#�#�#�#�#�$�$�$�$�$�$� � � � � � �;�;�;�;�;�;�;�;�;�;�0�0�0�0�0�0�0�0�5�5�5�5�5�5�5�5�"�"�"�"�"�"�1�1�1�1�1�1�1�1�1�1�1�1�-�-�-�-�-�-�F�F�F�F�F�F�1�1�1�1�1�1�@�@�@�@�@�@�1�1�1�1�1�1�3�3�3�3�3�3�3�3�R�R�R�R�R�R�R�R�R�R�+�+�+�+�+�+�+�+�������H�H�H�H�H� �H�H�H�VFF�FF�FF�FF�FF�y�FF�FF�FF�R V�V�V�V�VrL
Memory