+
    iQ9                         ^ RI Ht ^ RIHt ^ RIHt ^ RIHt ^ RIH	t	 ^RI
Ht ^RIHtHt ^RIHt ^R	IHtHtHtHt ^R
IHtHt  ! R R]4      t ! R R]]4      t]tR# )    )Callable)Dict)sympy_deprecation_warningis_sequence)as_int)
MatrixBase)MutableRepMatrix	RepMatrix)_iszero)_liupc _row_structure_symbolic_cholesky_cholesky_sparse_LDLdecomposition_sparse)_lower_triangular_solve_sparse_upper_triangular_solve_sparsec                     a a ] tR t^t oRt]V 3R l4       t]R 4       tR t	R t
R tR tR tR	 tR
 tR tRR ltRR lt]! ]RRR4      t]! ]RRR4      tR tR tRR ltRR ltR tR t]P                  ]n        ]P                  ]n        ]P                  ]n        ]P                  ]n        ]P                  ]n        ]P                  ]n        RtVt V ;t!# )SparseRepMatrixa  
A sparse matrix (a matrix with a large number of zero elements).

Examples
========

>>> from sympy import SparseMatrix, ones
>>> SparseMatrix(2, 2, range(4))
Matrix([
[0, 1],
[2, 3]])
>>> SparseMatrix(2, 2, {(1, 1): 2})
Matrix([
[0, 0],
[0, 2]])

A SparseMatrix can be instantiated from a ragged list of lists:

>>> SparseMatrix([[1, 2, 3], [1, 2], [1]])
Matrix([
[1, 2, 3],
[1, 2, 0],
[1, 0, 0]])

For safety, one may include the expected size and then an error
will be raised if the indices of any element are out of range or
(for a flat list) if the total number of elements does not match
the expected shape:

>>> SparseMatrix(2, 2, [1, 2])
Traceback (most recent call last):
...
ValueError: List length (2) != rows*columns (4)

Here, an error is not raised because the list is not flat and no
element is out of range:

>>> SparseMatrix(2, 2, [[1, 2]])
Matrix([
[1, 2],
[0, 0]])

But adding another element to the first (and only) row will cause
an error to be raised:

>>> SparseMatrix(2, 2, [[1, 2, 3]])
Traceback (most recent call last):
...
ValueError: The location (0, 2) is out of designated range: (1, 1)

To autosize the matrix, pass None for rows:

>>> SparseMatrix(None, [[1, 2, 3]])
Matrix([[1, 2, 3]])
>>> SparseMatrix(None, {(1, 1): 1, (3, 3): 3})
Matrix([
[0, 0, 0, 0],
[0, 1, 0, 0],
[0, 0, 0, 0],
[0, 0, 0, 3]])

Values that are themselves a Matrix are automatically expanded:

>>> SparseMatrix(4, 4, {(1, 1): ones(2)})
Matrix([
[0, 0, 0, 0],
[0, 1, 1, 0],
[0, 1, 1, 0],
[0, 0, 0, 0]])

A ValueError is raised if the expanding matrix tries to overwrite
a different element already present:

>>> SparseMatrix(3, 3, {(0, 0): ones(2), (1, 1): 2})
Traceback (most recent call last):
...
ValueError: collision at (1, 1)

See Also
========
DenseMatrix
MutableSparseMatrix
ImmutableSparseMatrix
c                  <a \        V4      ^8X  d_   \        V^ ,          \        4      '       dB   V^ ,          P                  pV^ ,          P                  pV^ ,          P                  4       oW4S3# / o\        V4      ^8X  d   V^ ,          f   RRV^,          .p\        V4      ^8X  EdN   VR,          w  rVYVu;J d   f   M MR;r4M6RWV39   d   \        R4      h\        V^ ,          4      \        V^,          4      rC\        V^,          \        4      '       d   V^,          pRW439   d   \        RP                  W44      4      h\        V4       Uu. uF  qP                  V4      NK  	  p	p\        V4       U
u. uF  qP                  V
4      NK  	  pp
V	 F;  pV F2  p
V P                  V! W4      4      pWP                  8w  g   K,  VSW3&   K4  	  K=  	  W4S3# \        V^,          \        \        34      '       Ed   V3R lpV^,          P                  4        F  w  w  rVp\        V\        4      '       dC   VP                  4       P                  4        F  w  w  rpV! WX,           Wj,           V4       K   	  K`  \        V\         \"        34      '       dC   V P$                  ! V3/ VB w   poS F#  w  rV! WX,           Wj,           SW3,          4       K%  	  K  V P                  V4      pV! WVV P                  V4      4       K  	  EM-\'        V^,          4      '       Ed   \(        ;QJ d#    R V^,           4       F  '       g   K   RM	  RM! R V^,           4       4      '       * pV'       g    V P$                  ! V^,          3/ VB w   poMV^,          p\        V4      W4,          8w  d%   \        R	P                  \        V4      W44      4      h\        V4       FT  p\        V4       FB  p
VW,          V
,           ,          pV P                  V4      pWP                  8w  g   K<  VSW3&   KD  	  KV  	  VfX   SP+                  4       pV'       d   \-        R
 V 4       4      ^,           M^ pV'       d   \-        R V 4       4      ^,           M^ pMdSP+                  4        FP  w  rV'       d   W8  g   V
'       g   K  W8  g   K%  \        RP                  W3^ V^,
          ^ V^,
          4      4      h	  W4S3# \        V4      ^8X  d   \        V^ ,          \         \"        34      '       d   V^ ,          p^ p\/        V4       Fu  w  pp\        V\         \"        34      '       g   V.p\/        V4       F,  w  rWP                  8w  g   K  V P                  V4      SW3&   K.  	  \-        V\        V4      4      pKw  	  V'       d   \        V4      M^ pTpW4S3# \0        SV `H  ! V!  w  r4p\        V4       FC  p\        V4       F1  p
VWH,          V
,           ,          pWP                  8w  g   K+  VSW3&   K3  	  KE  	  W4S3# u upi u up
i )   N:N   Nz*Pass rows=None and no cols for autosizing.z2{} and {} must be integers for this specification.c           	         < V'       dE   W3S9   d5   VSW3,          8w  d&   \        R P                  W3VSW3,          4      4      hVSW3&   R# R# )z)There is a collision at {} for {} and {}.N)
ValueErrorformat)ijvsmats   &&&S/var/www/html/photoedit/myenv/lib/python3.14/site-packages/sympy/matrices/sparse.pyupdate7SparseRepMatrix._handle_creation_inputs.<locals>.update   sS    6T>a4:o", K!'4:!>#  &'QT
     c              3   8   "   T F  p\        V4      x  K  	  R # 5iNr   ).0r   s   & r   	<genexpr>:SparseRepMatrix._handle_creation_inputs.<locals>.<genexpr>   s     ?w!{1~~ws   TFzMThe length of the flat list ({}) does not match the specified size ({} * {}).c              3   *   "   T F	  w  rVx  K  	  R # 5ir$    )r%   r_s   &  r   r&   r'           .1   c              3   *   "   T F	  w  rVx  K  	  R # 5ir$   r)   )r%   r+   cs   &  r   r&   r'      r,   r-   z?The location {} is out of the designated range[{}, {}]x[{}, {}])len
isinstancer	   rowscolstodokr   r   r   r   range_sympifyzerodictr   itemslisttuple_handle_creation_inputsr   anykeysmax	enumeratesuper)clsargskwargsr2   r3   r*   r/   opr   row_indicesr   col_indicesvaluer    r   vvr+   flat	flat_listr>   rowmatr   	__class__s   &*,                   @r   r<   'SparseRepMatrix._handle_creation_inputsk   s+   t9>ja*==7<<D7<<D7==?Dt##t9>d1go$Q(Dt9>8DA~~""t! @B B $DG_fT!Wod$q'8,,!WD<'$))/);= = 9>dD1||AD8=dD1||AD$A( #RX 6 HH,).DJ ) % 4''DGdD\22' "&aIFQA!!Z00*+'')//*;JFQB"15!%4 +<#Ae}55%(%@%@%Mf%M
1d$(DA"15!%ad< %)  LLOqS\\!_5 "1 T!W%%3?tAw?333?tAw???33DGFvF Aq$ !%QI9~4(B#VC	ND?  #4[!&tA$-afqj$9E$'LL$7E$0-2QT
	 "- ) |yy{6:s...26:s...2 !IIKDAQY!!	(0#VQFAtaxD1HE  ( t##Y!^
47T5M B BQAA#A,3!#e}55%C&s^EAXX~%(\\"%5QT
 , 3s8$ ' 3q6ADDt## $g=tDOD4[tA
OE(%*QT
 % ! t##A EDs   X<:Yc                >    \        R RRR7       V P                  4       # )z
            The private _smat attribute of SparseMatrix is deprecated. Use the
            .todok() method instead.
            z1.9z$deprecated-private-matrix-attributes)deprecated_since_versionactive_deprecations_target)r   r4   selfs   &r   _smatSparseRepMatrix._smat   s'     	" &+'M	
 zz|r"   c                    V P                  VP                  R R4      VP                  R\        4      VP                  RR4      R7      # )methodLDL
iszerofunctry_block_diagF)rX   rZ   r[   )invgetr   )rT   rD   s   &,r   _eval_inverseSparseRepMatrix._eval_inverse   sD    xxvzz(E:#)::lG#D'-zz2BE'J  L 	Lr"   c                   \        V4      '       g   \        R4      h/ pV P                  4       P                  4        F  w  r4V! V4      pV^ 8w  g   K  WRV&   K  	  V P	                  V P
                  V P                  V4      # )zApply a function to each element of the matrix.

Examples
========

>>> from sympy import SparseMatrix
>>> m = SparseMatrix(2, 2, lambda i, j: i*2+j)
>>> m
Matrix([
[0, 1],
[2, 3]])
>>> m.applyfunc(lambda i: 2*i)
Matrix([
[0, 2],
[4, 6]])

z`f` must be callable.)callable	TypeErrorr4   r9   _newr2   r3   )rT   fdokkr   fvs   &&    r   	applyfuncSparseRepMatrix.applyfunc   so    $ {{344
 JJL&&(DA1BQwA )
 yyDIIs33r"   c                    ^RI Hp V! V 4      # )z,Returns an Immutable version of this Matrix.)ImmutableSparseMatrix)	immutablerk   )rT   rk   s   & r   as_immutableSparseRepMatrix.as_immutable  s    4$T**r"   c                    \        V 4      # )zReturns a mutable version of this matrix.

Examples
========

>>> from sympy import ImmutableMatrix
>>> X = ImmutableMatrix([[1, 2], [3, 4]])
>>> Y = X.as_mutable()
>>> Y[1, 1] = 5 # Can set values in Y
>>> Y
Matrix([
[1, 2],
[3, 5]])
)MutableSparseMatrixrS   s   &r   
as_mutableSparseRepMatrix.as_mutable$  s     #4((r"   c                    \        V P                  4       P                  4       R R7       Uu. uF  p\        WV,          3,           4      NK  	  up# u upi )a3  Returns a column-sorted list of non-zero elements of the matrix.

Examples
========

>>> from sympy import SparseMatrix
>>> a=SparseMatrix(((1, 2), (3, 4)))
>>> a
Matrix([
[1, 2],
[3, 4]])
>>> a.CL
[(0, 0, 1), (1, 0, 3), (0, 1, 2), (1, 1, 4)]

See Also
========

sympy.matrices.sparse.SparseMatrix.row_list
c                 *    \        \        V 4      4      # r$   )r:   reversed)rf   s   &r   <lambda>*SparseRepMatrix.col_list.<locals>.<lambda>I  s    Y]^fgh^iYjr"   key)sortedr4   r>   r;   rT   rf   s   & r   col_listSparseRepMatrix.col_list5  sB    ( 06djjl6G6G6IOj/kl/k!a7*n%/kllls   "Ac                4    \        V P                  4       4      # )z2Returns the number of non-zero elements in Matrix.)r0   r4   rS   s   &r   nnzSparseRepMatrix.nnzK  s    4::<  r"   c                    \        V P                  4       P                  4       \        R7       Uu. uF  p\	        WV,          3,           4      NK  	  up# u upi )a2  Returns a row-sorted list of non-zero elements of the matrix.

Examples
========

>>> from sympy import SparseMatrix
>>> a = SparseMatrix(((1, 2), (3, 4)))
>>> a
Matrix([
[1, 2],
[3, 4]])
>>> a.RL
[(0, 0, 1), (0, 1, 2), (1, 0, 3), (1, 1, 4)]

See Also
========

sympy.matrices.sparse.SparseMatrix.col_list
rx   )rz   r4   r>   r:   r;   r{   s   & r   row_listSparseRepMatrix.row_listO  sL    * 4::<$$&D131 +,a7*n%13 	3 3s   "Ac                    W,          # )z"Scalar element-wise multiplicationr)   )rT   scalars   &&r   scalar_multiplySparseRepMatrix.scalar_multiplyf  s
    }r"   c                f    V P                   pW0,          P                  VR7      V,          V,          # )a  Return the least-square fit to the data.

By default the cholesky_solve routine is used (method='CH'); other
methods of matrix inversion can be used. To find out which are
available, see the docstring of the .inv() method.

Examples
========

>>> from sympy import SparseMatrix, Matrix, ones
>>> A = Matrix([1, 2, 3])
>>> B = Matrix([2, 3, 4])
>>> S = SparseMatrix(A.row_join(B))
>>> S
Matrix([
[1, 2],
[2, 3],
[3, 4]])

If each line of S represent coefficients of Ax + By
and x and y are [2, 3] then S*xy is:

>>> r = S*Matrix([2, 3]); r
Matrix([
[ 8],
[13],
[18]])

But let's add 1 to the middle value and then solve for the
least-squares value of xy:

>>> xy = S.solve_least_squares(Matrix([8, 14, 18])); xy
Matrix([
[ 5/3],
[10/3]])

The error is given by S*xy - r:

>>> S*xy - r
Matrix([
[1/3],
[1/3],
[1/3]])
>>> _.norm().n(2)
0.58

If a different xy is used, the norm will be higher:

>>> xy += ones(2, 1)/10
>>> (S*xy - r).norm().n(2)
1.5

rX   )Tr\   )rT   rhsrX   ts   &&& r   solve_least_squares#SparseRepMatrix.solve_least_squaresj  s+    l FF||6|*1,S00r"   c                   V P                   '       gO   V P                  V P                  8  d   \        R4      hV P                  V P                  8  d   \        R4      hR# V P	                  VR7      P                  V4      # )zReturn solution to self*soln = rhs using given inversion method.

For a list of possible inversion methods, see the .inv() docstring.
zUnder-determined system.z]For over-determined system, M, having more rows than columns, try M.solve_least_squares(rhs).r   N)	is_squarer2   r3   r   r\   multiply)rT   r   rX   s   &&&r   solveSparseRepMatrix.solve  sq    
 ~~~yy499$ !;<<TYY&  "N O O ' 8868*33C88r"   NzAlternate faster representationc                    \        V 4      # r$   )r   rS   s   &r   liupcSparseRepMatrix.liupc  s    d|r"   c                    \        V 4      # r$   )r   rS   s   &r   row_structure_symbolic_cholesky/SparseRepMatrix.row_structure_symbolic_cholesky  s    /55r"   c                    \        WR 7      # )	hermitian)r   rT   r   s   &&r   choleskySparseRepMatrix.cholesky  s    ::r"   c                    \        WR 7      # r   )r   r   s   &&r   LDLdecomposition SparseRepMatrix.LDLdecomposition  s    'BBr"   c                    \        W4      # r$   )r   rT   r   s   &&r   lower_triangular_solve&SparseRepMatrix.lower_triangular_solve      -d88r"   c                    \        W4      # r$   )r   r   s   &&r   upper_triangular_solve&SparseRepMatrix.upper_triangular_solve  r   r"   r)   )rY   )T)"__name__
__module____qualname____firstlineno____doc__classmethodr<   propertyrU   r^   rh   rm   rq   r|   r   r   r   r   r   RLCLr   r   r   r   r   r   r   r   r   r   __static_attributes____classdictcell____classcell__)rN   __classdict__s   @@r   r   r      s
    Sj ~$ ~$@  L
4@+
)"m,!3.71r9 
(D$(I	JB	(D$(I	JB6;C99 /5nnEM.N.V.V#+.>.F.FH.F.N.N.D.L.L".D.L.L""r"   r   c                   0   a  ] tR tRt o ]R 4       tRtV tR# )rp   i  c                r    V P                   ! V/ VB w  r4pV P                  W4V4      pV P                  V4      # r$   )r<   _smat_to_DomainMatrix_fromrep)rB   rC   rD   r2   r3   r   reps   &*,    r   rc   MutableSparseMatrix._new  s=    66GGD''D9||C  r"   r)   N)r   r   r   r   r   rc   r   r   )r   s   @r   rp   rp     s     ! !r"   rp   N)collections.abcr   sympy.core.containersr   sympy.utilities.exceptionsr   sympy.utilities.iterablesr   sympy.utilities.miscr   
matrixbaser	   	repmatrixr
   r   	utilitiesr   decompositionsr   r   r   r   solversr   r   r   rp   SparseMatrixr)   r"   r   <module>r      sT    $ & @ 1 ' " 2  DvMi vMr!/+; ! #r"   