o
    Ö­jãY  ã                   @   sÄ   d Z dZg d¢ZddlZddlmZ ddlZddlm	Z	 ddl
mZmZmZ dd	lmZ dd
lmZmZmZmZmZmZmZmZ G dd„ deeeƒZdd„ ZG dd„ deeƒZG dd„ de	eƒZdS )zDictionary Of Keys based matrixzrestructuredtext en)Ú	dok_arrayÚ
dok_matrixÚisspmatrix_doké    N)Úwarné   )Úspmatrix)Ú_spbaseÚsparrayÚissparse)Ú
IndexMixin)ÚisdenseÚgetdtypeÚisshapeÚ	isintlikeÚisscalarlikeÚupcastÚupcast_scalarÚcheck_shapec                       sN  e Zd ZdZdZd{ddœdd„Zdd	„ Zd|d
d„Zd|dd„Ze	jj
e_
e	jj
e_
dd„ Zdd„ Zd|dd„Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zd d!„ Zd"d#„ Zd$d%„ Zd&d'„ Zd(d)„ Zd}d+d,„Zd-d.„ Zd/d0„ Zd1d2„ Zd3d4„ Zd5d6„ Zd7d8„ Zd9d:„ Z d;d<„ Z!d=d>„ Z"d?d@„ Z#dAdB„ Z$dCdD„ Z%dEdF„ Z&dGdH„ Z'dIdJ„ Z(dKdL„ Z)dMdN„ Z*dOdP„ Z+dQdR„ Z,dSdT„ Z-dUdV„ Z.dWdX„ Z/dYdZ„ Z0d[d\„ Z1d]d^„ Z2d_d`„ Z3dadb„ Z4d~‡ fddde„	Z5ddfdg„Z6e	j6j
e6_
dhdi„ Z7djdk„ Z8e	j8j
e8_
e9d€dmdn„ƒZ:d�dodp„Z;e	j;j
e;_
d�dqdr„Z<e	j<j
e<_
d�dsdt„Z=e	j=j
e=_
dudv„ Z>e	j>j
e>_
d‚dydz„Z?‡  Z@S )ƒÚ	_dok_baseÚdok)r   é   NF©Úmaxprintc             
   C   sˆ  t j| ||d� t|tƒr(t|| jd�r(t|| jd�| _i | _t	|t
d�| _d S t|ƒr_|j| jkr;|r8| ¡ n|}n| ¡ }|d urJ|j|dd�}|j| _t|j| jd�| _t	|jƒ| _d S zt |¡}W n tyw } ztdƒ|‚d }~ww |jdkr†td|j› d	�ƒ‚|jd
kr¥|d ur”| |¡}dd„ t|ƒD ƒ| _t	|jƒ| _n| j|||d� ¡ }|j| _t	|jƒ| _t|j| jd�| _d S )Nr   ©Úallow_nd)ÚdefaultF©ÚcopyzInvalid input format.r   zDOK arrays don't yet support zD input.r   c                 S   s   i | ]\}}|d kr||“qS ©r   © )Ú.0ÚiÚvr   r   úN/var/www/html/CropPilot/venv/lib/python3.10/site-packages/scipy/sparse/_dok.pyÚ
<dictcomp>5   s    z&_dok_base.__init__.<locals>.<dictcomp>©ÚshapeÚdtype)r   Ú__init__Ú
isinstanceÚtupler   Ú	_allow_ndr   Ú_shapeÚ_dictr   Úfloatr'   r
   Úformatr   ÚtodokÚastyper&   ÚnpÚasarrayÚ	ExceptionÚ	TypeErrorÚndimÚ
ValueErrorÚ	enumerateÚ_coo_container)ÚselfÚarg1r&   r'   r   r   ÚeÚdr   r   r#   r(      s>   
€ÿ


z_dok_base.__init__c                 C   ó   t dƒ‚)Nz2Direct update to DOK sparse format is not allowed.)ÚNotImplementedError)r:   Úvalr   r   r#   Úupdate=   s   z_dok_base.updatec                 C   s   |d urt dƒ‚t| jƒS )Nz7_getnnz over an axis is not implemented for DOK format.)r?   Úlenr-   ©r:   Úaxisr   r   r#   Ú_getnnzA   s
   ÿ
z_dok_base._getnnzc                 C   s&   |d urt dƒ‚tdd„ |  ¡ D ƒƒS )Nz=count_nonzero over an axis is not implemented for DOK format.c                 s   s   � | ]}|d kV  qdS ©r   Nr   )r    Úxr   r   r#   Ú	<genexpr>M   s   € z*_dok_base.count_nonzero.<locals>.<genexpr>)r?   ÚsumÚvaluesrC   r   r   r#   Úcount_nonzeroH   s
   ÿz_dok_base.count_nonzeroc                 C   s
   t | jƒS ©N)rB   r-   ©r:   r   r   r#   Ú__len__R   ó   
z_dok_base.__len__c                 C   s
   || j v S rL   ©r-   ©r:   Úkeyr   r   r#   Ú__contains__U   rO   z_dok_base.__contains__c                C   s   | j  ||¡S rL   )r-   Ú
setdefault)r:   rR   r   r   r   r#   rT   X   s   z_dok_base.setdefaultc                C   s   | j |= d S rL   rP   rQ   r   r   r#   Ú__delitem__[   ó   z_dok_base.__delitem__c                 C   ó
   | j  ¡ S rL   )r-   ÚclearrM   r   r   r#   rX   ^   rO   z_dok_base.clearc                G   s   | j j|Ž S rL   )r-   Úpop)r:   Úargsr   r   r#   rY   a   rV   z_dok_base.popc                 C   r>   )Nz*reversed is not defined for dok_array type)r5   rM   r   r   r#   Ú__reversed__d   ó   z_dok_base.__reversed__c                 C   ó(   t | ƒj› dt |ƒj› �}td|› �ƒ‚©Nz and z unsupported operand type for |: ©ÚtypeÚ__name__r5   ©r:   ÚotherÚ
type_namesr   r   r#   Ú__or__g   ó   z_dok_base.__or__c                 C   r]   r^   r_   rb   r   r   r#   Ú__ror__k   rf   z_dok_base.__ror__c                 C   r]   r^   r_   rb   r   r   r#   Ú__ior__o   rf   z_dok_base.__ior__c                 C   rW   rL   )r-   ÚpopitemrM   r   r   r#   ri   s   rO   z_dok_base.popitemc                 C   rW   rL   )r-   ÚitemsrM   r   r   r#   rj   v   rO   z_dok_base.itemsc                 C   rW   rL   )r-   ÚkeysrM   r   r   r#   rk   y   rO   z_dok_base.keysc                 C   rW   rL   )r-   rJ   rM   r   r   r#   rJ   |   rO   z_dok_base.valuesç        c              
   C   sê   || j v r
| j | S t|ƒr| jdkr|f}| jt|ƒkr%td|› d�ƒ‚z|D ]}t|ƒs0J ‚q(W n tttfyF } ztdƒ|‚d}~ww tdd„ t	|| j
ƒD ƒƒ}tdd„ t	|| j
ƒD ƒƒretd	ƒ‚| jdkrn|d
 }| j  ||¡S )z>This provides dict.get method functionality with type checkingr   zIndex z! length needs to match self.shapez%Index must be or consist of integers.Nc                 s   s(   � | ]\}}|d k r|| n|V  qdS rF   r   ©r    r!   ÚMr   r   r#   rH   Œ   s   €& z _dok_base.get.<locals>.<genexpr>c                 s   s$   � | ]\}}|d k p||kV  qdS rF   r   rm   r   r   r#   rH   �   ó   €" zIndex out of bounds.r   )r-   r   r6   rB   Ú
IndexErrorÚAssertionErrorr5   r7   r*   Úzipr&   ÚanyÚget)r:   rR   r   r!   r<   r   r   r#   rt      s(   

ÿ
€ÿ
z_dok_base.getc                 C   s   | j  || j d¡¡S ©Nr   ©r-   rt   r'   r`   )r:   Úidxr   r   r#   Ú_get_int”   ó   z_dok_base._get_intc                 C   s"   t | | jd ¡Ž }|  t|ƒ¡S ru   )ÚrangeÚindicesr&   Ú
_get_arrayÚlist)r:   rw   Úi_ranger   r   r#   Ú
_get_slice—   s   z_dok_base._get_slicec                    sú   t  |¡}|jdkrˆ j t|ƒˆ j d¡¡}t j|ˆ jd�S ˆ j	|j
ˆ jd�}‡ fdd„| ¡ D ƒ}|r{t|j
ƒdkrNt|ƒD ]\}}|rK||j|< q@|S t  t  t|ƒ¡|j
¡}t|ƒdkrd|d nt|Ž }t||dd�D ]\}}|rz||j|< qo|S )	Nr   )Ústype©r'   c                    s   g | ]	}ˆ j  |d ¡‘qS r   )r-   rt   )r    r!   rM   r   r#   Ú
<listcomp>¡   s    z(_dok_base._get_array.<locals>.<listcomp>r   T)Ústrict)r2   r3   r6   r-   rt   Úintr'   r`   ÚarrayÚ_dok_containerr&   ÚravelrB   r8   Úunravel_indexÚarangerr   )r:   rw   r@   Únew_dokÚdok_valsr!   r"   Únew_idxr   rM   r#   r|   ›   s(   


€û
€z_dok_base._get_arrayc                 C   s   | j  ||f| j d¡¡S ru   rv   ©r:   ÚrowÚcolr   r   r#   Ú_get_intXint°   s   z_dok_base._get_intXintc                 C   s   |   t||d ƒ|¡S ©Nr   ©Ú_get_sliceXsliceÚslicer�   r   r   r#   Ú_get_intXslice³   ry   z_dok_base._get_intXslicec                 C   s   |   |t||d ƒ¡S r‘   r’   r�   r   r   r#   Ú_get_sliceXint¶   ry   z_dok_base._get_sliceXintc                 C   s"  |  | jd ¡\}}}|  | jd ¡\}}}t|||ƒ}	t|||ƒ}
t|	ƒt|
ƒf}t| ƒd|d  |d  kr>|  |	|
¡S | j|| jd�}|  ¡ D ]D}tt	|d ƒ| |ƒ\}}|dksg|dk sg||d krhqJtt	|d ƒ| |ƒ\}}|dksƒ|dk sƒ||d kr„qJ| j
| |j
||f< qJ|S )Nr   r   r   r�   )r{   r&   rz   rB   Ú_get_columnXarrayr†   r'   rk   Údivmodr„   r-   )r:   rŽ   r�   Ú	row_startÚrow_stopÚrow_stepÚ	col_startÚcol_stopÚcol_stepÚ	row_rangeÚ	col_ranger&   ÚnewdokrR   r!   ÚriÚjÚrjr   r   r#   r“   ¹   s"   z_dok_base._get_sliceXslicec                 C   s   |   |g| ¡ ¡S rL   )r—   r‡   r�   r   r   r#   Ú_get_intXarrayÐ   s   z_dok_base._get_intXarrayc                 C   s,   |   | ¡ |g¡}|jdkr| |j¡S |S r‘   )r—   r‡   r6   Úreshaper&   )r:   rŽ   r�   Úresr   r   r#   Ú_get_arrayXintÓ   s   
z_dok_base._get_arrayXintc                 C   s$   t t| | jd ¡Ž ƒ}|  ||¡S ru   ©r}   rz   r{   r&   r—   r�   r   r   r#   Ú_get_sliceXarrayÙ   ó   z_dok_base._get_sliceXarrayc                 C   s$   t t| | jd ¡Ž ƒ}|  ||¡S r‘   r©   r�   r   r   r#   Ú_get_arrayXsliceÝ   r«   z_dok_base._get_arrayXslicec           	      C   sh   | j t|ƒt|ƒf| jd�}t|ƒD ]\}}t|ƒD ]\}}| j ||fd¡}|r0||j||f< qq|S )Nr�   r   )r†   rB   r'   r8   r-   rt   )	r:   rŽ   r�   r¡   r!   Úrr£   Úcr"   r   r   r#   r—   á   s   €ýz_dok_base._get_columnXarrayc                 C   s|   t tjt ||¡ƒ\}}| j|j| jd�}t t	|jd ƒt	|jd ƒ¡D ]}| j
 || || fd¡}|r;||j
|< q%|S )Nr�   r   r   )Úmapr2   Ú
atleast_2dÚbroadcast_arraysr†   r&   r'   Ú	itertoolsÚproductrz   r-   rt   )r:   rŽ   r�   r!   r£   r¡   rR   r"   r   r   r#   Ú_get_arrayXarrayì   s   $
€z_dok_base._get_arrayXarrayc                 C   s,   |r	|| j |< d S || j v r| j |= d S d S rL   rP   )r:   rw   rG   r   r   r#   Ú_set_intø   s
   
ÿz_dok_base._set_intc                 C   sŠ   |  ¡ }|  ¡ }t|ƒt|ƒkr(t|ƒdkr$tjt|ƒ|d | jd�}ntdƒ‚t||ƒD ]\}}|r9|| j|< q-|| jv rB| j|= q-d S )Nr   r   r�   z*Need len(index)==len(data) or len(data)==1)r‡   rB   r2   Úfullr'   r7   rr   r-   )r:   rw   rG   Úidx_setÚx_setr!   r"   r   r   r#   Ú
_set_arrayþ   s   
€üz_dok_base._set_arrayc                 C   s4   ||f}|r|| j |< d S || j v r| j |= d S d S rL   rP   )r:   rŽ   r�   rG   rR   r   r   r#   Ú_set_intXint  s   
ÿz_dok_base._set_intXintc                 C   s†   t tt| ¡ ƒƒ}t tt| ¡ ƒƒ}| ¡ }| j tt||ƒ|ƒ¡ t |dk¡d D ]}|| || f}| j| dkr@| j|= q+d S ru   )	r}   r¯   r„   r‡   r-   rA   rr   r2   Únonzero)r:   rŽ   r�   rG   r!   rR   r   r   r#   Ú_set_arrayXarray  s   €üz_dok_base._set_arrayXarrayc                    s\  t |ƒr1t| j|ƒ}| j| j|d�‰ tjdd„ | jD ƒŽ D ]}| j |d¡| }|r.|ˆ |< qˆ S t	|ƒr |j| jkr?t
dƒ‚t| j|jƒ}| j| j|d�‰ | j ¡ ˆ _|jdkr^| ¡ }n| ¡ }| jdkrqt|jd |jƒ}n	tt|jŽ |jƒ}tjdd	�� ˆ j ‡ fd
d„|D ƒ¡ W d   ƒ ˆ S 1 s™w   Y  ˆ S t|ƒr¬|  ¡ | ‰ ˆ S tS )Nr�   c                 S   s   g | ]}t |ƒ‘qS r   )rz   )r    r=   r   r   r#   r‚   %  s    z%_dok_base.__add__.<locals>.<listcomp>r   z Matrix dimensions are not equal.r   r   Úignore)Úoverc                 3   s$   � | ]\}}|ˆ | | fV  qd S rL   r   ©r    Úkr"   ©Únewr   r#   rH   8  ro   z$_dok_base.__add__.<locals>.<genexpr>)r   r   r'   r†   r&   r²   r³   r-   rt   r
   r7   r   r   r/   rj   Útocoor6   rr   ÚcoordsÚdatar2   ÚerrstaterA   r   ÚtodenseÚNotImplemented)r:   rc   Ú	res_dtyperR   ÚaijÚo_itemsr   rÁ   r#   Ú__add__   s>   €ì



ÿúüÿz_dok_base.__add__c                 C   s   | | S rL   r   ©r:   rc   r   r   r#   Ú__radd__?  r\   z_dok_base.__radd__c                 C   sD   | j jdkr
tdƒ‚| j| j| j d�}|j dd„ |  ¡ D ƒ¡ |S )NÚbz2Negating a sparse boolean matrix is not supported.r�   c                 s   s   � | ]
\}}|| fV  qd S rL   r   r¿   r   r   r#   rH   H  s   € z$_dok_base.__neg__.<locals>.<genexpr>)r'   Úkindr?   r†   r&   r-   rA   rj   ©r:   rÂ   r   r   r#   Ú__neg__B  s   ÿz_dok_base.__neg__c                    s>   t | jˆ ƒ}| j| j|d�}|j ‡ fdd„|  ¡ D ƒ¡ |S )Nr�   c                 3   ó    � | ]\}}||ˆ  fV  qd S rL   r   r¿   ©rc   r   r#   rH   O  ó   € z(_dok_base._mul_scalar.<locals>.<genexpr>)r   r'   r†   r&   r-   rA   rj   ©r:   rc   rÉ   rÂ   r   rÔ   r#   Ú_mul_scalarK  s   z_dok_base._mul_scalarc                    sÞ   t ˆjˆ jƒ}ˆjdkrLtˆ ƒr7ˆ jdkrˆ ¡ ˆ  ¡ @ }nˆ ¡ ˆ  ¡ jd @ }|t‡ ‡fdd„|D ƒƒƒS t	ˆ ƒrJ|t‡ fdd„ˆ 
¡ D ƒƒƒS tS tjˆjd |d�}ˆ 
¡ D ]\\}}}||  |ˆ |  7  < qZ|S )Nr   r   r   c                 3   s$   � | ]}ˆj | ˆ j |  V  qd S rL   rP   )r    rÀ   ©rc   r:   r   r#   rH   \  ro   z+_dok_base._matmul_vector.<locals>.<genexpr>c                 3   s    � | ]\}}ˆ | | V  qd S rL   r   r¿   rÔ   r   r#   rH   ^  rÕ   r�   )r   r'   r6   r
   r/   rk   rÃ   rÄ   rI   r   rj   rÈ   r2   Úzerosr&   )r:   rc   rÉ   rk   Úresultr!   r£   r"   r   rØ   r#   Ú_matmul_vectorR  s   

z_dok_base._matmul_vectorc           	         sœ   t | jˆ jƒ}| jdkrt‡ fdd„| j ¡ D ƒƒS | jd }ˆ jdkr'|fn|ˆ jd f}tj||d�}|  ¡ D ]\\}}}||  |ˆ |  7  < q9|S )Nr   c                 3   s    � | ]\}}|ˆ |  V  qd S rL   r   )r    r£   r"   rÔ   r   r#   rH   m  rÕ   z0_dok_base._matmul_multivector.<locals>.<genexpr>r   r�   )	r   r'   r6   rI   r-   rj   r&   r2   rÙ   )	r:   rc   Úresult_dtypern   Ú	new_shaperÚ   r!   r£   r"   r   rÔ   r#   Ú_matmul_multivectorh  s   

z_dok_base._matmul_multivectorc                    ó.   t ˆ ƒr| j ‡ fdd„|  ¡ D ƒ¡ | S tS )Nc                 3   rÓ   rL   r   r¿   rÔ   r   r#   rH   y  rÕ   z%_dok_base.__imul__.<locals>.<genexpr>©r   r-   rA   rj   rÈ   rÍ   r   rÔ   r#   Ú__imul__w  ó   z_dok_base.__imul__c                    sR   t ˆ ƒr#t| jˆ ƒ}| j| j|d�}|j ‡ fdd„|  ¡ D ƒ¡ |S |  ¡ ˆ  S )Nr�   c                 3   ó    � | ]\}}||ˆ  fV  qd S rL   r   r¿   rÔ   r   r#   rH   �  rÕ   z(_dok_base.__truediv__.<locals>.<genexpr>)	r   r   r'   r†   r&   r-   rA   rj   ÚtocsrrÖ   r   rÔ   r#   Ú__truediv__}  s   z_dok_base.__truediv__c                    rß   )Nc                 3   rã   rL   r   r¿   rÔ   r   r#   rH   ‡  rÕ   z)_dok_base.__itruediv__.<locals>.<genexpr>rà   rÍ   r   rÔ   r#   Ú__itruediv__…  râ   z_dok_base.__itruediv__c                 C   s
   t  | ¡S rL   )ÚdictÚ
__reduce__rM   r   r   r#   rè   ‹  s   
z_dok_base.__reduce__r   c                    s   | j dkrtƒ  |¡S tdƒ‚)Nr   z diagonal requires two dimensions)r6   ÚsuperÚdiagonalr7   )r:   rÀ   ©Ú	__class__r   r#   rê   ‘  s   
z_dok_base.diagonalc                 C   sh   | j dkr	|  ¡ S |d ur|dkrtdƒ‚| j\}}| j||f| j|d�}|j dd„ |  ¡ D ƒ¡ |S )Nr   )r   r   zvSparse arrays/matrices do not support an 'axes' parameter because swapping dimensions is the only logical permutation.)r'   r   c                 s   s$   � | ]\\}}}||f|fV  qd S rL   r   ©r    ÚleftÚrightr@   r   r   r#   rH   £  ro   z&_dok_base.transpose.<locals>.<genexpr>)	r6   r   r7   r&   r†   r'   r-   rA   rj   )r:   Úaxesr   rn   ÚNrÂ   r   r   r#   Ú	transpose–  s   
ÿ
z_dok_base.transposec                 C   sj   d}t |tdd� | jdkr|  ¡ }|j ¡ |_|S | j\}}| j||f| jd�}dd„ |  	¡ D ƒ|_
|S )zÃDEPRECATED: Return the conjugate transpose.

        .. deprecated:: 1.14.0

            `conjtransp` is deprecated and will be removed in v1.16.0.
            Use ``.T.conj()`` instead.
        zS`conjtransp` is deprecated and will be removed in v1.16.0. Use `.T.conj()` instead.r   )Ú
stacklevelr   r�   c                 S   s$   i | ]\\}}}||ft  |¡“qS r   )r2   Úconjrí   r   r   r#   r$   »  s   $ z(_dok_base.conjtransp.<locals>.<dictcomp>)r   ÚDeprecationWarningr6   rÃ   rÅ   Ú	conjugater&   r†   r'   rj   r-   )r:   ÚmsgrÂ   rn   rñ   r   r   r#   Ú
conjtransp¨  s   

z_dok_base.conjtranspc                 C   s$   | j | j| jd�}|j | j¡ |S ©Nr�   )r†   r&   r'   r-   rA   rÑ   r   r   r#   r   ¾  s   z_dok_base.copyr   c                C   s^   t  ||¡}ttt|ƒƒtƒrtdd„ t|Ž D ƒƒ}nt|ƒd f}| |t|ƒd�}||_	|S )Nc                 s   s   � | ]	}t |ƒd  V  qdS )r   N)Úmax)r    rw   r   r   r#   rH   É  s   € z%_dok_base.fromkeys.<locals>.<genexpr>r   r�   )
rç   Úfromkeysr)   ÚnextÚiterr*   rr   rú   r`   r-   )ÚclsÚiterableÚvalueÚtmpr&   rÚ   r   r   r#   rû   Å  s   z_dok_base.fromkeysc                    s¢   | j ‰ˆdkr| j| j| jd�S | jt| jƒd�‰ tj|  ¡ | jˆd�}| j	dkr/t
|  ¡ Ž n|  ¡ f}t‡ ‡fdd„|D ƒƒ}| j||f| j| jd�}d	|_|S )
Nr   r�   )Úmaxval©r'   Úcountr   c                 3   s    � | ]}t j|ˆ ˆd �V  qdS )r  N)r2   Úfromiter)r    Úix©Ú	idx_dtypeÚnnzr   r#   rH   Ù  rÕ   z"_dok_base.tocoo.<locals>.<genexpr>r%   T)r	  r9   r&   r'   Ú_get_index_dtyperú   r2   r  rJ   r6   rr   rk   r*   Úhas_canonical_format)r:   r   rÅ   ÚindsrÄ   ÚAr   r  r#   rÃ   Ð  s    z_dok_base.tocooc                 C   s   |r|   ¡ S | S rL   r   ©r:   r   r   r   r#   r0   à  s   z_dok_base.todokc                 C   s&   | j dkr	tdƒ‚| jdd�j|d�S )Nr   z%tocsr() not valid for 1d sparse arrayFr   )r6   r?   rÃ   Útocscr  r   r   r#   r  ç  s   
z_dok_base.tocscc                 G   s¾   t || jd�}t|ƒt| jƒkrt‚| jdkr0|d }t| jƒD ]
}||kr*| j|= q || _d S |\}}| j\}}||k sA||k rZt|  	¡ ƒD ]\}}||ksS||krY| j||f= qG|| _d S )Nr   r   éÿÿÿÿ)
r   r+   rB   r&   r?   r6   r}   r-   r,   rk   )r:   r&   ÚnewNr!   ÚnewMrn   rñ   r£   r   r   r#   Úresizeî  s&   
€
€
z_dok_base.resizeÚunsafeTc                 C   sb   t  |¡}| j|kr)| j| j|d�}t jt| j ¡ ƒ|d�}tt	| j|ƒƒ|_|S |r/|  
¡ S | S rù   )r2   r'   r†   r&   r…   r}   r-   rJ   rç   rr   r   )r:   r'   Úcastingr   rÚ   rÅ   r   r   r#   r1     s   

z_dok_base.astype)NNFrL   )rl   r   )NF)r   )F)r  T)Ara   Ú
__module__Ú__qualname__Ú_formatr+   r(   rA   rE   rK   r   Ú__doc__rN   rS   rT   rU   rX   rY   r[   re   rg   rh   ri   rj   rk   rJ   rt   rx   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ò   rø   r   Úclassmethodrû   rÃ   r0   r  r  r1   Ú__classcell__r   r   rë   r#   r      sˆ    '





	










r   c                 C   s
   t | tƒS )aÑ  Is `x` of dok_array 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_array, dok_matrix, coo_matrix, isspmatrix_dok
    >>> isspmatrix_dok(dok_matrix([[5]]))
    True
    >>> isspmatrix_dok(dok_array([[5]]))
    False
    >>> isspmatrix_dok(coo_matrix([[5]]))
    False
    )r)   r   )rG   r   r   r#   r     s   
r   c                   @   s   e Zd ZdZdS )r   a!  
    Dictionary Of Keys based sparse array.

    This is an efficient structure for constructing sparse
    arrays incrementally.

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

        dok_array(S)
            with another sparse array or matrix S (equivalent to S.todok())

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

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

    Notes
    -----

    Sparse arrays 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_array once constructed.

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

    N)ra   r  r  r  r   r   r   r#   r   /  s    r   c                   @   sL   e Zd ZdZdd„ Zdd„ Zeeed�Zdd„ Zd	d
„ Z	dd„ Z
dd„ ZdS )r   a/  
    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)
            where D is a 2-D ndarray

        dok_matrix(S)
            with another sparse array or matrix S (equivalent to S.todok())

        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
    size
    T

    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

    c                 C   s"   | j |dd� | j¡}|j| _d S )NFr   )r¦   Úasformatr/   Ú__dict__)r:   r&   Ú
new_matrixr   r   r#   Ú	set_shape˜  s   zdok_matrix.set_shapec                 C   s   | j S )zGet shape of a sparse matrix.)r,   rM   r   r   r#   Ú	get_shapeœ  s   zdok_matrix.get_shape)ÚfgetÚfsetc                 C   rW   rL   )r-   r[   rM   r   r   r#   r[   ¢  rO   zdok_matrix.__reversed__c                 C   ó    t |tƒr| j|jB S | j|B S rL   ©r)   r   r-   rÍ   r   r   r#   re   ¥  ó   

zdok_matrix.__or__c                 C   r#  rL   r$  rÍ   r   r   r#   rg   ª  r%  zdok_matrix.__ror__c                 C   s0   t |tƒr|  j|jO  _| S |  j|O  _| S rL   r$  rÍ   r   r   r#   rh   ¯  s
   
ÿzdok_matrix.__ior__N)ra   r  r  r  r  r   Úpropertyr&   r[   re   rg   rh   r   r   r   r#   r   d  s    3r   )r  Ú__docformat__Ú__all__r²   Úwarningsr   Únumpyr2   Ú_matrixr   Ú_baser   r	   r
   Ú_indexr   Ú_sputilsr   r   r   r   r   r   r   r   rç   r   r   r   r   r   r   r   r#   Ú<module>   s$    (    5