a
    Re                     @   sN   d Z ddlZddlmZ ddlmZ ddlm	Z
 ddlmZ G dd dZdS )	z'unit tests for sparse utility functions    N)assert_equal)raises)_sputils)matrixc                   @   st   e Z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 Zdd ZdS )TestSparseUtilsc                 C   sT   t tdtj t tddtj t tdtttj t tddtj d S )Nintcint32float32boolid)	r   sputilsZupcastnpr   float64complexfloatZ
complex128self r   S/var/www/sunrise/env/lib/python3.9/site-packages/scipy/sparse/tests/test_sputils.pytest_upcast   s    zTestSparseUtils.test_upcastc                 C   st   t jdgdd}ttjd tdt ttjd |dt j ttdd td W d    n1 sf0    Y  d S )	N   int8dtype)default)az0object dtype is not supported by sparse matricesmatchO)	r   arrayr   r   Zgetdtyper   r   assert_raises
ValueError)r   Ar   r   r   test_getdtype   s    zTestSparseUtils.test_getdtypec                 C   s   t tdd t tdd t tdd t tdd t ttdd t tdd t ttdgd t tdggd t td	d t td
d d S )N      @T      @      ?      @   Z16Fr   r      )r   r   Zisscalarliker   r    r   r   r   r   test_isscalarlike   s    z!TestSparseUtils.test_isscalarlikec                 C   s   t tdd t ttdd t ttdgd ttdd td W d    n1 sj0    Y  t tdd t td	d t td
d t tdd d S )Nr&   Tr)   Fz4Inexact indices into sparse matrices are not allowedr   r%   r'   r(   r*   r+   )r   r   Z	isintliker   r    r!   r"   r   r   r   r   test_isintlike+   s    (zTestSparseUtils.test_isintlikec                 C   s*  t tdd t tdd t tdd t tdd t tdgdfd t tjddd	d t tjd
dd	d t tjddd	d t tjd
dd	d t tjdddd t tjdgdfddd t tjddddd t tjdddd t tjdddd t tjdddd d S )Nr+   T)   r,   )      ?r,   F)r,   r,   r,   r,   )r,   )nonneg)r,   r1   )
allow_ndim)r,   r,   )r2   r3   )r,   )r,   r,   )r   r   Zisshaper   r   r   r   test_isshape:   s"    zTestSparseUtils.test_isshapec                 C   s   t tdd t tdd t tdgd t tg dd t ttg dd t ttdgdgdggd t tdd d S )Nr*   Tr   r,   r)   r   r,   r)   F)r   r   Z
issequencer   r    r   r   r   r   test_issequenceN   s    "zTestSparseUtils.test_issequencec                 C   s   t tdd t tdgdggd t ttdd  d t tddgd t ttdd t tdgggd t tdd d S )N)r   Tr   r,   r)   F)r   r   Zismatrixr   Zaranger   r   r   r   test_ismatrixX   s    zTestSparseUtils.test_ismatrixc                 C   s2   t ttdgd t ttdgd d S )Nr   T)r   r   Zisdenser   r    r   r   r   r   r   test_isdenseb   s    zTestSparseUtils.test_isdensec                 C   sB   t ttjd t ttjd t ttjd dD ]}t| q.d S )N)r   r   r0   r)   )r4   r1   r   r   N)r!   	TypeErrorr   Zvalidateaxisr"   )r   Zaxisr   r   r   test_validateaxisf   s
    z!TestSparseUtils.test_validateaxisc                 C   sb  t t t jj}|d }t jddd}t jddd}tt tj	||fddt d ||d< tt tj	||fddt d ||d< tt tj	||fddt d	 t jd
dd}t jd
dd}tt t	||ft d	 t jddd}t jddd}tt tj	||f|ddt d	 ||d< tt tj	||f|dt d	 d S )Nr   Z   Zuint32r   T)check_contentsr   r1   int64Y      )maxvalr=   )rA   )
r   r>   Ziinfor   maxZonesr   r   r   Zget_index_dtype)r   ZimaxZtoo_bigZa1Za2r   r   r   test_get_index_dtypeo   sJ    
	z$TestSparseUtils.test_get_index_dtypec                 C   s   t dgd}t|d d S )N)
   r1   )i  i )rD   i23)r   Zcheck_shaper   )r   Z	new_shaper   r   r   test_check_shape_overflow   s    z)TestSparseUtils.test_check_shape_overflowc                 C   s   g dg}t |}tt|t js*J tt|t js@J t|}d|d d d d f< t|| tj|dd}d|d d d d f< t|g dg d S )Nr6   {   F)copyrF   rF   rF   )r   r    
isinstancer   r   r   r   r   bcr   r   r   test_matrix   s    



zTestSparseUtils.test_matrixc                 C   sr   g dg}t |}tt|t js*J tt|t js@J t|}d|d d d d f< t|g dg d S )Nr6   rF   rH   )r   r    rI   r   Zasmatrixr   r   rJ   r   r   r   test_asmatrix   s    


zTestSparseUtils.test_asmatrixN)__name__
__module____qualname__r   r$   r-   r.   r5   r7   r8   r9   r;   rC   rE   rM   rN   r   r   r   r   r   
   s   

	9r   )__doc__numpyr   Znumpy.testingr   Zpytestr   r!   Zscipy.sparser   r   Zscipy.sparse._sputilsr   r   r   r   r   r   <module>   s   