403Webshell
Server IP : 217.160.0.135  /  Your IP : 216.73.217.85
Web Server : Apache
System : Linux www 6.18.52-i1-ampere #1203 SMP Mon Sep 14 18:29:59 CEST 2026 aarch64
User : sws1074145052 ( 1074145052)
PHP Version : 8.3.32
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : OFF  |  Pkexec : OFF
Directory :  /lib/python3/dist-packages/scipy/sparse/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /lib/python3/dist-packages/scipy/sparse/__pycache__/_dok.cpython-311.pyc
�

d�c>���dZdZddgZddlZddlZddlmZmZddl	m
Z
dd	lmZm
Z
mZmZmZmZmZmZmZ	dd
lmZn#e$rd�ZYnwxYwGd�dee
e��Zd
�ZdS)zDictionary Of Keys based matrixzrestructuredtext en�
dok_matrix�isspmatrix_dok�N�)�spmatrix�
isspmatrix)�
IndexMixin)	�isdense�getdtype�isshape�	isintlike�isscalarlike�upcast�
upcast_scalar�get_index_dtype�check_shape)�isSequenceTypec�b�t|d��pt|d��pt|d��S)N�__len__�__next__�next)�hasattr)�xs �3/usr/lib/python3/dist-packages/scipy/sparse/_dok.py�_is_sequencers7����9�%�%�&���J�)?�)?�&��1�f�%�%�	'�c�6�eZdZdZdZd,d�Zd�Zd�Zd�Ze	e
je�	��Zd-d
�Z
d�Ze
j
je
_e
jje_d�Zd.d�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Z d�Z!d �Z"d!�Z#d"�Z$d#�Z%d$�Z&d/d%�Z'e
j'je'_d&�Z(d'�Z)e
j)je)_d0d(�Z*e
j*je*_d0d)�Z+e
j+je+_d0d*�Z,e
j,je,_d+�Z-e
j-je-_dS)1ra�
    Dictionary Of Keys based sparse matrix.

    This is an efficient structure for constructing sparse
    matrices incrementally.

    This can be instantiated in several ways:
        dok_matrix(D)
            with a dense matrix, D

        dok_matrix(S)
            with a sparse matrix, S

        dok_matrix((M,N), [dtype])
            create the matrix with initial shape (M,N)
            dtype is optional, defaulting to dtype='d'

    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
        Number of nonzero elements

    Notes
    -----

    Sparse matrices can be used in arithmetic operations: they support
    addition, subtraction, multiplication, division, and matrix power.

    Allows for efficient O(1) access of individual elements.
    Duplicates are not allowed.
    Can be efficiently converted to a coo_matrix once constructed.

    Examples
    --------
    >>> import numpy as np
    >>> from scipy.sparse import dok_matrix
    >>> S = dok_matrix((5, 5), dtype=np.float32)
    >>> for i in range(5):
    ...     for j in range(5):
    ...         S[i, j] = i + j    # Update element

    �dokNFc���t�|��tj|��t|t���|_t
|t��r,t|��r|\}}t||f��|_
dSt|��r�t|��r|r|�
��}n|���}|�|�|d���}t�||��t|j��|_
|j|_dS	t%j|��}n"#t($r}t+d��|�d}~wwxYwt-|j��dkrt+d���|�||������}t�||��t|j��|_
|j|_dS)N)�defaultF��copyzInvalid input format.�z(Expected rank <=2 dense array or matrix.��dtype)�dict�__init__rr
�floatr$�
isinstance�tuplerr�_shaperrr!�todok�astype�update�shape�np�asarray�	Exception�	TypeError�len�_coo_container)	�self�arg1r.r$r!�M�N�e�ds	         rr&zdok_matrix.__init__Js����
�
�d������$�����e�U�3�3�3��
��d�E�"�"�	!�w�t�}�}�	!��D�A�q�%�q�!�f�-�-�D�K�K�K�
��
�
�	!��d�#�#�
$��
$��y�y�{�{����z�z�|�|��� ��{�{�5�u�{�5�5���K�K��d�#�#�#�%�d�j�1�1�D�K���D�J�J�J�
@��z�$�'�'�����
@�
@�
@�� 7�8�8�a�?�����
@�����4�:���!�#�#�� J�K�K�K��#�#�D��#�6�6�<�<�>�>�A��K�K��a� � � �%�d�j�1�1�D�K���D�J�J�Js�0E�
E$�E�E$c� �td���)Nz9Direct modification to dok_matrix element is not allowed.)�NotImplementedError)r5�vals  rr-zdok_matrix.updatels��!�#4�5�5�	5rc�8�t�||��S)z�An update method for dict data defined for direct access to
        `dok_matrix` data. Main purpose is to be used for effcient conversion
        from other spmatrix classes. Has no checking if `data` is valid.)r%r-)r5�datas  r�_updatezdok_matrix._updateqs���{�{�4��&�&�&rc���|�|d����|j��}|j|_t�|��t�||��dS�NFr )�reshape�asformat�format�__dict__r%�clearr-)r5r.�
new_matrixs   r�	set_shapezdok_matrix.set_shapews]���\�\�%�e�\�4�4�=�=�d�k�J�J�
�"�+��
��
�
�4�������D�*�%�%�%�%�%r)�fget�fsetc�X�|�td���t�|��S)Nz6getnnz over an axis is not implemented for DOK format.)r<r%r)r5�axiss  r�getnnzzdok_matrix.getnnzs1����%�'8�9�9�
9��|�|�D�!�!�!rc�X�td�|���D����S)Nc3�"K�|]
}|dkV��dS)rN�)�.0rs  r�	<genexpr>z+dok_matrix.count_nonzero.<locals>.<genexpr>�s&����1�1�a�1��6�1�1�1�1�1�1r)�sum�values�r5s r�
count_nonzerozdok_matrix.count_nonzero�s'���1�1�4�;�;�=�=�1�1�1�1�1�1rc�6�t�|��S�N)r%rrVs rrzdok_matrix.__len__�s���|�|�D�!�!�!r�c�`�	|\}}t|��rt|��sJ�n/#tttf$r}t	d��|�d}~wwxYw|dks(||jdks|dks||jdkrt	d���t�|||��S)ztThis overrides the dict.get method, providing type checking
        but otherwise equivalent functionality.
        z!Index must be a pair of integers.NrrzIndex out of bounds.)r�AssertionErrorr2�
ValueError�
IndexErrorr.r%�get)r5�keyr�i�jr9s      rr_zdok_matrix.get�s���	I��D�A�q��Q�<�<�0�I�a�L�L�0�0�0�0���	�:�6�	I�	I�	I��@�A�A�q�H�����	I����
��E�E�Q�$�*�Q�-�'�'�1�q�5�5�A���A��4F�4F��3�4�4�4��x�x��c�7�+�+�+s�%(�A�A�Ac�n�t�|||f|j�d����S�Nr)r%r_r$�type�r5�row�cols   r�_get_intXintzdok_matrix._get_intXint�s*���x�x��s�C�j�$�*�/�/�!�*<�*<�=�=�=rc�P�|�t||dz��|��S�Nr��_get_sliceXslice�slicerfs   r�_get_intXslicezdok_matrix._get_intXslice�s&���$�$�U�3��A��%6�%6��<�<�<rc�P�|�|t||dz����Srkrlrfs   r�_get_sliceXintzdok_matrix._get_sliceXint�s&���$�$�S�%��S��U�*;�*;�<�<�<rc�l�|�|jd��\}}}|�|jd��\}}}t|||��}	t|||��}
t|	��t|
��f}t|��d|dz|dzkr|�|	|
��S|�||j���}|���D]�}
tt|
d��|z
|��\}}|dks|dks||dkr�Dtt|
d��|z
|��\}}|dks|dks||dkr��t�||
��}t�|||f|����|S)Nrrr"r#)
�indicesr.�ranger3�_get_columnXarray�_dok_containerr$�keys�divmod�intr%�__getitem__�__setitem__)r5rgrh�	row_start�row_stop�row_step�	col_start�col_stop�col_step�	row_range�	col_ranger.�newdokr`ra�rirb�rjrs                   rrmzdok_matrix._get_sliceXslice�s���(+���D�J�q�M�(B�(B�%�	�8�X�(+���D�J�q�M�(B�(B�%�	�8�X��)�X�x�8�8�	��)�X�x�8�8�	��Y����Y���0���t�9�9��E�!�H��u�Q�x�/�/�/��)�)�)�Y�?�?�?��$�$�U�$�*�$�=�=���9�9�;�;�	0�	0�C��3�s�1�v�;�;��2�H�=�=�E�A�r��Q�w�w�!�a�%�%�1��a��=�=���3�s�1�v�;�;��2�H�=�=�E�A�r��Q�w�w�!�a�%�%�1��a��=�=��� � ��s�+�+�A����V�a��V�Q�/�/�/�/��
rc�X�|���}|�|g|��SrY��squeezerurfs   r�_get_intXarrayzdok_matrix._get_intXarray�s'���k�k�m�m���%�%�s�e�S�1�1�1rc�X�|���}|�||g��SrYr�rfs   r�_get_arrayXintzdok_matrix._get_arrayXint�s'���k�k�m�m���%�%�c�C�5�1�1�1rc��tt|�|jd�����}|�||��Srd��listrtrsr.rurfs   r�_get_sliceXarrayzdok_matrix._get_sliceXarray��<���5�#�+�+�d�j��m�4�4�5�6�6���%�%�c�3�/�/�/rc��tt|�|jd�����}|�||��Srkr�rfs   r�_get_arrayXslicezdok_matrix._get_arrayXslice�r�rc�F�|�t|��t|��f|j���}t|��D]X\}}t|��D]C\}}t�|||fd��}|rt�|||f|���D�Y|S)Nr#r)rvr3r$�	enumerater%r_r{)	r5rgrhr�ra�rrb�c�vs	         rruzdok_matrix._get_columnXarray�s����$�$�c�#�h�h��C���%9���$�L�L���c�N�N�	8�	8�D�A�q�!�#���
8�
8���1��H�H�T�A�q�6�1�-�-���8��$�$�V�a��V�Q�7�7�7��
8��
rc���ttjtj||����\}}|�|j|j���}tjt|jd��t|jd����D]J}t�|||||fd��}|rt�|||���K|S)Nr#rr)
�mapr/�
atleast_2d�broadcast_arraysrvr.r$�	itertools�productrtr%r_r{)r5rgrhrarbr�r`r�s        r�_get_arrayXarrayzdok_matrix._get_arrayXarray�s����2�=�"�"5�c�3�"?�"?�@�@���1��$�$�Q�W�D�J�$�?�?���$�U�1�7�1�:�%6�%6��a�g�a�j�8I�8I�J�J�	1�	1�C������#���#��/��3�3�A��
1�� � ���a�0�0�0���
rc��||f}|rt�|||��dSt�||��r||=dSdSrY)r%r{�__contains__)r5rgrhrr`s     r�_set_intXintzdok_matrix._set_intXint�s^���C�j���	����T�3��*�*�*�*�*�
�
�
�t�S�
)�
)�	��S�	�	�	�	�	rc	��ttt|�������}ttt|�������}|���}t�|t
t
||��|����tj|dk��dD]4}||||f}t�	||��dkr||=�5dSrd)
r�r�ry�ravelr%r-�zipr/�nonzerorz)r5rgrhrrar`s      r�_set_arrayXarrayzdok_matrix._set_arrayXarray�s����3�s�C�I�I�K�K�(�(�)�)���3�s�C�I�I�K�K�(�(�)�)��
�G�G�I�I�����D�#�c�#�s�m�m�Q�/�/�0�0�0���A��F�#�#�A�&�	�	�A��q�6�3�q�6�"�C�����c�*�*�a�/�/���I��		�	rc�����t���r�t|j���}|�|j|����|j\}}tjt|��t|����D](}t�	||d���z}|r|�|<�)�n>t���r؉j|jkrtd���t|j�j��}|�|j|����t�
�|��tjd���5t�
���fd�����D����ddd��n#1swxYwYnWt#���r|���}|�z�n.t'���r|����z�nt*S�S)Nr#r� Matrix dimensions are not equal.�ignore)�overc3�>�K�|]}|�|�|zfV��dSrYrQ)rR�k�new�others  ��rrSz%dok_matrix.__add__.<locals>.<genexpr>
s5�����I�I�q�Q��A���q�� 1�2�I�I�I�I�I�Ir)r
rr$rvr.r�r�rtr%r_rr]rr-r/�errstaterwr�tocscr	�todense�NotImplemented)	r5r��	res_dtyper7r8r`�aij�cscr�s	 `      @r�__add__zdok_matrix.__add__�s$��������	"�%�d�j�%�8�8�I��%�%�d�j�	�%�B�B�C��:�D�A�q� �(��q���5��8�8�<�<�
#�
#���h�h�t�c�A�.�.��6���#�"�C��H��
#�
�E�
"�
"�	"��{�d�j�(�(� �!C�D�D�D��t�z�5�;�7�7�I��%�%�d�j�	�%�B�B�C��K�K��T�"�"�"���(�+�+�+�
K�
K����C�I�I�I�I�I�E�J�J�L�L�I�I�I�K�K�K�
K�
K�
K�
K�
K�
K�
K�
K�
K�
K�
K����
K�
K�
K�
K����
�
�	"��*�*�,�,�C���+�C�C�
�U�^�^�	"��,�,�.�.�5�(�C�C�!�!��
s�;;F�F�	Fc�(���t���r����j�j���}�j\}}t	jt
|��t
|����D](}t��|d���z}|r|||<�)n�t���r��j�jkrtd������j�j���}t�|���t�|��fd�����D����nWt���r����}|�z}n.t���r�����z}nt"S|S)Nr#rr�c3�>�K�|]}|�|�|zfV��dSrYrQ)rRr�r�r5s  ��rrSz&dok_matrix.__radd__.<locals>.<genexpr>"s5�����F�F�A��D��G�e�A�h�.�/�F�F�F�F�F�Fr)r
rvr.r$r�r�rtr%r_rr]r-rwrr�r	r�r�)r5r�r�r7r8r`r�r�s``      r�__radd__zdok_matrix.__radd__s���������	"��%�%�d�j��
�%�C�C�C��:�D�A�q� �(��q���5��8�8�<�<�
#�
#���h�h�t�c�A�.�.��6���#�"�C��H��
#��E�
"�
"�
	"��{�d�j�(�(� �!C�D�D�D��%�%�d�j��
�%�C�C�C��K�K��T�"�"�"��K�K��F�F�F�F�F������F�F�F�
H�
H�
H�
H�
��
�
�	"��*�*�,�,�C���+�C�C�
�U�^�^�	"��$�,�,�.�.�(�C�C�!�!��
rc����jjdkrtd������j�j���}t
�|�fd�����D����|S)N�bz2Negating a sparse boolean matrix is not supported.r#c3�.�K�|]}|�|fV��dSrYrQ)rRr�r5s  �rrSz%dok_matrix.__neg__.<locals>.<genexpr>1s-�����=�=�A�1�t�A�w�h�-�=�=�=�=�=�=r)r$�kindr<rvr.r%r-rw�r5r�s` r�__neg__zdok_matrix.__neg__,s{����:�?�c�!�!�%�'4�5�5�
5��!�!�$�*�D�J�!�?�?�����C�=�=�=�=������=�=�=�>�>�>��
rc����t|j���}|�|j|���}t�|�fd�|���D����|S)Nr#c3�,�K�|]\}}||�zfV��dSrYrQ�rRr�r�r�s   �rrSz)dok_matrix._mul_scalar.<locals>.<genexpr>8s/�����B�B�T�Q��1�a�%�i�.�B�B�B�B�B�Br)rr$rvr.r%r-�items�r5r�r�r�s `  r�_mul_scalarzdok_matrix._mul_scalar4sd���!�$�*�e�4�4�	��!�!�$�*�I�!�>�>�����C�B�B�B�B�T�Z�Z�\�\�B�B�B�C�C�C��
rc���tj|jdt|j|j�����}|���D]!\\}}}||xx|||zz
cc<�"|S)Nrr#)r/�zerosr.rr$r�)r5r��resultrarbr�s      r�_mul_vectorzdok_matrix._mul_vector;sn����$�*�Q�-�v�d�j�%�+�/N�/N�O�O�O�������	&�	&�I�F�Q��A��1�I�I�I��U�1�X��%�I�I�I�I��
rc	��|jd|jdf}t|j|j��}tj||���}|���D])\\}}}||dd�fxx|||dd�fzz
cc<�*|S)Nrrr#)r.rr$r/r�r�)r5r��result_shape�result_dtyper�rarbr�s        r�_mul_multivectorzdok_matrix._mul_multivectorBs����
�1�
�u�{�1�~�6���d�j�%�+�6�6����,�l�;�;�;�������	*�	*�I�F�Q��A��1�Q�Q�Q�3�K�K�K�1�u�Q�q�q�q�S�z�>�)�K�K�K�K��
rc���t���r;t�|�fd�|���D����|StS)Nc3�,�K�|]\}}||�zfV��dSrYrQr�s   �rrSz&dok_matrix.__imul__.<locals>.<genexpr>M�/�����G�G�$�!�Q��1�u�9�~�G�G�G�G�G�Gr�r
r%r-r�r��r5r�s `r�__imul__zdok_matrix.__imul__K�O�������	��K�K��G�G�G�G�$�*�*�,�,�G�G�G�H�H�H��K��rc�(��t���rlt|j���}|�|j|���}t
�|�fd�|���D����|S|����zS)Nr#c3�,�K�|]\}}||�zfV��dSrYrQr�s   �rrSz)dok_matrix.__truediv__.<locals>.<genexpr>Us/�����F�F���A�q�!�e�)�n�F�F�F�F�F�Fr)	r
rr$rvr.r%r-r��tocsrr�s `  r�__truediv__zdok_matrix.__truediv__Qs��������	�%�d�j�%�8�8�I��%�%�d�j�	�%�B�B�C��K�K��F�F�F�F������F�F�F�G�G�G��J��z�z�|�|�e�#�#rc���t���r;t�|�fd�|���D����|StS)Nc3�,�K�|]\}}||�zfV��dSrYrQr�s   �rrSz*dok_matrix.__itruediv__.<locals>.<genexpr>[r�rr�r�s `r�__itruediv__zdok_matrix.__itruediv__Yr�rc�6�t�|��SrY)r%�
__reduce__rVs rr�zdok_matrix.__reduce___s�����t�$�$�$rc���|�td���|j\}}|�||f|j|���}t�|d�|���D����|S)NzoSparse matrices do not support an 'axes' parameter because swapping dimensions is the only logical permutation.)r$r!c3�.K�|]\\}}}||f|fV��dSrYrQ�rR�left�rightr=s    rrSz'dok_matrix.transpose.<locals>.<genexpr>qsO����B�B�0�m�t�U�S�"�4�=�#�.�B�B�B�B�B�Br)r]r.rvr$r%r-r�)r5�axesr!r7r8r�s      r�	transposezdok_matrix.transposeis������K�L�L�
L��z���1��!�!�1�a�&��
��!�F�F�����C�B�B�48�J�J�L�L�B�B�B�	C�	C�	C��
rc���|j\}}|�||f|j���}t�|d�|���D����|S)zReturn the conjugate transpose.r#c3�RK�|]"\\}}}||ftj|��fV��#dSrY)r/�conjr�s    rrSz(dok_matrix.conjtransp.<locals>.<genexpr>{sW����B�B�0�m�t�U�S�"�4�=�"�'�#�,�,�7�B�B�B�B�B�Br)r.rvr$r%r-r�)r5r7r8r�s    r�
conjtranspzdok_matrix.conjtranspwst���z���1��!�!�1�a�&��
�!�;�;�����C�B�B�48�J�J�L�L�B�B�B�	C�	C�	C��
rc�~�|�|j|j���}t�||��|S)Nr#)rvr.r$r%r-r�s  rr!zdok_matrix.copys7���!�!�$�*�D�J�!�?�?�����C������
rc�B�|jdkr!|�|j|j���St	t|j�����}t
j|���|j|j���}t
jd�|�	��D��||j���}t
jd�|�	��D��||j���}|�|||ff|j|j���}d|_
|S)	Nrr#)�maxval)r$�countc3� K�|]	\}}|V��
dSrYrQ)rRra�_s   rrSz#dok_matrix.tocoo.<locals>.<genexpr>��&����5�5���A�1�5�5�5�5�5�5rc3� K�|]	\}}|V��
dSrYrQ)rRr�rbs   rrSz#dok_matrix.tocoo.<locals>.<genexpr>�r�r)r.r$T)�nnzr4r.r$r�maxr/�fromiterrUrw�has_canonical_format)r5r!�	idx_dtyper?rgrh�As       r�tocoozdok_matrix.tocoo�s����8�q�=�=��&�&�t�z���&�D�D�D�#�3�t�z�?�?�;�;�;�	��{�4�;�;�=�=��
�$�(�K�K�K���k�5�5������5�5�5�Y�d�h�W�W�W���k�5�5������5�5�5�Y�d�h�W�W�W�����
�C��:��d�j��
�
 �
�
��"&����rc�2�|r|���S|SrYr �r5r!s  rr+zdok_matrix.todok�s���	��9�9�;�;���rc�V�|�d����|���SrB)r�r�r�s  rr�zdok_matrix.tocsc�s'���z�z�u�z�%�%�+�+��+�6�6�6rc���t|��}|\}}|j\}}||ks||kr8t|�����D]\}}||ks||kr|||f=�||_dSrY)rr.r�rwr*)r5r.�newM�newNr7r8rarbs        r�resizezdok_matrix.resize�s���E�"�"���
��d��z���1��!�8�8�t�a�x�x��t�y�y�{�{�+�+�
#�
#���A���9�9��T�	�	��Q��T�
������r)NNFrY)rZ)NF)F).�__name__�
__module__�__qualname__�__doc__rEr&r-r@rI�propertyr�	get_shaper.rNrWrr_rirorqrmr�r�r�r�rur�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r!r�r+r�r�rQrrrrs�������/�/�`�F� !� !� !� !�D5�5�5�
'�'�'�&�&�&�
�H�(�,�9�=�=�=�E�"�"�"�"�2�2�2��_�,�F�N�$�2�:�M��"�"�"�,�,�,�,�>�>�>�=�=�=�=�=�=����02�2�2�2�2�2�0�0�0�0�0�0�	�	�	�	�	�	����
�
�
����>���0���������������$�$�$����%�%�%�
�
�
�
�!�*�2�I��������
�=�(�D�L������N�*�E�M�����
�N�*�E�M�7�7�7�7��N�*�E�M�	�	�	��_�,�F�N�N�Nrc�X�ddlm}t|t��pt||��S)a�Is x of dok_matrix type?

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

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

    Examples
    --------
    >>> from scipy.sparse import dok_matrix, isspmatrix_dok
    >>> isspmatrix_dok(dok_matrix([[5]]))
    True

    >>> from scipy.sparse import dok_matrix, csr_matrix, isspmatrix_dok
    >>> isspmatrix_dok(csr_matrix([[5]]))
    False
    r)�	dok_array)�_arraysrr(r)rrs  rrr�s5��.#�"�"�"�"�"��a��$�$�@�
�1�i�(@�(@�@r)r�
__docformat__�__all__r��numpyr/�_baserr�_indexr�_sputilsr	r
rrr
rrrr�operatorrr�ImportErrorr%rrrQrr�<module>rs���%�%�%�
��)�
*����������'�'�'�'�'�'�'�'�������L�L�L�L�L�L�L�L�L�L�L�L�L�L�L�L�L�L�L�L�L�L�'�7�7�7�7�7�7�7���'�'�'�'�'�'�'�'�'����V-�V-�V-�V-�V-��:�t�V-�V-�V-�rA�A�A�A�As�=�A�A

Youez - 2016 - github.com/yon3zu
LinuXploit