K irtddlmZddlmZddlmZddlmZddlm Z m Z m Z GddeZ Gd d eZ y ) )S)_sympify)KroneckerDelta) MatrixExpr) ZeroMatrixIdentity OneMatrixcneZdZdZfdZedZedZdZdZ dZ dZ e xZ Z d Zd ZxZS) PermutationMatrixaA Permutation Matrix Parameters ========== perm : Permutation The permutation the matrix uses. The size of the permutation determines the matrix size. See the documentation of :class:`sympy.combinatorics.permutations.Permutation` for the further information of how to create a permutation object. Examples ======== >>> from sympy import Matrix, PermutationMatrix >>> from sympy.combinatorics import Permutation Creating a permutation matrix: >>> p = Permutation(1, 2, 0) >>> P = PermutationMatrix(p) >>> P = P.as_explicit() >>> P Matrix([ [0, 1, 0], [0, 0, 1], [1, 0, 0]]) Permuting a matrix row and column: >>> M = Matrix([0, 1, 2]) >>> Matrix(P*M) Matrix([ [1], [2], [0]]) >>> Matrix(M.T*P) Matrix([[2, 0, 1]]) See Also ======== sympy.combinatorics.permutations.Permutation cddlm}t|}t||st dj |t |||S)Nr Permutationz({} must be a SymPy Permutation instance.) sympy.combinatorics.permutationsrr isinstance ValueErrorformatsuper__new__)clspermr __class__s l/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/sympy/matrices/expressions/permutation.pyrzPermutationMatrix.__new__;sI@~$ ,:AA$GI IwsD))c<|jdj}||fSNr)argssize)selfrs rshapezPermutationMatrix.shapeEsyy|  d|rc4|jdjSr)r is_Identityrs rr"zPermutationMatrix.is_IdentityJsyy|'''rc H|jrt|jS|S)N)r"r rows)rhintss rdoitzPermutationMatrix.doitNs   DII& & rc V|jd}t|j||Sr)rrapply)rijkwargsrs r_entryzPermutationMatrix._entrySs$yy|djjmQ//rcTt|jd|zjSr)r rr')rexps r _eval_powerzPermutationMatrix._eval_powerWs# 1!45::< cycles_picksabcflagcyclelmtempppick new_cyclesr* new_cyclemats r _eval_rewrite_as_BlockDiagMatrixz2PermutationMatrix._eval_rewrite_as_BlockDiagMatrixgs@0yy|00 1a%! EE AE Aq51q5=D!7DAA ''0FAq51uA ) E*$++D1$aC E*Q1uA ) E*$++D1$aC E*QC! H  DJA ,12qQU2 2!!),SZ  FAz*D#D)C KK  %%3s8 F)__name__ __module__ __qualname____doc__rpropertyr r"r'r-r0r3_eval_transpose _eval_adjointr:rP __classcell__rs@rr r s`/b*(( 0=5'43Om">&rr c^eZdZdZej ffd ZddZedZ dZ dZ xZ S) MatrixPermuteazSymbolic representation for permuting matrix rows or columns. Parameters ========== perm : Permutation, PermutationMatrix The permutation to use for permuting the matrix. The permutation can be resized to the suitable one, axis : 0 or 1 The axis to permute alongside. If `0`, it will permute the matrix rows. If `1`, it will permute the matrix columns. Notes ===== This follows the same notation used in :meth:`sympy.matrices.matrixbase.MatrixBase.permute`. Examples ======== >>> from sympy import Matrix, MatrixPermute >>> from sympy.combinatorics import Permutation Permuting the matrix rows: >>> p = Permutation(1, 2, 0) >>> A = Matrix([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) >>> B = MatrixPermute(A, p, axis=0) >>> B.as_explicit() Matrix([ [4, 5, 6], [7, 8, 9], [1, 2, 3]]) Permuting the matrix columns: >>> B = MatrixPermute(A, p, axis=1) >>> B.as_explicit() Matrix([ [2, 3, 1], [5, 6, 4], [8, 9, 7]]) See Also ======== sympy.matrices.matrixbase.MatrixBase.permute cddlm}t|}|jst dj |t|}t |tr|jd}t ||st dj |t|}|dvr t d|j|}||jk7r |j|}t|5||||S#t$rt dj |||wxYw)Nrrz#{} must be a SymPy matrix instance.z>{} must be a SymPy Permutation or a PermutationMatrix instance)rrzThe axis must be 0 or 1.zsSize does not match between the permutation {} and the matrix {} threaded over the axis {} and cannot be converted.)rrr is_Matrixrrrr rr rresizerr)rrOraxisrmat_sizers rrzMatrixPermute.__new__s@sm}}5<rss4'*44\& \&~G