
    (phcN                         S r Sr/ SQrSSKrSSKJr  SSKJr  SS	K	J
r
JrJrJr  SS
KJr  SSKJrJrJrJrJrJr  SSKJr   " S S\5      rS rS r " S S\\5      r " S S\\5      rg)zSparse DIAgonal formatzrestructuredtext en)	dia_array
dia_matrixisspmatrix_dia    N   )copy_if_needed   )spmatrix)issparse_formats_spbasesparray)_data_matrix)isshapeupcast_chargetdtypeget_sum_dtypevalidateaxischeck_shape)
dia_matvecc                      \ rS rSrSrSSS.S jjrS rS rSS jr\	R                  R                  \l
        SS	 jr\	R                  R                  \l
        SS
 jr\	R                  R                  \l
        S rS rS rSS jrSS jr\	R"                  R                  \l
        SS jr\	R$                  R                  \l
        SS jr\	R&                  R                  \l
        SS jr\	R(                  R                  \l
        SS jr\	R*                  R                  \l
        SS jrS r\	R.                  R                  \l
        Srg)	_dia_base   diaNmaxprintc                   [         R                  " XUS9  [        U5      (       a  UR                  S:X  aU  U(       a  UR	                  5       nUR
                  U l        UR                  U l        [        UR                  5      U l	        GOwUR                  U R                  :X  a  U(       a  UR	                  5       nOUR                  5       nUR
                  U l        UR                  U l        [        UR                  5      U l	        GO[        U[        5      (       Ga2  [        U5      (       av  [        U5      U l	        [        R                  " S[!        U["        S95      U l        U R%                  ['        U R                  5      S9n[        R                  " SUS9U l        GO[ Uu  pUc  [)        S5      eU(       d  [*        n[        R,                  " [        R.                  " US   X4S	95      U l        [        R.                  " US
   U R%                  ['        U5      S9US	9n	[        R0                  " U	5      U l        [        U5      U l	        O [        R4                  " U5      n[        U [6        5      (       a)  UR8                  S:w  a  [)        SUR8                   S35      eU R;                  XUS9R                  5       nUR
                  U l        UR                  U l        [        UR                  5      U l	        Ub+  [!        U5      nU R
                  R=                  U5      U l        U R                  R8                  S
:w  a  [)        S5      eU R
                  R8                  S:w  a  [)        S5      eU R
                  R                  S   [?        U R                  5      :w  a:  [)        SU R
                  R                  S   [?        U R                  5      4-  5      e[?        [        R@                  " U R                  5      5      [?        U R                  5      :w  a  [)        S5      eg ! [2         a  n
Sn[)        U5      U
eS n
A
ff = f! [2         a  n
[)        SU R                   S35      U
eS n
A
ff = f)Nr   r   )r   r   )defaultmaxvalr   dtypezexpected a shape argument)r!   copyr   z+unrecognized form for dia_array constructorzunrecognized form for z_matrix constructorr   zDIA arrays don't support zD input. Use 2D)r!   shapezoffsets array must have rank 1zdata array must have rank 2zBnumber of diagonals (%d) does not match the number of offsets (%d)z&offset array contains duplicate values)!r   __init__r
   formatr"   dataoffsetsr   r#   _shapetodia
isinstancetupler   npzerosr   float_get_index_dtypemax
ValueErrorr   
atleast_2darray
atleast_1d	Exceptionasarrayr   ndim_coo_containerastypelenunique)selfarg1r#   r!   r"   r   A	idx_dtyper&   r'   emessagenewdtypes                D/var/www/html/venv/lib/python3.13/site-packages/scipy/sparse/_dia.pyr$   _dia_base.__init__   sw   d8<D>>{{e#99;D II	#||)$**5;;$++-$		A

AFF	 yy)!''2e$$t}} *$/HHUHUE,JK	 11TZZ1I	!xx9=5$(MD
 }()DEE- "bhhtAwe.W XDI hhtAw-1-B-B#e*-B-U,02G $&==#9DL"-e"4DKMzz$' $((TYY!^ #<TYYK!WXX##DU#CIIKADI99DL%agg.DKH		((2DI <<!=>>99>>Q:;;99??1T\\!22 @yyq)3t||+<=> ? ? ryy&'3t||+<<EFF =Y ! 5KG$W-145$  M !9$(KK=0C"E FKLMMs0   (P0 Q 0
Q:QQ
Q9Q44Q9c                     [         U R                     u  p[        U [        5      (       a  SOSnU R                  R
                  S   nSU SU SU R                   SU R                   SU S	U R
                   S
3$ )Nr3   matrixr   <z sparse z of dtype 'z'
	with z stored elements (z diagonals) and shape >)r   r%   r*   r   r&   r#   r!   nnz)r<   _fmt
sparse_clsds        rC   __repr___dia_base.__repr__c   s}    $++& *4 9 9Wx
IIOOAuHZLDJJ< @hhZ1!4J4::,VWY	
    c                     U R                   u  p[        R                  " U R                  R                   S   5      nX0R                  SS2S4   -
  nUS:  nXTU:  -  nXSU:  -  nU$ )zvReturns a mask of the same shape as self.data, where
mask[i,j] is True when data[i,j] corresponds to a stored element.r   Nr   )r#   r,   aranger&   r'   )r<   num_rowsnum_colsoffset_indsrowmasks         rC   
_data_mask_dia_base._data_maskl   sg     "ZZii		 23LL400qx x'(rP   c                     Ub  [        S5      eU R                  5       n[        R                  " U R                  U   5      $ )Nz<count_nonzero over an axis is not implemented for DIA format)NotImplementedErrorrX   r,   count_nonzeror&   )r<   axisrW   s      rC   r\   _dia_base.count_nonzerow   s?    %N   		$00rP   c                     Ub  [        S5      eU R                  u  p#SnU R                   H-  nUS:  a  U[        X#U-
  5      -  nM  U[        X%-   U5      -  nM/     [	        U5      $ )Nz6_getnnz over an axis is not implemented for DIA formatr   )r[   r#   r'   minint)r<   r]   MNrI   ks         rC   _getnnz_dia_base._getnnz   sn    % '7 8 8jjA1us1qSz!s13qz!	 
 3xrP   c           
          [        U5        Ub  US:  a  US-  n[        U R                  5      nU R                  u  pVS nUS:X  a  U R	                  5       nU R
                  U-  R                  SS9n	U	R                  S   U:X  a  U	n
O/[        R                  " XiR                  S9n
XS U	R                  S   & U R                  XS9nO[        R                  " US4US9n[        R                  " XdS9n[        XV[        U R                  5      U R
                  R                  S   U R                  U R
                  X5        U R                  U5      nUc  UR                  X#S9$ U R                  UR                  US95      nUR                  SX#S9$ )	Nr   r   r]   r    r   )r!   out )r]   r!   ri   )r   r   r!   r#   rX   r&   sumr,   r-   _ascontaineronesr   r:   r'   )r<   r]   r!   ri   	res_dtyperS   rT   retrW   xresrow_sumsones                rC   rk   _dia_base.sum   sg   TqAID!$**-	!ZZ19??$DT!&&A&.AwwqzX%hhxww7#$KQWWQZ ##C#9C xx1Y?H''(4Cx3t||+<yyq)4<<CS ((2H|||%|99##HLLdL$;<CwwBew55rP   c                 N   [        U[        5      (       d  UR                  U 5      $ [        R                  " U R
                  UR
                  5      (       a(  U R                  U R                  UR                  -   5      $ [        R                  " U R
                  UR
                  5      n[        R                  " X R
                  5      n[        R                  " X!R
                  5      nU R                  R                  S   nUR                  R                  S   nXV:X  aV  [        U5      [        U R
                  5      :X  a4  U R                  [        U5         nXtS S 24==   UR                  -  ss'   GOXV:X  aU  [        U5      [        UR
                  5      :X  a3  UR                  [        U5         nXsS S 24==   U R                  -  ss'   O[        U R                  S   US   -   U R                  S   5      n[        R                  " [        U5      U4[        R                  " U R                  UR                  5      S9nXsS U24==   U R                  S S 2S U24   -  ss'   XtS U24==   UR                  S S 2S U24   -  ss'   U R!                  Xr4U R                  S9$ )Nr   r   r    r#   )r*   r   _add_sparser,   array_equalr'   
_with_datar&   union1dsearchsortedr#   r:   _invert_indexr`   r-   result_type_dia_container)	r<   othernew_offsetsself_idx	other_idxself_dother_dnew_datarM   s	            rC   rx   _dia_base._add_sparse   s   %++$$T** >>$,,66??499uzz#9:: jju}}=??;=OOK?	#**""1% [!1S5F!Fyyx!89H\"ejj0"3{#3s5==7I#Izz-	":;Hq[!TYY.! DJJqMKO3TZZ]CA xx[!1%nnTYY

;H ww&'499QU+;;'()UZZ2A2->>)""H#:$**"MMrP   c                 >    U R                  U R                  U-  5      $ N)rz   r&   )r<   r   s     rC   _mul_scalar_dia_base._mul_scalar   s    tyy5011rP   c                    Un[         R                  " U R                  S   [        U R                  R
                  UR                  R
                  5      S9nU R                  R                  S   nU R                  u  pV[        XV[        U R                  5      X@R                  U R                  UR                  5       UR                  5       5        U$ )Nr   r    r   )r,   r-   r#   r   r!   charr&   r   r:   r'   ravel)r<   r   rp   yLrb   rc   s          rC   _matmul_vector_dia_base._matmul_vector   s    HHTZZ]+djjoo78ww||+E F IIOOAjj1DLL)1llDII779aggi	) rP   c                 f   U R                   u  p4UR                  S:X  a  [        R                  nO[	        U5      nUS:  a  [        X2-   XE5      nSnUnO[        X4U-
  U5      nUnX&-   nUR                  S:w  a  US U nU R                  R                   u  pX R                  ;   ai  X:  aE  [        R                  " X4U R                  R                  S9nU R                  US S 2S U
24'   Xl        XR                  U R                  U:H  Xx24'   g [        R                  " U R                  U R                  R                  R                  U5      5      U l        [        X5      n[        R                  " U	S-   U4U R                  R                  S9nU R                  US S2S U
24'   XSXx24'   Xl        g )Nr   r    r   rv   )r#   r7   r,   infr:   r`   r&   r'   r-   r!   appendtyper0   )r<   valuesrd   rb   rc   values_nn	min_index	max_index	data_rows	data_colsr&   ms                rC   _setdiag_dia_base._setdiag   su   zz;;!vvH6{Hq5AE1'AIIA1uh'AII;;!BQZF#yy	$xx 6diiooN&*iiQ

]# 	@FIIdlla')<<=99T\\4<<3E3E3J3J13MNDLI)A88Y]A.diiooFD$(IID"jyj!,2Y(()IrP   c                 4    U(       a  U R                  5       $ U $ r   r"   )r<   r"   s     rC   r)   _dia_base.todia  s    99;KrP   c                    Ub  US:w  a  [        S5      eU R                  u  p4[        U R                  5      nU R                  * n[        R
                  " [        U5      [        R                  S9S S 2S 4   n[        R
                  " U[        R                  S9Xe-  S S 2S 4   -
  n[        SXPR                  R                  S   -
  5      n	[        R                  " U R                  [        R                  " U R                  R                  S   U	4U R                  R                  S945      n
XU4   n
U R                  X4XC4US9$ )N)r   r   zvSparse arrays/matrices do not support an 'axes' parameter because swapping dimensions is the only logical permutation.r    r   r   )r#   r"   )r1   r#   r0   r'   r,   rR   r:   intcr&   hstackr-   r!   r   )r<   axesr"   rS   rT   max_dimr'   rc
pad_amountr&   s              rC   	transpose_dia_base.transpose  s'    L M M "ZZdjj/ <<- IIc'l"''21d7;IIhbgg.'2CQW1MMGIIOOA$667
yy$))RXXtyyq/A:.N48IIOO&E F GqDz""D?; &* # , 	,rP   c                    U R                   u  p#X* ::  d  X:  a)  [        R                  " SU R                  R                  S9$ [        R
                  " U R                  U:H  5      u  n[        SU5      n[        X!-   U5      nXe-
  nUR                  S:X  a(  [        R                  " XpR                  R                  S9$ U R                  US   XV24   nU[        U5      -
  n	U	S:  a  [        R                  " USU	4SS9nU$ )Nr   r    constant)mode)r#   r,   emptyr&   r!   nonzeror'   r0   r`   sizer-   r:   pad)
r<   rd   rowscolsidx	first_collast_colresult_sizeresultpaddings
             rC   diagonal_dia_base.diagonal1  s    ZZ
:88ATYY__55zz$,,!+,1I	tx&*88q=88Kyy??3q69#556F+Q;VVFQLzBFrP   c                    U R                   S:X  a$  U R                  U R                  U R                  S9$ U R                  u  p#U R                  R                  u  pE[
        R                  " U5      nX`R                  S S 2S 4   -
  nUS:  nXU:  -  nXU:  -  nXR                  S:g  -  nU R                  [        U R                  5      S9n	[
        R                  " US-   U	S9n
[
        R                  " UR                  SS9S U 5      U
SUS-   & XS:  a	  X   XS-   S & UR                  UR                     R                  U	SS9nU R                  R                  UR                     nU R                  XU
4U R                  U R                  S9$ )	Nr   r    r   r   rh   Fr   )r#   r!   )rI   _csc_containerr#   r!   r&   r,   rR   r'   r/   r0   r-   cumsumrk   Tr9   )r<   r"   rS   rT   num_offsets
offset_lenrU   rV   rW   r?   indptrindicesr&   s                rC   tocsc_dia_base.tocscC  sp   88q=&&tzz&DD!ZZ"&))//ii
+LL400qx x'(a ))TZZ)A	(Q,i8!#4888+;IX+F!GqA $*$6Fa<=!%%-&&yu&=yy{{466"""D6#:$**)- # 5 	5rP   c                 N   U R                   u  p#U R                  R                   u  pE[        R                  " U5      nX`R                  S S 2S 4   -
  nUS:  nXU:  -  nXU:  -  nXR                  S:g  -  nXx   n[        R
                  " Xd5      UR                  5          n	U R                  U R                  4[        U R                   5      S9n
UR                  U
SS9nU	R                  U
SS9n	U R                  U   nU R                  XU	44U R                   U R                  SS9$ )Nr   )arraysr   Fr   )r#   r!   r"   )r#   r&   r,   rR   r'   tiler   r/   r0   r9   r8   r!   )r<   r"   rS   rT   r   r   rU   rV   rW   colr?   r&   s               rC   tocoo_dia_base.tocoo]  s    !ZZ"&))//ii
+LL400qx x'(a iggk/

=))LL?3tzz? * 
	 jjj/jjj/yy "":djj

 # 
 	
rP   c                     U(       a3  U R                  XR                  R                  5       4U R                  S9$ U R                  XR                  4U R                  S9$ )zReturns a matrix with the same sparsity structure as self,
but with different data.  By default the structure arrays are copied.
rw   )r   r'   r"   r#   )r<   r&   r"   s      rC   rz   _dia_base._with_datax  sb     &&||((*+4:: '   &&||$DJJ '  rP   c                    [        U5      nUu  p#U R                  S S 2S U24   U l        X R                  S   :  a  [        R                  " U R
                  U R                  S   -   U R                  R                  S   :  5      (       a`  U R
                  S S 2S 4   U R                  S   -   [        R                  " U R                  R                  S   5      :*  nSU R                  U'   Xl        g )Nr   r   )r   r&   r#   r,   anyr'   rR   r(   )r<   r#   rb   rc   rW   s        rC   resize_dia_base.resize  s    E"IIa!e$	

1t||djjm3diiooa6HHIILLD)DJJqM9IIdiiooa012DDIIdOrP   )r(   r&   r'   )NNFr   )NNN)r   )F)NF)T)__name__
__module____qualname____firstlineno___formatr$   rN   rX   r\   r   __doc__re   rk   rx   r   r   r   r)   r   r   r   r   rz   r   __static_attributes__rj   rP   rC   r   r      s    GKGT KGZ
	1 $1199M oo--GO!6F ++%%CK#NJ2#J MM))EM,,  ))11I  ''//H50 MM))EM
0 MM))EM ^^++FNrP   r   c                 t    [         R                  " U 5      n[         R                  " [        U 5      5      X'   U$ )z)Helper function to invert an index array.)r,   
zeros_likerR   r:   )r   invs     rC   r}   r}     s)    
--
CyyS"CHJrP   c                 "    [        U [        5      $ )a  Is `x` of dia_matrix type?

Parameters
----------
x
    object to check for being a dia matrix

Returns
-------
bool
    True if `x` is a dia matrix, False otherwise

Examples
--------
>>> from scipy.sparse import dia_array, dia_matrix, coo_matrix, isspmatrix_dia
>>> isspmatrix_dia(dia_matrix([[5]]))
True
>>> isspmatrix_dia(dia_array([[5]]))
False
>>> isspmatrix_dia(coo_matrix([[5]]))
False
)r*   r   )rp   s    rC   r   r     s    . a$$rP   c                       \ rS rSrSrSrg)r   i  aH  
Sparse array with DIAgonal storage.

This can be instantiated in several ways:
    dia_array(D)
        where D is a 2-D ndarray

    dia_array(S)
        with another sparse array or matrix S (equivalent to S.todia())

    dia_array((M, N), [dtype])
        to construct an empty array with shape (M, N),
        dtype is optional, defaulting to dtype='d'.

    dia_array((data, offsets), shape=(M, N))
        where the ``data[k,:]`` stores the diagonal entries for
        diagonal ``offsets[k]`` (See example below)

Attributes
----------
dtype : dtype
    Data type of the array
shape : 2-tuple
    Shape of the array
ndim : int
    Number of dimensions (this is always 2)
nnz
size
data
    DIA format data array of the array
offsets
    DIA format offset array of the array
T

Notes
-----

Sparse arrays can be used in arithmetic operations: they support
addition, subtraction, multiplication, division, and matrix power.
Sparse arrays with DIAgonal storage do not support slicing.

Examples
--------

>>> import numpy as np
>>> from scipy.sparse import dia_array
>>> dia_array((3, 4), dtype=np.int8).toarray()
array([[0, 0, 0, 0],
       [0, 0, 0, 0],
       [0, 0, 0, 0]], dtype=int8)

>>> data = np.array([[1, 2, 3, 4]]).repeat(3, axis=0)
>>> offsets = np.array([0, -1, 2])
>>> dia_array((data, offsets), shape=(4, 4)).toarray()
array([[1, 0, 3, 0],
       [1, 2, 0, 4],
       [0, 2, 3, 0],
       [0, 0, 3, 4]])

>>> from scipy.sparse import dia_array
>>> n = 10
>>> ex = np.ones(n)
>>> data = np.array([ex, 2 * ex, ex])
>>> offsets = np.array([-1, 0, 1])
>>> dia_array((data, offsets), shape=(n, n)).toarray()
array([[2., 1., 0., ..., 0., 0., 0.],
       [1., 2., 1., ..., 0., 0., 0.],
       [0., 1., 2., ..., 0., 0., 0.],
       ...,
       [0., 0., 0., ..., 2., 1., 0.],
       [0., 0., 0., ..., 1., 2., 1.],
       [0., 0., 0., ..., 0., 1., 2.]])
rj   Nr   r   r   r   r   r   rj   rP   rC   r   r         HrP   r   c                       \ rS rSrSrSrg)r   i  a[  
Sparse matrix with DIAgonal storage.

This can be instantiated in several ways:
    dia_matrix(D)
        where D is a 2-D ndarray

    dia_matrix(S)
        with another sparse array or matrix S (equivalent to S.todia())

    dia_matrix((M, N), [dtype])
        to construct an empty matrix with shape (M, N),
        dtype is optional, defaulting to dtype='d'.

    dia_matrix((data, offsets), shape=(M, N))
        where the ``data[k,:]`` stores the diagonal entries for
        diagonal ``offsets[k]`` (See example below)

Attributes
----------
dtype : dtype
    Data type of the matrix
shape : 2-tuple
    Shape of the matrix
ndim : int
    Number of dimensions (this is always 2)
nnz
size
data
    DIA format data array of the matrix
offsets
    DIA format offset array of the matrix
T

Notes
-----

Sparse matrices can be used in arithmetic operations: they support
addition, subtraction, multiplication, division, and matrix power.
Sparse matrices with DIAgonal storage do not support slicing.

Examples
--------

>>> import numpy as np
>>> from scipy.sparse import dia_matrix
>>> dia_matrix((3, 4), dtype=np.int8).toarray()
array([[0, 0, 0, 0],
       [0, 0, 0, 0],
       [0, 0, 0, 0]], dtype=int8)

>>> data = np.array([[1, 2, 3, 4]]).repeat(3, axis=0)
>>> offsets = np.array([0, -1, 2])
>>> dia_matrix((data, offsets), shape=(4, 4)).toarray()
array([[1, 0, 3, 0],
       [1, 2, 0, 4],
       [0, 2, 3, 0],
       [0, 0, 3, 4]])

>>> from scipy.sparse import dia_matrix
>>> n = 10
>>> ex = np.ones(n)
>>> data = np.array([ex, 2 * ex, ex])
>>> offsets = np.array([-1, 0, 1])
>>> dia_matrix((data, offsets), shape=(n, n)).toarray()
array([[2., 1., 0., ..., 0., 0., 0.],
       [1., 2., 1., ..., 0., 0., 0.],
       [0., 1., 2., ..., 0., 0., 0.],
       ...,
       [0., 0., 0., ..., 2., 1., 0.],
       [0., 0., 0., ..., 1., 2., 1.],
       [0., 0., 0., ..., 0., 1., 2.]])
rj   Nr   rj   rP   rC   r   r     r   rP   r   )r   __docformat____all__numpyr,   
_lib._utilr   _matrixr	   _baser
   r   r   r   _datar   _sputilsr   r   r   r   r   r   _sparsetoolsr   r   r}   r   r   r   rj   rP   rC   <module>r      sm    %
7  '  7 7   %A, A,H%6I	7 IXI9 IrP   