U
    }h                     @   s   d dl Zd dlZd dlmZ d dlmZmZ dd Zej	
dddgd	d
 Zdd Zej	
dddgej	
dejejgdd ZdS )    N)mutual_reachability_graph)_convert_containerassert_allclosec               	   C   sb   t jd} | dd}|j| }t |d t|d}d}tjt	|d t
| W 5 Q R X dS )z=Check that we raise an error if the sparse format is not CSR.r   
           Z
sparse_cscz&Only sparse CSR matrices are supported)matchN)nprandomRandomStaterandnTfill_diagonalr   pytestZraises
ValueErrorr   )rngXerr_msg r   T/tmp/pip-unpacked-wheel-ig1s1lm8/sklearn/cluster/_hdbscan/tests/test_reachibility.py2test_mutual_reachability_graph_error_sparse_format   s    

r   
array_typearray
sparse_csrc                 C   sX   t jd}|dd}|j| }t |d t|| }t|}t|t|ksTt	dS )z.Check that the operation is happening inplace.r   r   r   N)
r   r	   r
   r   r   r   r   r   idAssertionError)r   r   r   mr_graphr   r   r   &test_mutual_reachability_graph_inplace   s    

r   c                  C   sV   t jd} | dd}|j| }t|d}t|dd}t|dd}t||  dS )zGCheck that we get the same results for dense and sparse implementation.r      r      )Zmin_samplesN)	r   r	   r
   r   r   r   r   r   Ztoarray)r   r   ZX_denseZX_sparseZmr_graph_denseZmr_graph_sparser   r   r   7test_mutual_reachability_graph_equivalence_dense_sparse&   s    

r   dtypec                 C   sf   t jd}|dd}|j| |}t |d t|| }|j|ksLt	t
|}|j|ksbt	dS )z@Check that the computation preserve dtype thanks to fused types.r   r   r   N)r   r	   r
   r   r   Zastyper   r   r    r   r   )r   r    r   r   r   r   r   r   -test_mutual_reachability_graph_preserve_dtype3   s    
r!   )Znumpyr   r   Z&sklearn.cluster._hdbscan._reachabilityr   Zsklearn.utils._testingr   r   r   markZparametrizer   r   Zfloat32Zfloat64r!   r   r   r   r   <module>   s   
