403Webshell
Server IP : 93.86.61.54  /  Your IP : 216.73.216.156
Web Server : Apache/2.4.62 (Ubuntu)
System : Linux rasin.ddns.net 6.8.0-124-generic #124~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Tue May 26 21:05:19 UTC x86_64
User : www-data ( 33)
PHP Version : 8.4.22
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : ON
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__/_compressed.cpython-310.pyc
o

��Ebh��@s�dZgZddlmZddlZddlZddlmZddl	m
Z
mZmZddl
mZmZddlmZdd	lmZmZmZmZmZmZmZmZdd
lmZddlmZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)Gdd
�d
eee�Z*dd�Z+dS)z>Base class for sparse matrix formats using compressed storage.�)�warnN)�_prune_array�)�spmatrix�
isspmatrix�SparseEfficiencyWarning)�_data_matrix�
_minmax_mixin)�_sparsetools)�get_csr_submatrix�csr_sample_offsets�csr_todense�csr_sample_values�
csr_row_index�
csr_row_slice�csr_column_index1�csr_column_index2)�
IndexMixin)
�upcast�upcast_char�	to_native�isdense�isshape�getdtype�isscalarlike�	isintlike�get_index_dtype�downcast_intp_index�
get_sum_dtype�check_shape�is_pydata_spmatrixc@sZeZdZdZdydd�Zdzdd�Zejje_d{dd	�Zd|dd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�Zd}d,d-�Zejje_d.d/�Zd0d1�Zejje_d2d3�Zejje_d~d4d5�Zejje_dzd6d7�Zd8d9�Zd:d;�Zd<d=�Z d>d?�Z!d@dA�Z"d{dBdC�Z#dDdE�Z$d{dFdG�Z%dydHdI�Z&dJdK�Z'dLdM�Z(dNdO�Z)dPdQ�Z*dRdS�Z+dTdU�Z,dVdW�Z-dXdY�Z.d|dZd[�Z/ej/je/_dd\d]�Z0ej0je0_d^d_�Z1d`da�Z2dbdc�Z3e4e2e3dd�Z5dedf�Z6dgdh�Z7didj�Z8e4e7e8dd�Z9dkdl�Z:dmdn�Z;dodp�Z<dqdr�Z=ej=je=_d|dsdt�Z>dudv�Z?dwdx�Z@dS)��
_cs_matrixzBbase matrix class for compressed row- and column-oriented matricesNFc
Csnt�|�t|�r"|j|jkr|r|��}n|�|j�}|�|�n�t|t�r�t	|�rat
|�|_|j\}}t
t||�d�}t�dt|td��|_t�d|�|_tj|�||f�dd|d�|_n�t|�dkrx|�|j|||d��}|�|�nlt|�dkr�|\}	}
}d}|dur�t|�}t
|
|f|d	d
�}tj|
||d�|_tj|||d�|_tj|	||d�|_n2td�|j���zt�|�}Wnty�}
z	td�|j��|
�d}
~
ww|�|�|j||d���|dur�t
|�|_n3|jdu�r!zt|j�d}|j��d}Wnt�y}
ztd
�|
�d}
~
wwt
|�||f��|_|du�r/|jj|dd�|_|jdd�dS)N��maxvalr)�defaultr��dtype���shaper&�T)r#�check_contents��copyr&z(unrecognized {}_matrix constructor usagez!unable to infer matrix dimensionsF�r-��
full_check) r�__init__r�formatr-�asformat�	_set_self�
isinstance�tuplerr�_shaper)r�max�np�zerosr�float�data�indices�_swap�indptr�len�	__class__�_coo_container�array�
ValueError�asarray�	Exception�astype�check_format)�self�arg1r)r&r-�M�N�	idx_dtype�otherr<r=r?r#�e�	major_dim�	minor_dim�rR�:/usr/lib/python3/dist-packages/scipy/sparse/_compressed.pyr1s�





��
��������
��
�
z_cs_matrix.__init__cCs�|durt|jd�S|dkr|d7}|�|d|f�\}}|�|j�\}}|dkr4tjt|j�|d�S|dkr>t�|j�St	d��)N���rr'r)�	minlengthzaxis out of bounds)
�intr?r>r)r9�bincountrr=�diffrD)rI�axis�_rLrRrRrS�getnnzls�z_cs_matrix.getnnzcCs4|r|��}|j|_|j|_|j|_t|j�|_dS)z:take the member variables of other and assign them to selfN)r-r<r=r?rr)r7)rIrNr-rRrRrSr4}sz_cs_matrix._set_selfTcCs�|�d�\}}|�|j�\}}|jjjdkr"td�|jjj�dd�|jjjdkr5td�|jjj�dd�t	|j|jf�}t
j|j|d�|_t
j|j|d�|_t|j
�|_
|j
j|jj|jjfD]
}|dkrjtd	��q`t|j�|dkr�td
�t|j�|d���|jddkr�td��t|j�t|j
�kr�td
��|jdt|j�kr�td��|��|r�|jdkr�|j��|kr�td�||���|j��dkr�td�|���t
�|j���dkr�td��dSdSdS)z�check whether the matrix format is valid

        Parameters
        ----------
        full_check : bool, optional
            If `True`, rigorous check, O(N) operations. Otherwise
            basic check, O(1) operations (default True).
        )�row�column�iz'indptr array has non-integer dtype ({})r*��
stacklevelz(indices array has non-integer dtype ({})r%rz'data, indices, and indptr should be 1-Dz&index pointer size ({}) should be ({})rz!index pointer should start with 0z*indices and data should have the same sizerTzQLast value of index pointer should be less than the size of index and data arraysz{} index values must be < {}z{} index values must be >= 0z8index pointer values must form a non-decreasing sequenceN)r>r)r?r&�kindrr2�namer=rr9rErr<�ndimrDr@�prune�nnzr8�minrX)rIr0�
major_name�
minor_namerPrQrM�xrRrRrSrH�sX
����
���z_cs_matrix.check_formatcCs*|��|j||j|�dd�}|��|S)z�Scalar version of self._binopt, for cases in which no new nonzeros
        are added. Produces a new spmatrix in canonical form.
        Tr.)�sum_duplicates�
_with_datar<�eliminate_zeros)rIrN�op�resrRrRrS�_scalar_binopt�sz_cs_matrix._scalar_binoptcCst|�r;t�|�r|j|jtjd�S|dkr4tdtdd�|�tj|jtjd��}|�	|t
j�}||S|�	|t
j�St
|�rE|��|kSt|�rKtSt|�r�tdtdd�|j|jkr^dS|j|jkrj|�|j�}|�|d�}|�tj|jtjd��}||SdS)	Nr%rzOComparing a sparse matrix with 0 using == is inefficient, try using != instead.r*r_zHComparing sparse matrices using == is inefficient, try using != instead.F�_ne_)rr9�isnanrAr)�bool_rr�onesro�operator�ne�eqr�todenser �NotImplementedrr2r3�_binopt)rIrN�all_true�invrnrRrRrS�__eq__�s8
��z_cs_matrix.__eq__cCs�t|�rGt�|�rtdtdd�|�tj|jtjd��}|S|dkr@tdtdd�|jt�|j�tjd�}|�	|t
j�}||S|�	|t
j�St
|�rQ|��|kSt|�rWtSt|�ru|j|jkrcdS|j|jkro|�|j�}|�|d�SdS)	Nz:Comparing a sparse matrix with nan using != is inefficientr*r_r%rz^Comparing a sparse matrix with a nonzero scalar using != is inefficient, try using == instead.Trp)rr9rqrrrArsr)rrrortrvrurrwr rxrr2r3ry)rIrNrzr{rRrRrS�__ne__�s4
��z_cs_matrix.__ne__cCst|�r;d|kr|dvrtd��|d|�r5t|t�tj|jt�|�d�}|�|�|�	|�}|�
||�S|�||�St|�rF||�
�|�St|�r�|j|jkrTtd��|j|jkr`|�|j�}|dvrj|�
||�Stdt�|�	tj|jtjd��}|�
||dkr�d	nd
�}||Std��)Nr)�_le_�_ge_z >= and <= don't work with 0.r%�inconsistent shapes)rr~zUComparing sparse matrices using >= and <= is inefficient, using <, >, or !=, instead.r~�_gt_�_lt_zOperands could not be compared.)r�NotImplementedErrorrrr9�emptyr)�result_type�fillrAryrorrwrrDr2r3rsrr)rIrNrm�op_name�bad_scalar_msg�	other_arrrzrnrRrRrS�_inequalitys4



�z_cs_matrix._inequalitycC�|�|tjdd�S)Nr�zgComparing a sparse matrix with a scalar greater than zero using < is inefficient, try using >= instead.)r�rt�lt�rIrNrRrRrS�__lt__?��z_cs_matrix.__lt__cCr�)Nr�zdComparing a sparse matrix with a scalar less than zero using > is inefficient, try using <= instead.)r�rt�gtr�rRrRrS�__gt__Er�z_cs_matrix.__gt__cCr�)Nr~zgComparing a sparse matrix with a scalar greater than zero using <= is inefficient, try using > instead.)r�rt�ler�rRrRrS�__le__Kr�z_cs_matrix.__le__cCr�)NrzdComparing a sparse matrix with a scalar less than zero using >= is inefficient, try using < instead.)r�rt�ger�rRrRrS�__ge__Qr�z_cs_matrix.__ge__cCs�|j|jkrtd�|j|j���t|jj|jj�}|�d�d}tj|||dd�}|�|j�\}}|j	j
r7|n|j}t|||j
|j|j|�|j|dd�S)NzIncompatible shapes ({} and {})�CFrT)r&�orderr-Fr.)r)rDr2rr&�charr>r9rC�flags�c_contiguous�Tr
r?r=r<�
_container)rIrNr&r��resultrKrL�yrRrRrS�
_add_dense[s�z_cs_matrix._add_densecC�|�|d�S)N�_plus_�ryr�rRrRrS�_add_sparseg�z_cs_matrix._add_sparsecCr�)N�_minus_r�r�rRrRrS�_sub_sparsejr�z_cs_matrix._sub_sparsecCs&t|�r	|�|�St|��r|j|jkr|�|�}|�|d�S|jdkr-|�|��d�S|jdkr;|�|��d�S|jddkrP|jddkrP|�|���S|jddkre|jddkre|�|���S|jddkr�|jd|jdkr�|j	|���
�dgf|jd|jdfd�}|�|�S|jddkr�|jd|jdkr�|j	|���
�dgf|jd|jdfd�}|�|�S|jddkr�|jd|jdkr�|j	|���
�dgf|jd|jdfd�}|�|�S|jddk�r|jd|jdk�r|j	|���
�dgf|jd|jdfd�}|�|�Std��t�
|�}|jdk�r.t�|��|�S|jdk�r<|�|jd�S|jdk�rLt�|��d|�S|��}|j|jk�rft�|j||j|jf�}�n"|jddk�r�|jddk�r~t�|j|�}n|jd|jdk�r�t�|j|d	d	�|jf�}ntd��t�t�|jd�t|j��}t�|j|jd�}|j|�tj��
�||ff|jd|jdfd
d�S|jddk�r@|jddk�r�t�|jd	d	�d	f|�}n |jd|jdk�r	t�|jd	d	�d	f||j�}ntd��t�|j|jd�}t�t�|jd�t|j��}|j|�tj��
�||ff|jd|jdfd
d�S|jddk�rd|jd|jdk�rdt�|j|d	d	�|jf�
��}n$|jddk�r�|jd|jdk�r�t�|j||j�
��}ntd��|�tj��
�|_|S)zPPoint-wise multiplication by another matrix, vector, or
        scalar.
        �_elmul_)rr)rrrr�r)r�r'NF�r)r-)r�_mul_scalarrr)rAry�toarray�_mul_sparse_matrix�tocsc�_dia_container�ravelrDr9�
atleast_2drc�multiply�size�flat�tocoor<r\�col�repeat�aranger@�tilerB�view�ndarray)rIrNr-�retr<r\r�rRrRrSr�ms�




"�
"�
"�
&�

�"�&"&z_cs_matrix.multiplycCsT|j\}}tj|t|jj|jj�d�}tt|jd�}||||j	|j
|j||�|S)Nr%�_matvec)r)r9r:rr&r��getattrr
r2r?r=r<)rIrNrKrLr��fnrRrRrS�_mul_vector�s
�z_cs_matrix._mul_vectorc
Csl|j\}}|jd}tj||ft|jj|jj�d�}tt|jd�}|||||j	|j
|j|��|���|S)Nrr%�_matvecs)
r)r9r:rr&r�r�r
r2r?r=r<r�)rIrNrKrL�n_vecsr�r�rRrRrS�_mul_multivector�s


��z_cs_matrix._mul_multivectorc
Csf|j\}}|j\}}|�||f�d}|�|�}t|j|j|j|jf�}tt|jd�}|||t	j
|j|d�t	j
|j|d�t	j
|j|d�t	j
|j|d��}	t|j|j|j|jf|	d�}t	j|d|d�}
t	j|	|d�}t	j|	t|j
|j
�d�}tt|jd�}|||t	j
|j|d�t	j
|j|d�|jt	j
|j|d�t	j
|j|d�|j|
||�|j|||
f||fd�S)Nr�_matmat_maxnnzr%r"r�_matmatr�)r)r>rArr?r=r�r
r2r9rEr�rr&r<)
rIrNrK�K1�K2rL�
major_axisrMr�rer?r=r<rRrRrSr��s@



��
���z_cs_matrix._mul_sparse_matrixrcCs�|j\}}||ks||krtjd|jjd�Stt|jd�}tjt|t|d�|t	|d��t
|j�d�}|||jd|jd|j|j|j|�|S)Nrr%�	_diagonalr)
r)r9r�r<r&r�r
r2rfr8rr?r=)rI�k�rows�colsr�r�rRrRrS�diagonals
 ��z_cs_matrix.diagonalcCs�t|�rI||�r+tdtdd�tj|jt�|�jd�}|�|�|�	|�}|�
||�S|��||jt�|��}|j	||j
|jf|j|jd�}|St|�rT||��|�St|�r^|�
||�Std��)NzITaking maximum (minimum) with > 0 (< 0) number results to a dense matrix.r*r_r%)r&r)zOperands not compatible.)rrrr9r�r)rEr&r�rAryrjr<r=r?rrwrrD)rIrN�npopr��dense_checkr��new_data�matrRrRrS�_maximum_minimum0s*�

�z_cs_matrix._maximum_minimumcC�|�|tjddd��S)N�	_maximum_cSst�|�dkS�Nr�r9rE�rirRrRrS�<lambda>I�z$_cs_matrix.maximum.<locals>.<lambda>)r�r9�maximumr�rRrRrSr�G�
�z_cs_matrix.maximumcCr�)N�	_minimum_cSst�|�dkSr�r�r�rRrRrSr�Or�z$_cs_matrix.minimum.<locals>.<lambda>)r�r9�minimumr�rRrRrSr�Mr�z_cs_matrix.minimumcCs�t|d�sO||�d�dvrOt|j�}tjt|j�d|d�}|�tj	�\}}|||<|�
|�}|ddkr9|j}|durG|j|jkrGt
d��|jd	||d
�Stj||||d
�S)z~Sum the matrix over the given axis.  If the axis is None, sum
        over both rows and columns, returning a scalar.
        �	blocksize))rrT)rr'rrr%r'Nzdimensions do not matchrR)rYr&�out)�hasattrr>rr&r9r:r@r?�
_minor_reduce�add�_ascontainerr�r)rD�sumr)rIrYr&r��	res_dtyper��major_index�valuerRrRrSr�Ws


z_cs_matrix.sumcCs>|dur|j}t�t�|j��}|�|t|j|��}||fS)a�Reduce nonzeros with a ufunc over the minor axis when non-empty

        Can be applied to a function of self.data by supplying data parameter.

        Warning: this does not call sum_duplicates()

        Returns
        -------
        major_index : array of ints
            Major indices where nonzero

        value : array of self.dtype
            Reduce result for nonzeros in each major_index
        N)r<r9�flatnonzerorXr?�reduceatr)rI�ufuncr<r�r�rRrRrSr�ts�z_cs_matrix._minor_reducec
Cs\|�|j�\}}|�||f�\}}t|||j|j|j||d||d�	\}}}	|	j|jd�S)Nrr%)r>r)rr?r=r<r�r&)
rIr\r�rKrL�major�minorr?r=r<rRrRrS�_get_intXint�s
�z_cs_matrix._get_intXintcCsF|�||f�\}}|jdvr|jdvr|j||dd�S|�|��|�S)N)rNTr.)r>�step�_get_submatrix�_major_slice�_minor_slice�rIr\r�r�r�rRrRrS�_get_sliceXslice�sz_cs_matrix._get_sliceXslicec	
Cs�|jj}|�|j�\}}|�||f�\}}tj||d�}tj||d�}tj|j|jd�}t|||j	|j|j
|j|��|��|�	|jdkrJ|�
|�S|�|�|j��S)Nr%r)r=r&r>r)r9rEr�r�rr?r<r�rcr�rA�reshape)	rIr\r�rMrKrLr�r��valrRrRrS�_get_arrayXarray�s�

z_cs_matrix._get_arrayXarraycCs"|�||f�\}}|�|��|�S�N)r>�_major_index_fancy�_minor_index_fancyr�rRrRrS�_get_columnXarray�sz_cs_matrix._get_columnXarrayc
Cs�|jj}tj||d���}|�|j�\}}t|�}|�||f�}|dkr)|�|�S|j	|d|j	|}|jj}tj
|d|d�}	tj||	dd�d�|	d}
tj|
|d�}tj|
|jd�}t
|||j	|j|j||�|j|||	f|dd�S)	zBIndex along the major axis where idx is an array of ints.
        r%rrN�r�rTFr�)r=r&r9rEr�r>r)r@rAr?r:�cumsumr�rr<)
rI�idxrMr=rZrLrK�	new_shape�row_nnz�
res_indptrre�res_indices�res_datarRrRrSr��s(
��z_cs_matrix._major_index_fancyc	Cs�|td�kr|r|��S|S|�|j�\}}|�|�\}}}tt|||��}|�||f�}|dkr6|�|�S||}	}
|dkrE|dkrEd}
|d|d}}|j|||�|j|	|
|�}
|jj	}t
j|d|d�}t
j|
|dd�d�|dkr�t|j||j|�}t
j
|j||d�}t
j
|j||d�}n!|d}t
j||d�}t
j||j	d�}t||||j|j|j||�|j|||f|dd	�S)
z@Index along the major axis where idx is a slice object.
        NrrTrr%r�r.Fr�)�slicer-r>r)r=r@�rangerAr?r&r9r:r�rCr<r�r)rIr�r-rKrL�start�stopr�r��start0�stop0�start1�stop1r�rMr��all_idxrrrerRrRrSr��s>

���z_cs_matrix._major_slicec
	Cs�|jj}tj||d���}|�|j�\}}t|�}|�||f�}|dkr)|�|�Stj	||d�}t�
|j�}t|||||j|j||�t�
|�j|dd�}	|d}
tj|
|d�}tj|
|jd�}t|	|t|j�|j|j||�|j|||f|dd�S)zBIndex along the minor axis where idx is an array of ints.
        r%rFr.rTr�)r=r&r9rEr�r>r)r@rAr:�
empty_liker?r�argsortrGr�rr<)
rIr�rMrKrLr�r��col_offsetsr��	col_orderrerrrRrRrSr��s,
���z_cs_matrix._minor_index_fancycCs�|td�kr|r|��S|S|�|j�\}}|�|�\}}}tt|||��}|dkr4|�|�||f��S|dkr?|j||d�S|�	t
�|||��S)z@Index along the minor axis where idx is a slice object.
        Nrr)r�r-)rr-r>r)r=r@rrAr�r�r9r�)rIr�r-rKrLrrr�rRrRrSr�sz_cs_matrix._minor_slicec
Cs�|�|j�\}}t||�\}}t||�\}}	|dkr.|dkr.||kr.|	|kr.|r,|��S|St|||j|j|j||||	�	\}
}}|�|||	|f�}
|j|||
f|
|j	dd�S)zbReturn a submatrix of this matrix.

        major, minor: None, int, or slice with step 1
        rF)r)r&r-)
r>r)�_process_slicer-rr?r=r<rAr&)rIr�r�r-rKrL�i0�i1�j0�j1r?r=r<r)rRrRrSr�s 
��z_cs_matrix._get_submatrixcC�$|�||f�\}}|�|||�dSr��r>�	_set_many�rIr\r�rir^�jrRrRrS�_set_intXint1�z_cs_matrix._set_intXintcCrr�rrrRrRrS�_set_arrayXarray5rz_cs_matrix._set_arrayXarraycCs|j|�||f��|j\}}|dko|jddk}|dko$|jddk}|j|j}}	tj|j|jd�}|j	dkr<dS|rUt�
t�|�t|��}t�
|	|�}	t�
||�}|rnt�
||�}t�
t�|�t|	��}	t�
||�}|�|||	f|||	ff�\}
}|�|
||�dS)Nrrr%)�
_zero_manyr>r)r\r�r9rEr<r&r�r�r�r@r�r)rIr\r�rirKrL�
broadcast_row�
broadcast_col�r�cr^rrRrRrS�_set_arrayXarray_sparse9s$

"z"_cs_matrix._set_arrayXarray_sparsec	Cs�d|jvrdS|j\}}|jdk}|dkr@|rt|||�}n
t|||t|��}tj||jjd�}tj||jjd�}||8}n*|rJt|||�}n
t|||t|��}tj||jjd�}tj||jjd�}||7}|st|dt|��}||||f<dS)Nrr%)r)rcrfr@r9r�r=r&)	rI�valuesr�rKrL�	broadcast�	max_indexr^rrRrRrS�_setdiagRs(



z_cs_matrix._setdiagcCsl|�|j�\}}dd�}tj||jjddd���}tj||jjddd���}|||�|||�||||fS)NcSsF|��}||krtd||f��|��}||kr!td||f��dS)Nzindex (%d) out of range (>= %d)zindex (%d) out of range (< -%d))r8�
IndexErrorrf)r=�boundr�rRrRrS�check_boundsss�
��z1_cs_matrix._prepare_indices.<locals>.check_boundsFr�r&r-�ndmin)r>r)r9rCr=r&r�)rIr^rrKrLr(rRrRrS�_prepare_indicesps


z_cs_matrix._prepare_indicesc
	Cs"|�||�\}}}}tj||jddd���}|j}tj||jjd�}t|||j	|j||||�}|dkrD|�
�t|||j	|j||||�d|vrO||j|<dStd�
|j
�tdd	�|dk}	||	|j||	<|	}	||	}||d
k|7<||	}||d
k|7<|�||||	�dS)z�Sets value at each (i, j) to x

        Here (i,j) index major and minor respectively, and must not contain
        duplicate entries.
        Frr)r%rTNzZChanging the sparsity structure of a {}_matrix is expensive. lil_matrix is more efficient.r*r_r)r+r9rCr&r�r�r�r=rr?rjr<rr2r�_insert_many)
rIr^rrirKrL�	n_samples�offsetsr��maskrRrRrSr�s6��
�z_cs_matrix._set_manyc	Cs�|�||�\}}}}t|�}tj||jjd�}t|||j|j||||�}|dkr9|��t|||j|j||||�d|j	||dk<dS)z�Sets value at each (i, j) to zero, preserving sparsity structure.

        Here (i,j) index major and minor respectively.
        r%rrrTN)
r+r@r9r�r=r&rr?rjr<)rIr^rrKrLr-r.r�rRrRrSr�s��z_cs_matrix._zero_manycCs�tj|dd�}|j|dd�}|j|dd�}|j|dd�}|j}t|j|jf|jd|jd�}tj|j|d�|_tj|j|d�|_tj||d�}tj||d�}g}g}tj	|dd	�\}	}
t�
|
t|��}
t�|
�}d
}t
t|	|
|
dd���D]z\}
\}}}|j|}|j|}|�
|j||��|�
|j||��tj	|||�ddd�dd	�\}}t|�||kr�|�
|||��|�
|||��n&|�
|||�ddd�|�|�
|||�ddd�|�t|�||
<|}qw|j|}|�
|j|d��|�
|j|d��t�|�|_t�|�|_tj|jj|d�}|d
�|d
<t�|j�}||	|7<||dd�<tj||d
�|_|�rLd|_|��|jdd�dS)a:Inserts new nonzero at each (i, j) with value x

        Here (i,j) index major and minor respectively.
        i, j and x must be non-empty, 1d arrays.
        Inserts each major group (e.g. all entries per row) at a time.
        Maintains has_sorted_indices property.
        Modifies i, j, x in place.
        �	mergesort)ra�clip)�moderTr"r%T)�return_indexrrNr�Fr/)r9r�take�has_sorted_indicesrr=r?r�rE�unique�appendr@rX�	enumerate�zipr<�concatenater�r)r��sort_indicesrH)rIr^rrir��do_sortrM�
indices_parts�
data_parts�ui�	ui_indptr�new_nnzs�prevr �ii�js�jerr�uj�	uj_indptr�nnzs�indptr_diffrRrRrSr,�s\	�
&

$  
z_cs_matrix._insert_manycCsn|�|j�\}}|j}tjt|�|jjd�}t�||j	|�|�||f�\}}|j
|j||ff|j||jd�S)Nr%r,)r>r)r=r9r�r@r&r
�	expandptrr?rBr<)rIr-rPrQ�
minor_indices�
major_indicesr\r�rRrRrSr�
s�z_cs_matrix.tocoocCs�|dur|dur|�d�d}|�||�}|jjs!|jjs!td��|jjr,|��}|}n|��}|j}|�|j	�\}}t
|||j|j|j
|�|S)N�cfrz&Output array must be C or F contiguous)r>�_process_toarray_argsr�r��f_contiguousrD�tocsrr�r�r)r
r?r=r<)rIr�r�rir�rKrLrRrRrSr�sz_cs_matrix.toarraycCs4|�|j�\}}t�|||j|j|j�|��dS)zVRemove zero entries from the matrix

        This is an *in place* operation.
        N)r>r)r
�csr_eliminate_zerosr?r=r<rd�rIrKrLrRrRrSrl/s
�z_cs_matrix.eliminate_zeroscCsJt|dd�sd|_|jSt|d�s"tt�t|j�d|j|j��|_	|jS)a^Determine whether the matrix has sorted indices and no duplicates

        Returns
            - True: if the above applies
            - False: otherwise

        has_canonical_format implies has_sorted_indices, so if the latter flag
        is False, so will the former be; if the former is found True, the
        latter flag is also set.
        �_has_sorted_indicesTF�_has_canonical_formatr)
r�rTr��boolr
�csr_has_canonical_formatr@r?r=�has_canonical_format�rIrRrRrS�__get_has_canonical_format9s

���z%_cs_matrix.__get_has_canonical_formatcCst|�|_|rd|_dSdS)NT)rUrTr5�rIr�rRrRrS�__set_has_canonical_formatOs

�z%_cs_matrix.__set_has_canonical_format)�fget�fsetcCsL|jrdS|��|�|j�\}}t�|||j|j|j�|�	�d|_dS)zmEliminate duplicate matrix entries by adding them together

        This is an *in place* operation.
        NT)
rWr;r>r)r
�csr_sum_duplicatesr?r=r<rdrRrRrRrSrjWs�
z_cs_matrix.sum_duplicatescCs2t|d�stt�t|j�d|j|j��|_|jS)z�Determine whether the matrix has sorted indices

        Returns
            - True: if the indices of the matrix are in sorted order
            - False: otherwise

        rSr)r�rUr
�csr_has_sorted_indicesr@r?r=rSrXrRrRrS�__get_sortedgs

��z_cs_matrix.__get_sortedcCst|�|_dSr�)rUrSrZrRrRrS�__set_sortedwsz_cs_matrix.__set_sortedcCs|��}|��|S)z9Return a copy of this matrix with sorted indices
        )r-r;)rI�ArRrRrS�sorted_indices|sz_cs_matrix.sorted_indicescCs4|jst�t|j�d|j|j|j�d|_dSdS)z3Sort the indices of this matrix *in place*
        rTN)r5r
�csr_sort_indicesr@r?r=r<rXrRrRrSr;�s�
�z_cs_matrix.sort_indicescCs�|�|j�d}t|j�|dkrtd��t|j�|jkr!td��t|j�|jkr-td��t|jd|j��|_t|jd|j��|_dS)z8Remove empty space after all non-zero elements.
        rrz index pointer has invalid lengthz)indices array has fewer than nnz elementsz&data array has fewer than nnz elementsN)	r>r)r@r?rDr=rer<r)rIrPrRrRrSrd�sz_cs_matrix.prunec
Gs�t|�}t|d�r=|j\}}t|d|�\}}t|d|�\}}|s$|r-td|j|f��|jd||jd|}}	n|�|�\}}|�|j�\}}	||krq|jd|j|�|_|j	d|j|�|_	|jd|d�|_n||kr�t
�|j|d�|_|j|dd��|j|�||	kr�|j|k}
t
�
|
�s�|j|
|_|j	|
|_	|�t
j|
�\}}|j�d�||jdd�|<t
j|j|jd�||_dS)Nr�rrz.shape must be divisible into %s blocks. Got %sr�)rr�r��divmodrDr)r>r=r?r<r9�resizer��allr�r�r�r7)
rIr)�bm�bn�new_M�rm�new_N�rnrKrLr/r�r�rRrRrSrf�s:

� 


z_cs_matrix.resizecCsH|r|j||j��|j��f|j|jd�S|j||j|jf|j|jd�S)z�Returns a matrix with the same sparsity structure as self,
        but with different data.  By default the structure arrays
        (i.e. .indptr and .indices) are copied.
        r()rAr=r-r?r)r&)rIr<r-rRrRrSrk�s���z_cs_matrix._with_datacCs |�|�}tt|j||j�}|j|j}t|j|j|j|jf|d�}tj	|jj
|d�}tj	||d�}gd�}||vrEtj	|tjd�}	ntj	|t|j
|j
�d�}	||j
d|j
dtj|j|d�tj|j|d�|jtj|j|d�tj|j|d�|j|||	�|j|	||f|j
d�}
|
��|
S)z5apply the binary operation fn to two sparse matrices.r"r%)rpr�r�r~rrrr�)rAr�r
r2rerr?r=r9r�r)rrrr&rEr<rd)rIrNrmr��maxnnzrMr?r=�bool_opsr<rbrRrRrSry�s4

���	z_cs_matrix._binoptcCs�|j|jkr
td��|�|d�}t�|jtj�rGtj|j|jd�}|�tj	�|�
�\}}d|||f<|��}|j||j
|jf<|�|�}|S|}|S)z?
        Divide this matrix by a second sparse matrix.
        r��_eldiv_r%r)r)rDryr9�
issubdtyper&�inexactr�r��nan�nonzeror�r<r\r�r�)rIrNrr�r\r�rRrRrS�_divide_sparse�s
�z_cs_matrix._divide_sparse)NNFr�)F)T)r)NNN)NN)A�__name__�
__module__�__qualname__�__doc__r1r[rr4rHror|r}r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrr!r%r+rrr,r�r�rl�$_cs_matrix__get_has_canonical_format�$_cs_matrix__set_has_canonical_format�propertyrWrj�_cs_matrix__get_sorted�_cs_matrix__set_sortedr5rcr;rdrfrkryrurRrRrRrSr!s�

R


F	$""
s

$






(

'
L



�	
"
"r!cCs�|dur
d|}}||fSt|t�r+|�|�\}}}|dkr"td��t||�}||fSt|�rS|dkr7||7}||d}}|dksF||krOtd|||f��||fStd��)Nrrz$slicing with step != 1 not supportedz'index out of bounds: 0 <= %d < %d <= %dzexpected slice or scalar)r5rr=rDrfrr&�	TypeError)�sl�numrr�striderRrRrSrs&

�
���r),ry�__all__�warningsrrt�numpyr9�scipy._lib._utilr�_baserrr�_datarr	�r
rrr
rrrrr�_indexr�_sputilsrrrrrrrrrrrrr r!rrRrRrRrS�<module>s0(<

Youez - 2016 - github.com/yon3zu
LinuXploit