o
    8ήc+                     @   s   d dl Z d dlmZ d dlmZmZ d dlmZ d dlmZm	Z	 d dl
Z
G dd de
jZG dd	 d	ee
jZed
krAe
  dS dS )    N)types)TypeManagerTypeCastingRules)rules)	castgraph
Conversionc                   @   s   e Zd Zdd ZdS )CompatibilityTestMixinc                 C   s  t j}t j}t j}t j}t j}t j}t j}t j}	t j	}
t j
}t j}t j}t j}t j}| |||tj | |||tj | |||tj | |||tj | |||tj | |||tj | |||	tj | ||	|tj | ||	|tj | |||tj | |||tj | ||	|tj | |||tj | ||	|tj | |||tj | ||
|tj | |||tj | |||tj | |||tj | |||tj | |||tj | |||tj | |||tj | |||
tj tt jt jD ]#\}}|t jv r4|t jvr4q"| j|||d ud||f d q"d S )NzNo cast from %s to %s)msg)r   booleanint8int16int32int64uint8uint16uint32uint64float16float32float64	complex64
complex128assertEqualr   exactsafeunsafepromote	itertoolsproductnumber_domaincomplex_domain
assertTrue)selfcheck_compatiblebi8i16i32i64u8u16u32u64f16f32f64c64c128tatb r4   @/tmp/pip-target-vg8gfxp4/lib/python/numba/tests/test_typeconv.pycheck_number_compatibility   s^   

z1CompatibilityTestMixin.check_number_compatibilityN)__name__
__module____qualname__r6   r4   r4   r4   r5   r   
   s    r   c                   @   sL   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S )TestTypeConvc                 C   s   t  }tj}tj}tj}||| ||| ||f}||f||f||fg}|||dd}| |d | 	t
 |||dd}W d    d S 1 sNw   Y  d S NTF   )r   r   r   r   r   set_promoteset_unsafe_convertselect_overloadr   assertRaises	TypeError)r"   tmr'   r(   r.   sigovsselr4   r4   r5   test_typeconvF   s    "zTestTypeConv.test_typeconvc                 C   s   t j}| |j d S N)r   default_type_managerr6   r#   )r"   rB   r4   r4   r5   test_default_rules^   s   zTestTypeConv.test_default_rulesc                 C   sd   t j}tj}tj}|||f}|||f|||fg}| |||ddd | |||ddd d S r;   )r   rH   r   r   r   r   r?   )r"   rB   r'   r(   rC   rD   r4   r4   r5   test_overload1b   s   
zTestTypeConv.test_overload1c                 C   s   t j}tj}tj}tj}|||f}|||f|||f|||fg}| |j||dddd | |j||dddd |  | |j||dddd | |j||dddd d S )NFallow_unsafeexact_match_requiredr<   T)	r   rH   r   r   r   r   r   r?   reverse)r"   rB   r&   r'   r(   rC   rD   r4   r4   r5   test_overload2r   s<   
zTestTypeConv.test_overload2c                 C   s   t j}tj}tj}tj}||f}||f||fg}| |j||dddd | |j||dddd |  | |j||dddd | |j||dddd d S )NFrK   r   Tr<   )	r   rH   r   r   r   r   r   r?   rN   )r"   rB   r'   r(   r/   rC   rD   r4   r4   r5   test_overload3   s:   zTestTypeConv.test_overload3c           	      C   s`   t j}tj}tj}tj}tj}tj}|||f}|||f|||fg}| |j	||dddd d S )NTFrK   r   )
r   rH   r   r   r   r   r   r   r   r?   )	r"   rB   r&   r'   r(   r-   r.   rC   rD   r4   r4   r5   test_overload4   s   
zTestTypeConv.test_overload4c                    s  t  t}tjtjtjtjtjtj t	d}|
 | |
 |
  |   fdd}|  | | | | | || || |  |tj |tj |tj |tj |tj d S )Nmade_upc                      s8   tj  tj   tj  tj  tj  tj  tj  tj  tj  tj  tj  tj   tj   tj d S rG   )r   r#   r   r   r   r   r4   r-   r.   r/   r&   r'   r(   r"   rB   r4   r5   	base_test   s   z7TestTypeConv.test_type_casting_rules.<locals>.base_test)r   r   r   r   r   r   r   r   r   Dummypromote_unsafesafe_unsafeunsafe_unsafeassertIsNoner#   r   r   r   r   r   )r"   tcrrR   rT   r4   rS   r5   test_type_casting_rules   s:   
z$TestTypeConv.test_type_casting_rulesc                    s2  g   fdd}t |}tj}tj}tj}tj}|||tj	 |||tj
  d  |||tj |||tj
  d  |||tj	 |||tj
 | ||tj	f dd  | ||tj
f dd  |  d d  | ||tjf dd  | ||tj
f dd  | ||tj
f dd  | ||tj
f dd  |  d d  | ||tj	f dd  | ||tj
f dd  | ||tj
f dd  | ||tj
f dd  | ||tj
f dd  | ||tj
f dd  | t dd  d d S )	Nc                    s     | ||f d S rG   )append)srcdstrelsavedr4   r5   callback   s   z7TestTypeConv.test_castgraph_propagate.<locals>.callbackr                  )r   	TypeGraphr   r   r   r   r   insert_ruler   r   r   r\   r   assertInassertIsr   len)r"   rb   tgr'   r(   r/   r.   r4   r`   r5   test_castgraph_propagate   s<   


z%TestTypeConv.test_castgraph_propagateN)r7   r8   r9   rF   rI   rJ   rO   rP   rQ   r[   rn   r4   r4   r4   r5   r:   D   s    <r:   __main__)r   
numba.corer   numba.core.typeconv.typeconvr   r   numba.core.typeconvr   r   r   unittestTestCaser   r:   r7   mainr4   r4   r4   r5   <module>   s    : c