K it2ddlmZddlmZddlmZddlmZm Z m Z ddl m Z m Z ddlmZmZddlmZddlmZmZmZmZdd lmZdd lmZdd lmZmZdd lm Z dd l!m"Z"ddl#m$Z$m%Z%ddl&m'Z'm(Z(m)Z)ddl*m+Z+m,Z,ddl-m.Z.Gdde,Z/Gdde/Z0dZ1y)) defaultdict)index)Expr)Kind NumberKind UndefinedKind)IntegerRational)_sympify SympifyError)S)ZZQQGFEXRAW) DomainMatrix)DMNonInvertibleMatrixError)CoercionFailed NotInvertible)sympy_deprecation_warning) is_sequence) filldedentas_int) ShapeErrorNonSquareMatrixErrorNonInvertibleMatrixError)classof MatrixBase) MatrixKindcReZdZUdZeed<dZd)dZedZ edZ edZ ed Z d Z d Zd Zed ZdZdZdZdZedefdZdZdZdZdZdZdZdZdZedZ edZ!dZ"dZ#d Z$d!Z%d"Z&d#Z'd$Z(d*d%Z)d&Z*d+d'Z+d+d(Z,y), 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. _repct|ts" t|}t|tstS|j j |j S#t$r tcYSwxYwN) isinstancer"r r NotImplementedr#unify_eqselfothers ^/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/sympy/matrices/repmatrix.py__eq__zRepMatrix.__eq__5s\%+ & eY/%%yy!!%**--   &%% &s AA*)A*Nc |(|r td|jj|S|j}|j}|s>|jr|j S|j r |jtS|jdi|}|jjr|jt}|S#t$rY|j SwxYw)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 z,Options cannot be used with domain parameter) TypeErrorr# convert_todomainis_ZZcopyis_QQrr choose_domainis_EXr)r*r2kwargsrepdomrep_doms r,to_DMzRepMatrix.to_DMAsV   NOO99''/ /iijj yyxxz!>>"-- $###-f- >>  ((/G&xxz!s.C CCcN|j}t|}|tk7rZ|jr|}n|jrt }nt}||k7r|j |}|}|tk7r|j|}|tk(rt|tstdddd||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.9deprecated-non-expr-in-matrixdeprecated_since_versionactive_deprecations_target stacklevel) r2r r is_Integer is_Rationalrr1 from_sympyr&rr)clsr9elementr2 new_domains r,_unify_element_sympyzRepMatrix._unify_element_sympys7# U?!!# $$ " V#nnZ0#$//8 U?:gt#< % */+J G|ctd|Dstddddt|||ft}td|Dr>td|Dr|j t }|S|j t }|S) Nc3<K|]}t|tywr%) issubclassr.0typs r, z1RepMatrix._dod_to_DomainMatrix..s:S:c4(:r>r?r@rBc3<K|]}t|tywr%)rPr rQs r,rTz1RepMatrix._dod_to_DomainMatrix..s:Sz#x(:rUc3<K|]}t|tywr%)rPr rQs r,rTz1RepMatrix._dod_to_DomainMatrix..s=:c7+=rU)allrrrr1rr)rIrowscolsdodtypesr9s r,_dod_to_DomainMatrixzRepMatrix._dod_to_DomainMatrixs:E:: % */+J 3t e4 :E: :=u==nnR( nnR( rMctt}t|D]"\}}|dk7s t||\}}||||<$t t t |} |j|||| } | SNr)rdict enumeratedivmodsetmaptyper^) rIrZr[ flat_list elements_dodnrJijr]r9s r,_flat_list_to_DomainMatrixz$RepMatrix._flat_list_to_DomainMatrixsx#4( #I. -JAw!|a1%, Q" - Ci()&&tT<G rMctt}|jD]\\}}}|dk7s||||<tt t |j }|j||||} | Sr`)rraitemsrdrerfvaluesr^) rIrZr[smatrhrjrkrJr]r9s r,_smat_to_DomainMatrixzRepMatrix._smat_to_DomainMatrixst#4( #zz| -OFQG!|%, Q" -Cdkkm,-&&tT<G rMcR|jjjSr%)r#to_sympy to_list_flatr*s r,flatzRepMatrix.flatsyy!!#0022rMcR|jjjSr%)r#rsto_listrus r, _eval_tolistzRepMatrix._eval_tolistsyy!!#++--rMcR|jjjSr%)r#rsto_dokrus r, _eval_todokzRepMatrix._eval_todoksyy!!#**,,rMcF|j|j|||Sr%)_fromreprq)rIrZr[doks r,_eval_from_dokzRepMatrix._eval_from_doks ||C55dD#FGGrMc4t|jSr%)list_eval_iter_valuesrus r, _eval_valueszRepMatrix._eval_valuessD**,--rMc|j}|j}|j}|jst |j |}|Sr%)r#r2 iter_valuesis_EXRAWrers)r*r9Kros r,rzRepMatrix._eval_iter_valuess<ii JJ"zzV,F rMc|j}|j}|j|j}|js fd|D}|S)Nc38K|]\}}||fywr%r/)rRrjvrss r,rTz-RepMatrix._eval_iter_items.. s8$!Qa!%8s)r#r2rs iter_itemsr)r*r9rrnrss @r,_eval_iter_itemszRepMatrix._eval_iter_itemss@ii JJ:: zz8%8E rMcT|j|jjSr%r~r#r4rus r,r4zRepMatrix.copy }}TYY^^-..rMreturncH|jj}|ttfvrt}t|S|t k(rU|j Dchc]}|j}}t|dk(r|\}t|St}t|Stdcc}w)Nrz%Domain should only be ZZ, QQ or EXRAW) r#r2rrrrrokindlenr RuntimeErrorr )r*r2 element_kindekindss r,rzRepMatrix.kinds!! b"X %L,''u_%)[[]3QVV3E35zQ!& ,'' - ,''FG G 4sBcd}|j}t||j|jzk7rt j j }|xs"tfd|jDS)NFc3<K|]}|jywr%)has)rRvaluepatternss r,rTz&RepMatrix._eval_has..(sJE9599h/Js) todokrrZr[r Zeroranyro)r*rzhasrs ` r, _eval_haszRepMatrix._eval_has s\jjl s8tyy* *66::x(DJsJSZZ\JJJrMctfdtjDsytj jk(S)Nc32K|]}||fdk(yw)rNr/)rRrjr*s r,rTz.RepMatrix._eval_is_Identity..+s=q41:?=sF)rYrangerZrrrus`r,_eval_is_IdentityzRepMatrix._eval_is_Identity*s7=E$)),<==4::< DII--rMcv||jz j|}t|jdk(Sr`)T applyfuncrro)r*simpfuncdiffs r,_eval_is_symmetriczRepMatrix._eval_is_symmetric/s0tvv ((24;;=!Q&&rMcT|j|jjS)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# transposerus r,_eval_transposezRepMatrix._eval_transpose3s "}}TYY00233rMcj|j|jj|jSr%)r~r#vstackr)s r,_eval_col_joinzRepMatrix._eval_col_joinF$}}TYY--ejj9::rMcj|j|jj|jSr%)r~r#hstackr)s r,_eval_row_joinzRepMatrix._eval_row_joinIrrMcX|j|jj||Sr%)r~r#extract)r*rowsListcolsLists r, _eval_extractzRepMatrix._eval_extractLs"}}TYY..xBCCrMct||Sr%)_getitem_RepMatrix)r*keys r, __getitem__zRepMatrix.__getitem__Os!$,,rMc\tj||ft}|j|Sr%)rzerosrr~rIrZr[r9s r, _eval_zeroszRepMatrix._eval_zerosRs'  $r2||C  rMc\tj||ft}|j|Sr%)reyerr~rs r, _eval_eyezRepMatrix._eval_eyeWs'd|R0||C  rMcft||j|j|jzSr%rr~r#r)s r, _eval_addzRepMatrix._eval_add\'tU#,,TYY-CDDrMcft||j|j|jzSr%rr)s r,_eval_matrix_mulzRepMatrix._eval_matrix_mul_rrMc|jj|j\}}|j|}t||j |Sr%)r#unifymul_elementwiserr~)r*r+selfrepotherrepnewreps r,_eval_matrix_mul_elementwisez&RepMatrix._eval_matrix_mul_elementwisebsE IIOOEJJ7((2tU#,,V44rMc|j|j|\}}|j|j|Sr%)rLr#r~ scalarmulr*r+r9s r,_eval_scalar_mulzRepMatrix._eval_scalar_mulgs4..tyy%@ U}}S]]5122rMc|j|j|\}}|j|j|Sr%)rLr#r~ rscalarmulrs r,_eval_scalar_rmulzRepMatrix._eval_scalar_rmulks4..tyy%@ U}}S^^E233rMc^|j|jjtSr%)r~r#rabsrus r, _eval_AbszRepMatrix._eval_Absos }}TYY00566rMc|j}|j}|ttfvr|j S|j |j dS)Nc"|jSr%) conjugate)rs r,z+RepMatrix._eval_conjugate..xs rM)r#r2rrr4r~r)r*r9r2s r,_eval_conjugatezRepMatrix._eval_conjugatersEii b"X 99; ==/F!GH HrMc|jt|ddk7ryd}t|jD]K}t|jD]1}|||fj |||f|}|dury|dus+|dus0|}3M|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)rgetattrrrZr[equals)r*r+failing_expressionrvrjrkanss r,rzRepMatrix.equalszs8 ::6 6 tyy! A499% 1a4j''ad 5GH%< _tB    rMc|js t t|}t |d} |j |}|jr! |j}|jS|j\}} d|z } || z}|jS#t$r t dwxYw#t$r tdwxYw#t$r}d|d}t||d}~wwxYw#t$rd|d}t|wxYw) 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 )Nr) is_squarerr ValueErrorr0rr<ris_Fieldinvrradj_detr to_Matrix) MmrdMdMiexcmsgdMadjdetdetinvs r,inv_modzRepMatrix.inv_mods3({{&( ( Eq A qE " IB :: =ffh}}JE3 4S&.C}}3 ECD D E IGH H I . =6qc;.s3< =! 46qc;.s33 4s: BB5C C0B25C  C-C((C-0D ctjt|}|jj t }|j |}|j|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)rrHr r#r1rlllr~)r*rrbasiss r,rz RepMatrix.lllsI: huo. YY ! !" %U#}}U##rMctjt|}|jj t }|j |\}}|j|}|j|}||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)rrHr r#r1r lll_transformr~)r*rrr transformBrs r,rzRepMatrix.lll_transformshT huo. YY ! !" %++%+8y MM%  MM) $!t rMr%)F)g?)-__name__ __module__ __qualname____doc__r__annotations__r-r< classmethodrLr^rlrqrvryr|rrrrr4propertyr rrrrrrrrrrrrrrrrrrrrrrr/rMr,r"r"sO6  .M^$$L2    3.-HH./ (j ( (K. '4&;;D-!!!!EE5 347I'R2h $D/rMr"ceZdZdZdZdZedddZefdZdZ d Z d Z d Z d Z d ZdZdZdZdZdZdZdZdZdZdZdZxZS)MutableRepMatrixzCMutable matrix based on DomainMatrix as the internal representationFc&|j|i|Sr%)_new)rIargsr8s r,__new__zMutableRepMatrix.__new__6ssxx(((rMTr4c|dur t|dk7r td|\}}}n!|j|i|\}}}t|}|j |||}|j |S)NFzA'copy=False' requires a matrix be initialized as rows,cols,[list])rr0_handle_creation_inputsrrlr~)rIr4rr8rZr[rgr9s r,rzMutableRepMatrix._new9sx 5=4yA~ cdd$( !D$ $?C$?$?$P$P !D$ YI,,T4C||C  rMcft||}|j\|_|_||_|Sr%)superrrrZr[r#)rIr9obj __class__s r,r~zMutableRepMatrix._fromrepIs/goc" YY#( rMcT|j|jjSr%rrus r,r4zMutableRepMatrix.copyPrrMc"|jSr%rrus r, as_mutablezMutableRepMatrix.as_mutableSsyy{rMc|j||}|R|\}}}|j|j|\|_}|jjj |||yy)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)_setitemrLr#r9setitem)r*rrrrjrks r, __setitem__zMutableRepMatrix.__setitem__VsaP]]3 & >KAq%#88EJ DIu IIMM ! !!Q . rMctj|jddd|f|jdd|dzdf|_|xjdzc_yNr)rrr#r[)r*cols r, _eval_col_delzMutableRepMatrix._eval_col_delsG '' !DSD&(9499Qs1uvX;NO  Q rMctj|jd|ddf|j|dzdddf|_|xjdzc_yr#)rrr#rZ)r*rows r, _eval_row_delzMutableRepMatrix._eval_row_delsG '' $3$q&(9499SUVQY;OP  Q rMcn|j|}|j|ddd|f||dd|dfSr%)rr)r*r$r+s r,_eval_col_insertz!MutableRepMatrix._eval_col_inserts9 % {{4$3$<QstV ==rMcn|j|}|j|d|ddf|||dddfSr%)rr)r*r'r+s r,_eval_row_insertz!MutableRepMatrix._eval_row_inserts9 % {{4Q<ST!V ==rMc^t|jD]}||||f||||f<y)aIn-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 NrrZ)r*rkfrjs r,col_opzMutableRepMatrix.col_ops8(tyy! *A41:q)DAJ *rMcltd|jD]}|||f|||fc|||f<|||f<y)aSwap 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*rjrkks r,col_swapzMutableRepMatrix.col_swapJ0q$))$ >> 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 Nrr[)r*rjr/rks r,row_opzMutableRepMatrix.row_ops8,tyy! *A41:q)DAJ *rMcVt|jD]}|||fxx|zcc<y)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]]) Nr7)r*rjfactorrks r,row_multzMutableRepMatrix.row_mults.tyy! A 1I I rMcft|jD]}|||fxx||||fzz cc<y)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]]) Nr7)r*str3rks r,row_addzMutableRepMatrix.row_adds:tyy! %A 1I4!9 $I %rMcltd|jD]}|||f|||fc|||f<|||f<y)aSwap 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 rNr7r2s r,row_swapzMutableRepMatrix.row_swapr5rMcht|jD]}||||f|||f|||f<y)aIn-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 Nr7)r*rjr3r/rks r, zip_row_opzMutableRepMatrix.zip_row_ops@,tyy! 3A41:tAqDz2DAJ 3rMct|stdt|z|j|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.)rr0rf copyin_matrix)r*rrs r, copyin_listzMutableRepMatrix.copyin_list8sAD5!JTRW[XY Y!!#ztDz%'899rMc|j|\}}}}|j}||z ||z } }||| fk7rttdt |j D].} t |j D]} || | f|| |z| |zf<0y)aCopy 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) key2boundsrrrrrZr[) r*rrrlorhiclochirdrdcrjrks r,rEzMutableRepMatrix.copyin_matrix^sF"__S1S#s sC#IB RH Z)OPQ Quzz" 5A5::& 5).q!tQWa#g%& 5 5rMc Pt|}|s*tj|jt|_yt |jDcic],}|tjt |j|.}}t||jt|_ycc}w)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 N) r rrrrr#rrZrafromkeysr[)r*rrjrhs r,fillzMutableRepMatrix.fillsz>$**4::u=DIOTUYU^U^O_`!At}}U499-=uEE`L`$\4::uEDIas1B#)rrrr is_zerorr rr~r4rr!r%r(r*r,r0r4r8r;r?rArCrFrErQ __classcell__)rs@r,rr+sMG)" ! ! /,/\>>*.<6*4 $%$<632$:L-5^$FrMrc t|tr4|\}} |jjt |t |S|j\}}||zsg|S|jj&}|j(}t|t} | r6t||z|D cgc]} |j*t-| |} } n#|j*t-t ||g} |t.k7r!|j0} | D cgc] } | |  } } | r| S| dS#t t f$rt|tr |jrt|tr_|jsS|dkdus/||jdk\dus|dkdus||jdk\dur tdddl m }||||cYSt|trt|j|}nt!|rn|g}t|trt|j"|}nt!|rn|g}|j%||cYSwxYwcc} wcc} w)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) MatrixElement)r&tupler# getitem_sympyindex_r0 IndexErrorr is_numberrr"sympy.matrices.expressions.matexprrUslicerrZrr[rr9r2getitemrcrrs)r*rrjrkrUrZr[r9r2is_slicerirorsvals r,rrsH#u1 &99**6!9fQi@ @2ZZ dd{c7Niimmc5) =B4$;=OPS=TUkckk6!T?3UFU!ckk6&+t#<=>F U?H/56hsm6F6 M!9 ]:& &1d#AKKZ4=PYZYdYdUtO!tzz!}*<)EUtO!tzz!}*<)E$%<==L$T1a00!U#$))$Q'QC!U#$))$Q'QC<<1% %) &FV 7s%-D% IIBH>9BH>=H>N)2 collectionsroperatorrrXsympy.core.exprrsympy.core.kindrrrsympy.core.numbersr r sympy.core.sympifyr r sympy.core.singletonr sympy.polys.domainsrrrrsympy.polys.matricesrsympy.polys.matrices.exceptionsrsympy.polys.polyerrorsrrsympy.utilities.exceptionsrsympy.utilities.iterablesrsympy.utilities.miscrr exceptionsrrr matrixbaserrrr r"rrr/rMr,rpsg#$ ;;05"11-F@@13RR+Q QhFFyFFR VrM