o
    0ZcKp                     @   st   d Z ddlZddlmZmZmZmZ ddlm	Z	m
Z
mZmZmZmZmZmZ ddlZG dd dZG dd dZdS )	z-Test functions for 1D array set operations.

    N)assert_array_equalassert_equalassert_raisesassert_raises_regex)ediff1dintersect1dsetxor1dunion1d	setdiff1duniquein1disinc                   @   s  e Zd Zdd Zdd Zdd Zdd Zd	d
 Zej	
dejg dejddejdfejg dejdejg dejdddfejg dejdejejdfgdd Zej	
dejg dejdddejg dejdfejg dejdejdgejddejg dejdfejg dejdddejg dejdfejg dejdddejg dejdfgd d! Zd"d# Zd$d% Zd&d' Zd(d) Zd*d+ Zd,d- Zd.d/ Zd0d1 Zd2d3 Zd4d5 Zd6d7 Z d8d9 Z!d:d; Z"d<d= Z#d>d? Z$dS )@
TestSetOpsc                 C   s   t g d}t g d}t g d}t||dd}t|| t g d}t g d}t g d}t||}t|| tg tg g  d S )N            r         r   r   )r   r   r   Tassume_unique)r   r   r   r   r   )r   r   r   r   r   r   r   )nparrayr   r   )selfabecced r!   V/var/www/chikooza/env/lib/python3.10/site-packages/numpy/lib/tests/test_arraysetops.pytest_intersect1d   s   


zTestSetOps.test_intersect1dc                 C   sL   G dd d}| }t ||}t|| t g dg d}t|g d d S )Nc                   @   s   e Zd Zdd ZdS )z4TestSetOps.test_intersect1d_array_like.<locals>.Testc                 S   s
   t dS )Nr   )r   aranger   r!   r!   r"   	__array__%   s   
z>TestSetOps.test_intersect1d_array_like.<locals>.Test.__array__N)__name__
__module____qualname__r&   r!   r!   r!   r"   Test$   s    r*   r   r   r   )r   r   )r   r*   r   resr!   r!   r"   test_intersect1d_array_like"   s   

z&TestSetOps.test_intersect1d_array_likec                 C   s  t g d}t g d}t||ddd\}}}t g d}t|| t|| | t|| | t g d}t g d}t||dd\}}}t g d}t|| t|| | t|| | t g d	g d
g}t g dg dg}t||ddd\}}}t ||j}t ||j}	t g d}
t|
||  t|
||	  t g dg dg}t g dg dg}t||dd\}}}t ||j}t ||j}	t g d}
t|
||  t|
||	  d S )Nr   r   r   r   )r   r   r      T)r   return_indices)r   r   r   )r   r   r   r   r   r   r   )r      r   r   r   r   r   r   )r0   )r   r   r   r/   )r   r1   r      )r   r   r   r/   )
      r1   	   )r   r/   r   r1   )r   r   r   r/   r/   )r   r   r1   r   r   )r   r   r   r   )r3   r4   r1   r   )r   r   r1   )r   r   r   r   unravel_indexshape)r   r   r   r   i1i2eeefui1ui2ear!   r!   r"   test_intersect1d_indices.   s<   

z#TestSetOps.test_intersect1d_indicesc                 C   s   t g d}t g d}t g d}t||}t|| t g d}t g d}t g d}t||}t|| t g d}t g d}t g d}t||}t|| tg tg g  d S )	Nr   r   )r   r   r   r+   )r/   r   r   )r   r   r   r   r   r/   )r   r1   r   r   )r/   r   r   r1   )r   r   r   r   r   r   r   r   r   r!   r!   r"   test_setxor1dU   s    





zTestSetOps.test_setxor1dc                 C   s,  t g }t dg}t ddg}tg t| tdgt|dd tdgt|dd tddgt|ddd tg t| tdgt| tg dt|d	d
d tg dt|ddgd	dgd tdd
gt|d
d tg dt|d	dgd td	dgt|d	d tg dt|ddgd d S )Nr   r   r   )to_begin)to_end)rB   rC   )r   r   r5   r   r5   )r   r/   r   r   r1   r   r/   r1   )r   r   r1   )r   r/   r   )r   r   r   r   )r   	zero_elemone_elemtwo_elemr!   r!   r"   test_ediff1dm   s"   
zTestSetOps.test_ediff1dzary, prepend, append, expectedr+   dtypeNrC   )r   r   r   rB   )      ?g      @g      "@c                 C   sH   d |}tt| t|||d W d    d S 1 sw   Y  d S )Nz dtype of `{}` must be compatiblearyrC   rB   )formatr   	TypeErrorr   )r   rM   prependappendexpectedmsgr!   r!   r"   !test_ediff1d_forbidden_type_casts   s   
"z,TestSetOps.test_ediff1d_forbidden_type_castszary,prepend,append,expectedi   i  )r   r   r   r   r   )r   r   r   r   )r   r   r   r   r   )r   r   r   rU   c                 C   s.   t j|||d}t|| |j|jksJ d S )NrL   )r   r   r   rJ   )r   rM   rP   rQ   rR   actualr!   r!   r"   test_ediff1d_scalar_handling   s   
z'TestSetOps.test_ediff1d_scalar_handlingc           	         s   dd }t j|tgdhd  fdd}t dg d}t g d	g d
g dg}||| ddg}d}||| t d}||| ||| ||| |d| ||d |dd g }||| ||| ||| d S )Nc                 S   s   t |  }| |v S N)r   asarrayflattentolist)r   r   r!   r!   r"   
_isin_slow   s   z(TestSetOps.test_isin.<locals>._isin_slowr   )otypesexcludedc                    s"   t | |} | |}t|| d S rX   )r   r   )r   r   xy	isin_slowr!   r"   assert_isin_equal   s   

z/TestSetOps.test_isin.<locals>.assert_isin_equal   r   r   r   )r3         )r   r   r   )      !   )r5   r1   )r   r/   )r5   r   r   r   r/   )r   	vectorizeboolr$   reshaper   )	r   r\   rc   r   r   r   dfr_   r!   ra   r"   	test_isin   s(   










zTestSetOps.test_isinc                 C   s  dD ]}g d}g d| }t g d}t||dd}t|| d|d< t g d	}t||dd}t|| d
\|d< |d< t g d}t||dd}t|| t g d}g d| }g d}t||}t|| |g d|  }g d}t||}t|| t g d}t g d| }t g d}t||}t|| t g d}t g d| }t g d}t||}t|| t ddg}t ddg| }t ddg}t||}t|| qt dg}t dg}t dg}t||}t|| ttg g g  d S )Nr   r3   r   r   )TFTTTr   r1   r   )FFTT)r   r1   r   )TFTFr   r   r   r   r   r   r   r   r   r   r   r   r   r   re   )FTFTTTTTTFTFFF)r   r   r   )TTTTTTTTTTTFTT)r   r   r   r   r   )r   r   r   r   r   r   )TFTTTr   r   Fr   r   r   r   )r   multr   r   r   r   r!   r!   r"   	test_in1d   sX   













zTestSetOps.test_in1dc                 C   sB   t g d}t ddg}t g d}t||}t|| d S )N)r   r   r   rn   er   rv   r   r   r   )TFTFFTFFrs   r@   r!   r!   r"   test_in1d_char_array+  s
   
zTestSetOps.test_in1d_char_arrayc                 C   sH   dD ]}t g d}g d| }tt t||t||dd qdS )zTest in1d's invert parameterrq   rr   re   TinvertN)r   r   r   ry   r   )r   rt   r   r   r!   r!   r"   test_in1d_invert4  s
   "zTestSetOps.test_in1d_invertc                 C   s   t ddd}t dddd}t dddd}t g d}tt||dd	| tt||d
d	| tt||dd	| tt||d
d	| d S )Nr/   r   r   r5   ?   rg   )FFFTTTTr   F)r   r$   rm   r   r   r   )r   r   r   long_br   r!   r!   r"   test_in1d_ravel=  s   zTestSetOps.test_in1d_ravelc                 C   s<   d g}t dgd }t dg}t ||}t|| d S Nr   r3   Frs   r   ar1ar2rR   resultr!   r!   r"   test_in1d_first_array_is_objectJ  
   z*TestSetOps.test_in1d_first_array_is_objectc                 C   s:   d}t d gd }t dg}t ||}t|| d S r~   rs   r   r!   r!   r"    test_in1d_second_array_is_objectQ  s
   z+TestSetOps.test_in1d_second_array_is_objectc                 C   s<   d g}t d gd }t dg}t ||}t|| d S )Nr3   Trs   r   r!   r!   r"    test_in1d_both_arrays_are_objectX  r   z+TestSetOps.test_in1d_both_arrays_are_objectc                 C   s`   t dtfdtfg}t jdg|d}t jdgd |d}t dg}t ||}t|| d S )Nfield1field2)r   NrI   r3   T)r   rJ   intobjectr   r   r   )r   dtr   r   rR   r   r!   r!   r"   +test_in1d_both_arrays_have_structured_dtype_  s   z6TestSetOps.test_in1d_both_arrays_have_structured_dtypec                 C   s`  t jddgtd}t jddgtd}t ddg}t ||}t|| t j||dd}t|t | t jg dtd}|d d }t jg dtd}|d d }t ddg}t ||}t|| t j||dd}t|t | t jg dtd}|d d }t jddgtd}t dd	g}t ||}t|| t j||dd}t|t | d S )
Nr   r   rI   Trx   )r   )r   r   r   rD   )r   r   r   r   F)r   r   r   r   r   ry   r   r!   r!   r"   'test_in1d_with_arrays_containing_tuplesi  s0   


z2TestSetOps.test_in1d_with_arrays_containing_tuplesc           	      C   s   t g d}t g d}t g d}t||}t|| t g dg dg}t g d}t g d}t||}t|| tg tg g  d S )N)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   r   r   r   r   r   )r   r   r	   r   )	r   r   r   r   r   r_   r`   ezzr!   r!   r"   test_union1d  s   



zTestSetOps.test_union1dc                 C   s   t g d}t g d}t ddg}t||}t|| t d}t d}t ddg}t||}t|| tg tg g  t dt j}tt|g jt j d S )	N)r/   r   r   r   r   r   r   r   r   r/   r         rf   r!   )r   r   r
   r   r$   uint32r   rJ   r@   r!   r!   r"   test_setdiff1d  s   





zTestSetOps.test_setdiff1dc                 C   sF   t g d}t g d}t ddg}t||dd}t|| d S )N)r   r   r   )r   r   r   r   r   Tr   )r   r   r
   r   )r   r   r   rR   rV   r!   r!   r"   test_setdiff1d_unique  s
   z TestSetOps.test_setdiff1d_uniquec                 C   s8   t g d}t g d}tt||t dg d S )N)r   r   r   )r   r   sr   )r   r   r   r
   )r   r   r   r!   r!   r"   test_setdiff1d_char_array  s   z$TestSetOps.test_setdiff1d_char_arrayc                 C   sR   t g d}t g d}t||}t||}t||}t||}t|| d S )N)r   r   r   r   r1   )r5   r1   r   r   r   r   r   )r   r   r   r   r	   r
   r   )r   r   r   c1aux1aux2c2r!   r!   r"   test_manyways  s   



zTestSetOps.test_manyways)%r'   r(   r)   r#   r-   r?   rA   rH   pytestmarkparametrizer   r   int64nanfloat32int8rT   int16float64int32rW   rp   ru   rw   rz   r}   r   r   r   r   r   r   r   r   r   r   r!   r!   r!   r"   r      s    '

)<		
!r   c                   @   sn   e Zd Zdd Zdd Zdd Zdd Zej	d	d
dgdd Z
dd Zdd Zdd Zdd Zdd ZdS )
TestUniquec                 C   sd  dd }g dd }g d}g d}g dd }t g dd}g }|t jd	  |t jd
  |d |d |D ]}t ||}	t ||}
||	|
|||| q>d}t t||}	||	d d < t t||}
||
d d < ||	|
|||| ddg}t tt	|||}	t tt	|||}
||	|
|||| g d}	t
t |	ddg g d}g d}g d}t|}t
|| t|dd\}}t
|| t
|| t d}d|d< t j|dd\}}t
|t d g }t j|ddd }t j|ddd }t j|ddddd  \}}t|jt j t|jt j t|jt j t|jt j dt jdt jg}ddt jg}g d}g d }g d!}tt || tt j|dd||f tt j|dd||f tt j|dd"||f d#t jd$td%t jtdt jg}d$d#td%t jg}g d&}g d'}g d(}tt || tt j|dd||f tt j|dd||f tt j|dd"||f t d)}t d*|t d+|g}t d+t d*|g}g d}g d }g d!}tt || tt j|dd||f tt j|dd||f tt j|dd"||f t d)}t dd,|t dd-|g}t dd-t dd,|g}g d}g d }g d!}tt || tt j|dd||f tt j|dd||f tt j|dd"||f t jgd. }t jg}d/g}g d0}d.g}tt || tt j|dd||f tt j|dd||f tt j|dd"||f d S )1Nc                 S   s  d}| d|}t| }t||| | d|}t| ddd\}}	t||| t|	|| | d|}t| ddd\}}	t||| t|	|| | d|}t| ddd\}}	t||| t|	|| | d|}t| ddd\}}
}t||| t|
|| t||| | d	|}t| ddd\}}
}t||| t|
|| t||| | d
|}t| ddd\}}
}t||| t|
|| t||| | d|}t| ddd\}}
}}t||| t|
|| t||| t||| d S )Nzcheck {0} failed for type {1}valuesreturn_indexTFreturn_inversereturn_countszreturn_index and return_inversezreturn_index and return_countsz return_inverse and return_countsz.return_index, return_inverse and return_counts)rN   r   r   )r   r   r8   r9   r   r   base_msgrS   vjj1j2j3r!   r!   r"   	check_all  sN   z,TestUnique.test_unique_1d.<locals>.check_all)r   r   r   r   r   r   r   r3   )r   r   r   r   )r   r   r   r   )r   r   r   r   r   r   r   )r   r   r   r   
AllIntegerAllFloatdatetime64[D]timedelta64[D]O) i)      ?              ?      r   r   r   )r   r   r   r   r+   )r   r   r   r   r   r   T)r   r   r   .)r   r   )r   r   g       @rK   )r   r   r   )r   r   r   r   )r   r   r   )r   y       @      y      ?      ?        )r   r   r   )r   r   r   r   r   )r   r   r   natz
2020-12-26z
2020-12-24Dhr   r   )r   r   r   r   )r   multiplyextend	typecodesrQ   r   emptylenlistzipr   r   	chararrayzerosr   rJ   intpr   complex
datetime64timedelta64)r   r   r   r   r8   r9   r   typesr   aabbunqinva1a2a2_inva1_idxa3_idxa3_invuaua_idxua_invua_cntr   all_nansr!   r!   r"   test_unique_1d  s   0





 

zTestUnique.test_unique_1dc                 C   s\   t t| jt t t| jdtfdtfg t tjttddd t tjttddd d S )Nr   r   r3   r   axis)	r   rO   _run_axis_testsr   r   r   	AxisErrorr   r$   r%   r!   r!   r"   test_unique_axis_errorsp  s   z"TestUnique.test_unique_axis_errorsc                 C   sZ   d}g dg dg}t |}tt|ddt|dd| tt|ddt|dd| d S )NzUnique failed on list of listsr   r   r   r   r   r   )r   rY   r   r   )r   rS   inpinp_arrr!   r!   r"   test_unique_axis_listx  s
   
 z TestUnique.test_unique_axis_listc                 C   s  g }| tjd  | tjd  |d |d |dtfdtfg |dtfdtfg |D ]}| | q4d}tjdtjd		d
d
t}tjddgddggtd	}tt|dd|| d}tddgddgddgddgg}tddgg}tt|dd|| d S )Nr   r   r   r   r   r   z&Non-bitwise-equal booleans test failedr3   rI   rD   r   FTr   r   z"Negative zero equality test failedg       r   )r   r   r   rQ   r   floatr   r$   uint8rm   viewrl   r   r   r   )r   r   rJ   rS   datar   r!   r!   r"   test_unique_axis  s"   

"zTestUnique.test_unique_axisr   r   rD   c                 C   s,   t g d}t||d}t|g d d S )N)r   r   r   r   r   r   r   r   r   r.   r   r   r   r   )r   r   r_   uniqr!   r!   r"   test_unique_1d_with_axis  s   z#TestUnique.test_unique_1d_with_axisc           
      C   sR  t jdt jd}t|ddddd\}}}}t|j|j t|t jdd t|t dg t|t ddg t|t dg t|d	dddd\}}}}t|j|j t|t jdd t|t g  t|t g  t|t g  d
}t j|d}tt	|D ]"}t
|}	|| dkrd|	|< nd	|	|< tt||dt j|	d qd S )N)r   r   )r7   rJ   r   Tr   r   r   r   )r   r   )r7   r   r   )r   r   r   r   r   r   r   r   )r   r   r   r   r   rJ   r   r   ranger   r   )
r   single_zeror   idxr   cntr7   multiple_zerosr   expected_shaper!   r!   r"   test_unique_axis_zeros  s8   

z!TestUnique.test_unique_axis_zerosc                 C   sh   t jg ddd}t j|d}t |}t j|ddd\}}}d}t|j|j| t|j|j| d S )N)@   r   r   r   r   r{   r{   r   r   r   r   r   r   r{   r   r   rI   r   T)r   r   z6Unique returned different results when asked for index)r   r   mamasked_equalr   r   r   mask)r   r_   r`   r   v2r   r   rS   r!   r!   r"   test_unique_masked  s   

zTestUnique.test_unique_maskedc                 C   sD   d}dD ]}t dgdgg|}t j|dd}t||||  qd S )Nz*sort order incorrect for integer type '%s'bhilqrD   r   r   r   )r   fmtr   r   r   r!   r!   r"    test_unique_sort_order_with_axis  s   z+TestUnique.test_unique_sort_order_with_axisc           
      C   s  t g dg dg dg dg|}d}t ddg}tt|||| d}t g dg dg}tt|dd||| d}t g d	g d
g d	g d
g}tt|dd||| d}t ddgddggddgddggg|}t j|ddgdd}tt|dd|| t|ddddd\}}}}	d}t|| || d}t|| | d}t|	t ddg| t|ddddd\}}}}	d}t|d d |f | d}t|d d |f | d}t|	t g d| d S )N)r   r   r   r   )r   r   r   r   z&Unique with 1d array and axis=0 failedr   r   z&Unique with 2d array and axis=0 failedr   z&Unique with 2d array and axis=1 failed)r   r   r   r   z&Unique with 3d array and axis=2 failedr   Tr   z-Unique's return_index=True failed with axis=0z/Unique's return_inverse=True failed with axis=0z.Unique's return_counts=True failed with axis=0z-Unique's return_index=True failed with axis=1z/Unique's return_inverse=True failed with axis=1z.Unique's return_counts=True failed with axis=1)r   r   r   )r   r   astyper   r   take)
r   rJ   r   rS   r   data3dr   r   r   r   r!   r!   r"   r     s\   
"
zTestUnique._run_axis_testsc                 C   sj   t ddt jt jt jg}t |}t j|dd}t|t dt jg t|t dt jt jt jg d S )Nr   F)	equal_nan)r   r   r   r   r   )r   r   r   not_unqr!   r!   r"   test_unique_nanequals  s
   
"z TestUnique.test_unique_nanequalsN)r'   r(   r)   r   r   r   r   r   r   r   r   r   r  r  r   r
  r!   r!   r!   r"   r     s     *
$	,r   )__doc__numpyr   numpy.testingr   r   r   r   numpy.lib.arraysetopsr   r   r   r	   r
   r   r   r   r   r   r   r!   r!   r!   r"   <module>   s    (   :