a
    
d                     @   s  d dl mZ d dl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 d dlmZ d dlmZ d d	lmZ d
d Zejdejejejejgejddddgfdddgfddg dfddg dfdddgfgdd Zejdejejejejgejdg ddd Zdd Zejddddddg d gd!d" Zejd#dd$d$d%d%gd&d&ggd%d'gd&d(ggd'd'gd(d(gggfdd$d$d%d%gd'd'ggd%d&gd'd(ggd&d&gd(d(gggfdd)d)d%d%gd&d&gd*d*ggd%d'gd&d(gd*d+ggd%d,gd&d-gd*d.ggd'd'gd(d(gd+d+ggd'd,gd(d-gd+d.ggd,d,gd-d-gd.d.gggfdd)d)d%d%gd'd'gd,d,ggd%d&gd'd(gd,d-ggd%d*gd'd+gd,d.ggd&d&gd(d(gd-d-ggd&d*gd(d+gd-d.ggd*d*gd+d+gd.d.gggfdd$d$d%d%gd&d&gd(d(gd'd'gggfgd/d0 Zejd1d2d3gd4d5 ZdS )6    )shuffleN)assert_allclose)assert_array_equal)expected_warnings)integral_image)haar_like_featurehaar_like_feature_coord)draw_haar_like_featurec               
   C   s   t jdt jd} t| }d}ttF t|dddd|d tdd|d t	| dddd|d W d    n1 sr0    Y  tddd\}}tt. t|dddd|d d |d	 W d    n1 s0    Y  d S )
N   r   dtypeZunknown_typer   r   feature_typetype-2-x   r   Zfeature_coord)
nponesfloat32r   pytestZraises
ValueErrorr   r	   r
   )imgimg_iir   
feat_coord	feat_type r   h/var/www/html/stable-diffusion-webui/venv/lib/python3.9/site-packages/skimage/feature/tests/test_haar.pytest_haar_like_feature_error   s    2r   r   z1feature_type,shape_feature,expected_feature_valuer   )T   g        type-2-ytype-3-x)*   )g      g      g       g      type-3-ytype-4)$   c                 C   sD   t jd|d}t|}t|dddd| d}tt t || d S )Nr   r   r   r   r   )r   r   r   r   r   sortunique)r   Zshape_featureZexpected_feature_valuer   r   r   haar_featurer   r   r   test_haar_like_feature    s    r+   r   r   r!   r"   r%   r&   c                 C   s`   t jd| d}t|}|j}d|jv r:t |jdd}t|dddd|d}|j|ks\J d S )	Nr   r   Zuintu r   r   r   )r   r   r   r   namereplacer   )r   r   r   r   Zexpected_dtyper*   r   r   r   !test_haar_like_feature_fused_type2   s    
r1   c                  C   sR   t jdt jd} t| }g d}t|dddd|d}t|dddd}t|| d S )Nr   r   r,   r   r   r   )r   r   int8r   r   r   )r   r   r   Z	haar_listZhaar_allr   r   r   test_haar_like_feature_listD   s    r3   )r!   r"   r&   c              	   C   s   t jdt jd}t|}t| trVt|  tdd | D  \}}t |}t |}nt	dd| \}}t
|dddd||d}t
|dddd| }t|| d S )Nr   r   c                 S   s   g | ]}t d d |qS )r   r   ).0Zfeat_tr   r   r   
<listcomp>Z   s   z6test_haar_like_feature_precomputed.<locals>.<listcomp>r   r   r   )r   r   r2   r   
isinstancelistr   zipZconcatenater	   r   r   )r   r   r   r   r   Zhaar_feature_precomputedr*   r   r   r   "test_haar_like_feature_precomputedN   s     

r9   z(feature_type,height,width,expected_coord   )r   r   )r      )r;   r   )r;   r;   r   )r   r:   )r;   r:   )r:   r   )r:   r;   )r:   r:   c                 C   sD   t ||| \}}tdd |D }t|| t|| ks@J d S )Nc                 S   s   g | ]}|qS r   r   )r4   Zhfr   r   r   r5          z0test_haar_like_feature_coord.<locals>.<listcomp>)r	   r   arrayr   all)r   heightwidthZexpected_coordr   r   r   r   r   test_haar_like_feature_coordg   s    '
rA   zmax_n_features,nnz_values)N.   )r;      c                 C   s   t jdt jd}tddd\}}t|dddd|| dd}tdg( t|dddd|| dd W d    n1 sp0    Y  |jd	ksJ t ||ksJ d S )
Nr   r   r   r&   r   )max_n_featuresrngz'`random_state` is a deprecated argument)rD   Zrandom_state)r   r   r   )r   zerosr   r	   r
   r   shapeZcount_nonzero)rD   Z
nnz_valuesr   Zcoord_imager   r   r   test_draw_haar_like_feature   s    $rJ   )randomr   r   numpyr   Znumpy.testingr   r   Zskimage._shared._warningsr   Zskimage.transformr   Zskimage.featurer   r	   r
   r   markZparametrizeZuint8r2   r   float64r+   r1   r3   r9   rA   rJ   r   r   r   r   <module>   s   





&
	
