o
    ۾i                     @   s@  d dl Z d dlZd dlZd dlZd dlZd dlmZmZ d dl	m
Z
mZmZ d dlmZ d dlmZmZmZ d dlmZmZmZ ddiZd	diZd
d ZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZ G dd deZ!G dd deZ"G dd deZ#e$dkre%  dS dS )    N)jitnjit)typesutilserrors)_header_lead)TestCasetag
needs_blas)matmul_usecaseimatmul_usecase
DumbMatrixnopythonTforceobjc                    s    fdd}|S )Nc                    s   |   S N xexpr   N/home/ubuntu/.local/lib/python3.10/site-packages/numba/tests/test_operators.pypow_usecase      z&make_static_power.<locals>.pow_usecaser   )r   r   r   r   r   make_static_power   s   r   c                   @   s  e Zd Zedd Zedd Zedd Zedd Zed	d
 Zedd Z	edd Z
edd Zedd Zedd ZerJeeZeeZedd Zedd Zedd Zedd Zedd Zedd  Zed!d" Zed#d$ Zed%d& Zed'd( Zed)d* Zed+d, Zed-d. Zed/d0 Zed1d2 Zed3d4 Zed5d6 Z ed7d8 Z!ed9d: Z"ed;d< Z#ed=d> Z$ed?d@ Z%edAdB Z&edCdD Z'edEdF Z(edGdH Z)edIdJ Z*edKdL Z+dMS )NLiteralOperatorImplc                 C   s   | | S r   r   r   yr   r   r   add_usecase      zLiteralOperatorImpl.add_usecasec                 C   s   | |7 } | S r   r   r   r   r   r   iadd_usecase       z LiteralOperatorImpl.iadd_usecasec                 C   s   | | S r   r   r   r   r   r   sub_usecase%   r   zLiteralOperatorImpl.sub_usecasec                 C   s   | |8 } | S r   r   r   r   r   r   isub_usecase)   r    z LiteralOperatorImpl.isub_usecasec                 C   s   | | S r   r   r   r   r   r   mul_usecase.   r   zLiteralOperatorImpl.mul_usecasec                 C   s   | |9 } | S r   r   r   r   r   r   imul_usecase2   r    z LiteralOperatorImpl.imul_usecasec                 C   s   | | S r   r   r   r   r   r   floordiv_usecase7   r   z$LiteralOperatorImpl.floordiv_usecasec                 C   s   | | } | S r   r   r   r   r   r   ifloordiv_usecase;   r    z%LiteralOperatorImpl.ifloordiv_usecasec                 C   s   | | S r   r   r   r   r   r   truediv_usecase@   r   z#LiteralOperatorImpl.truediv_usecasec                 C   s   | | } | S r   r   r   r   r   r   itruediv_usecaseD   r    z$LiteralOperatorImpl.itruediv_usecasec                 C   s   | | S r   r   r   r   r   r   mod_usecaseM   r   zLiteralOperatorImpl.mod_usecasec                 C   s   | |; } | S r   r   r   r   r   r   imod_usecaseQ   r    z LiteralOperatorImpl.imod_usecasec                 C   s   | | S r   r   r   r   r   r   r   V   r   zLiteralOperatorImpl.pow_usecasec                 C   s   | |C } | S r   r   r   r   r   r   ipow_usecaseZ   r    z LiteralOperatorImpl.ipow_usecasec                 C   s   | |> S r   r   r   r   r   r   bitshift_left_usecase_   r   z)LiteralOperatorImpl.bitshift_left_usecasec                 C   s   | |K } | S r   r   r   r   r   r   bitshift_ileft_usecasec   r    z*LiteralOperatorImpl.bitshift_ileft_usecasec                 C   s   | |? S r   r   r   r   r   r   bitshift_right_usecaseh   r   z*LiteralOperatorImpl.bitshift_right_usecasec                 C   s   | |L } | S r   r   r   r   r   r   bitshift_iright_usecasel   r    z+LiteralOperatorImpl.bitshift_iright_usecasec                 C   s   | |@ S r   r   r   r   r   r   bitwise_and_usecaseq   r   z'LiteralOperatorImpl.bitwise_and_usecasec                 C   s   | |M } | S r   r   r   r   r   r   bitwise_iand_usecaseu   r    z(LiteralOperatorImpl.bitwise_iand_usecasec                 C   s   | |B S r   r   r   r   r   r   bitwise_or_usecasez   r   z&LiteralOperatorImpl.bitwise_or_usecasec                 C   s   | |O } | S r   r   r   r   r   r   bitwise_ior_usecase~   r    z'LiteralOperatorImpl.bitwise_ior_usecasec                 C   s   | |A S r   r   r   r   r   r   bitwise_xor_usecase   r   z'LiteralOperatorImpl.bitwise_xor_usecasec                 C   s   | |N } | S r   r   r   r   r   r   bitwise_ixor_usecase   r    z(LiteralOperatorImpl.bitwise_ixor_usecasec                 C      |  S r   r   r   _unusedr   r   r   bitwise_not_usecase_binary      z.LiteralOperatorImpl.bitwise_not_usecase_binaryc                 C   r6   r   r   r   r   r   r   bitwise_not_usecase   r:   z'LiteralOperatorImpl.bitwise_not_usecasec                 C   s   |  S r   r   r   r   r   r   not_usecase   r:   zLiteralOperatorImpl.not_usecasec                 C   s   |  S r   r   r   r   r   r   negate_usecase   r:   z"LiteralOperatorImpl.negate_usecasec                 C   s   | 
 S r   r   r   r   r   r   unary_positive_usecase   r:   z*LiteralOperatorImpl.unary_positive_usecasec                 C   s   | |k S r   r   r   r   r   r   
lt_usecase   r   zLiteralOperatorImpl.lt_usecasec                 C   s   | |kS r   r   r   r   r   r   
le_usecase   r   zLiteralOperatorImpl.le_usecasec                 C   s   | |kS r   r   r   r   r   r   
gt_usecase   r   zLiteralOperatorImpl.gt_usecasec                 C   s   | |kS r   r   r   r   r   r   
ge_usecase   r   zLiteralOperatorImpl.ge_usecasec                 C   s   | |kS r   r   r   r   r   r   
eq_usecase   r   zLiteralOperatorImpl.eq_usecasec                 C   s   | |kS r   r   r   r   r   r   
ne_usecase   r   zLiteralOperatorImpl.ne_usecasec                 C   s   | |v S r   r   r   r   r   r   
in_usecase   r   zLiteralOperatorImpl.in_usecasec                 C   s   | |vS r   r   r   r   r   r   not_in_usecase   r   z"LiteralOperatorImpl.not_in_usecasec                 C   s   | |u S r   r   r   r   r   r   
is_usecase   r   zLiteralOperatorImpl.is_usecaseN),__name__
__module____qualname__staticmethodr   r   r!   r"   r#   r$   r%   r&   r'   r(   r   r   r)   r*   r   r+   r,   r-   r.   r/   r0   r1   r2   r3   r4   r5   r9   r;   r<   r=   r>   r?   r@   rA   rB   rC   rD   rE   rF   rG   r   r   r   r   r      s    




































r   c                   @   s  e Zd Zedd Zedd Zedd Zedd Zed	d
 Zedd Z	edd Z
edd Zedd Zedd Zedd Zedd Zedd Zedd Zedd Zedd  Zed!d" Zed#d$ Zed%d& Zed'd( Zed)d* Zed+d, Zed-d. Zed/d0 Zed1d2 Zed3d4 Zed5d6 Zed7d8 Zed9d: Z ed;d< Z!ed=d> Z"ed?d@ Z#edAdB Z$edCdD Z%edEdF Z&edGdH Z'edIdJ Z(edKdL Z)edMdN Z*edOdP Z+dQS )RFunctionalOperatorImplc                 C      t | |S r   )operatoraddr   r   r   r   r         z"FunctionalOperatorImpl.add_usecasec                 C   rM   r   )rN   iaddr   r   r   r   r      rP   z#FunctionalOperatorImpl.iadd_usecasec                 C   rM   r   )rN   subr   r   r   r   r!      rP   z"FunctionalOperatorImpl.sub_usecasec                 C   rM   r   )rN   isubr   r   r   r   r"      rP   z#FunctionalOperatorImpl.isub_usecasec                 C   rM   r   )rN   mulr   r   r   r   r#      rP   z"FunctionalOperatorImpl.mul_usecasec                 C   rM   r   )rN   imulr   r   r   r   r$      rP   z#FunctionalOperatorImpl.imul_usecasec                 C   rM   r   )rN   floordivr   r   r   r   r%      rP   z'FunctionalOperatorImpl.floordiv_usecasec                 C   rM   r   )rN   	ifloordivr   r   r   r   r&      rP   z(FunctionalOperatorImpl.ifloordiv_usecasec                 C   rM   r   )rN   truedivr   r   r   r   r'      rP   z&FunctionalOperatorImpl.truediv_usecasec                 C   rM   r   )rN   itruedivr   r   r   r   r(      rP   z'FunctionalOperatorImpl.itruediv_usecasec                 C   rM   r   )rN   modr   r   r   r   r)      rP   z"FunctionalOperatorImpl.mod_usecasec                 C   rM   r   )rN   imodr   r   r   r   r*      rP   z#FunctionalOperatorImpl.imod_usecasec                 C   rM   r   )rN   powr   r   r   r   r      rP   z"FunctionalOperatorImpl.pow_usecasec                 C   rM   r   )rN   ipowr   r   r   r   r+      rP   z#FunctionalOperatorImpl.ipow_usecasec                 C   rM   r   )rN   matmulr   r   r   r   r      rP   z%FunctionalOperatorImpl.matmul_usecasec                 C   rM   r   )rN   imatmulr   r   r   r   r     rP   z&FunctionalOperatorImpl.imatmul_usecasec                 C   rM   r   )rN   lshiftr   r   r   r   r,     rP   z,FunctionalOperatorImpl.bitshift_left_usecasec                 C   rM   r   )rN   ilshiftr   r   r   r   r-     rP   z-FunctionalOperatorImpl.bitshift_ileft_usecasec                 C   rM   r   )rN   rshiftr   r   r   r   r.     rP   z-FunctionalOperatorImpl.bitshift_right_usecasec                 C   rM   r   )rN   irshiftr   r   r   r   r/     rP   z.FunctionalOperatorImpl.bitshift_iright_usecasec                 C   rM   r   )rN   and_r   r   r   r   r0     rP   z*FunctionalOperatorImpl.bitwise_and_usecasec                 C   rM   r   )rN   iandr   r   r   r   r1     rP   z+FunctionalOperatorImpl.bitwise_iand_usecasec                 C   rM   r   )rN   or_r   r   r   r   r2     rP   z)FunctionalOperatorImpl.bitwise_or_usecasec                 C   rM   r   )rN   iorr   r   r   r   r3   #  rP   z*FunctionalOperatorImpl.bitwise_ior_usecasec                 C   rM   r   )rN   xorr   r   r   r   r4   '  rP   z*FunctionalOperatorImpl.bitwise_xor_usecasec                 C   rM   r   )rN   ixorr   r   r   r   r5   +  rP   z+FunctionalOperatorImpl.bitwise_ixor_usecasec                 C   
   t | S r   rN   invertr7   r   r   r   r9   /     
z1FunctionalOperatorImpl.bitwise_not_usecase_binaryc                 C   rj   r   rk   r   r   r   r   r;   3  rm   z*FunctionalOperatorImpl.bitwise_not_usecasec                 C   rj   r   )rN   not_r   r   r   r   r<   7  rm   z"FunctionalOperatorImpl.not_usecasec                 C   rj   r   )rN   negr   r   r   r   r=   ;  rm   z%FunctionalOperatorImpl.negate_usecasec                 C   rj   r   )rN   posr   r   r   r   r>   ?  rm   z-FunctionalOperatorImpl.unary_positive_usecasec                 C   rM   r   )rN   ltr   r   r   r   r?   C  rP   z!FunctionalOperatorImpl.lt_usecasec                 C   rM   r   )rN   ler   r   r   r   r@   G  rP   z!FunctionalOperatorImpl.le_usecasec                 C   rM   r   )rN   gtr   r   r   r   rA   K  rP   z!FunctionalOperatorImpl.gt_usecasec                 C   rM   r   )rN   ger   r   r   r   rB   O  rP   z!FunctionalOperatorImpl.ge_usecasec                 C   rM   r   )rN   eqr   r   r   r   rC   S  rP   z!FunctionalOperatorImpl.eq_usecasec                 C   rM   r   )rN   ner   r   r   r   rD   W  rP   z!FunctionalOperatorImpl.ne_usecasec                 C   s   t || S r   rN   containsr   r   r   r   rE   [  rP   z!FunctionalOperatorImpl.in_usecasec                 C   s   t ||  S r   rw   r   r   r   r   rF   _  s   z%FunctionalOperatorImpl.not_in_usecasec                 C   rM   r   )rN   is_r   r   r   r   rG   c  rP   z!FunctionalOperatorImpl.is_usecaseN),rH   rI   rJ   rK   r   r   r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r   r+   r   r   r,   r-   r.   r/   r0   r1   r2   r3   r4   r5   r9   r;   r<   r=   r>   r?   r@   rA   rB   rC   rD   rE   rF   rG   r   r   r   r   rL      s    






































rL   c                   @   s  e Zd ZdZeZejejej	ej
ejejejejejejejdZefddZefddZdd Zed	fd
dZg dZejejejejejejgZ ej!ej"gZ#efddZ$dd Z%efddZ&dd Z'efddZ(dd Z)efddZ*dd Z+efddZ,dd  Z-efd!d"Z.d#d$ Z/d%d& Z0d'd( Z1efd)d*Z2efd+d,Z3efd-d.Z4efd/d0Z5efd1d2Z6dd4d5Z7e7e8 d6d7d8d9d: e7e8 d;d7d8d9d: e7e8 d<d7d=d> ed3fd?d@Z9efdAdBZ:dCdD Z;efdEdFZ<dGdH Z=efdIdJZ>dKdL Z?efdMdNZ@efdOdPZAe7e8 dQdRdSd> efdTdUZBdVdW ZCefdXdYZDdZd[ ZEefd\d]ZFd^d_ ZGefd`daZHdbdc ZIefdddeZJdfdg ZKdhdi ZLdjdk ZMdldm ZNeOdndo ZPdpdq ZQdrds ZRefdtduZSe7e8 dvdwdxi efdydzZTe7e8 d{dwd|i efd}d~ZUe7e8 dddd efddZVdd ZWdd ZXdd ZYdd ZZdd Z[dd Z\dd Z]dd Z^dd Z_efddZ`dd ZaefddZbdd ZcdS )TestOperatorszw
    Test standard Python operators on scalars.

    NOTE: operators on array are generally tested in test_ufuncs.
    r,   r-   r.   r/   r0   r1   r2   r3   r4   r5   r9   c                 C   s   |D ]I}t |fi ||}t||D ]6\}}	t|}
t|}||
|	}|||	}| j||d||	|||f d | j|
|d||	||
|f d qqd S )Nz-mismatch for (%r, %r) with types %s: %r != %rmsg)r   	itertoolsproductcopyassertPreciseEqualselfpyfunc
x_operands
y_operands
types_listflags	arg_typescfuncr   r   x_got
x_expectedgotexpectedr   r   r   run_test_ints  s*   



zTestOperators.run_test_intsc                 C   s   |D ]=}t |fi ||}t||D ]*\}}	t|}
t|}||
|	}|||	}tjj||dd tjj|
|dd qqd S )Ngh㈵>)rtol)r   r~   r   r   nptestingassert_allcloser   r   r   r   run_test_floats  s   



zTestOperators.run_test_floatsc                 C   sX   t |dr
||S |tjv rtt|jS |tjv r t|jS |tjv r*t	|jS |S )Ndtype)
hasattrcast_python_valuer   unsigned_domainabsintrealinteger_domainreal_domainfloat)r   op
numba_typer   r   r   coerce_operand  s   






zTestOperators.coerce_operandTc              
   C   s   | j }| j}|s|| j }|D ]E}t||ffi ||}t||D ]0\}}	| ||}| |	|}	|||	}
|||	}| t|t|
 | 	||
d|||	f  q#qd S )Nzmismatch with %r (%r, %r))
compare_scalar_operandscompare_typescompare_unordered_typesr   r~   r   r   assertIstypeassertEqual)r   r   r   orderedopsr   typr   r   r   r   r   r   r   r   run_test_scalar_compare  s&   


z%TestOperators.run_test_scalar_compare)g      y            ?y             @y            ?      ?c                 C      |  | jj| d S r   )r   r   r?   r   r   r   r   r   test_lt_scalar     zTestOperators.test_lt_scalarc                 C      | j td d S Nr   )r   Noflagsr   r   r   r   test_lt_scalar_npm     z TestOperators.test_lt_scalar_npmc                 C   r   r   )r   r   r@   r   r   r   r   test_le_scalar  r   zTestOperators.test_le_scalarc                 C   r   r   )r   r   r   r   r   r   test_le_scalar_npm  r   z TestOperators.test_le_scalar_npmc                 C   r   r   )r   r   rA   r   r   r   r   test_gt_scalar  r   zTestOperators.test_gt_scalarc                 C   r   r   )r   r   r   r   r   r   test_gt_scalar_npm  r   z TestOperators.test_gt_scalar_npmc                 C   r   r   )r   r   rB   r   r   r   r   test_ge_scalar  r   zTestOperators.test_ge_scalarc                 C   r   r   )r   r   r   r   r   r   test_ge_scalar_npm  r   z TestOperators.test_ge_scalar_npmc                 C      | j | jj|dd d S NF)r   )r   r   rC   r   r   r   r   test_eq_scalar     zTestOperators.test_eq_scalarc                 C   r   r   )r   r   r   r   r   r   test_eq_scalar_npm  r   z TestOperators.test_eq_scalar_npmc                 C   r   r   )r   r   rD   r   r   r   r   test_ne_scalar  r   zTestOperators.test_ne_scalarc                 C   r   r   )r   r   r   r   r   r   test_ne_scalar_npm  r   z TestOperators.test_ne_scalar_npmc                 C   s,   t tjtjf| jj}| |tt d S r   )r   r   ellipsisr   rG   
assertTrueEllipsisr   r   r   r   r   test_is_ellipsis  s   zTestOperators.test_is_ellipsisc                    sV   t tjtjfdd| jj t dd fdd}| |dd | |dd d S )NTr   c                    s
    | |S r   r   r   
cfunc_voidr   r   r     rm   z-TestOperators.test_is_void_ptr.<locals>.cfunc      )r   r   voidptrr   rG   r   assertFalser   r   r   r   test_is_void_ptr  s   zTestOperators.test_is_void_ptrc                 C   s6   g d}g d}t jt jfg}| j|||||d d S )NFFTT)FTFTr   )r   booleanr   r   r   r   r   r   r   r   r   r   run_binop_bools  s   
zTestOperators.run_binop_boolsc                 C   s   g d}g d}t jt jft jt jfg}| j|||||d ddg}ddg}t jt jft jt jft jt jfg}| j|||||d d S )N)r   r   r   )r      r   r   r   r   r   int32int64r   byteuint32uint64r   r   r   r   run_binop_ints  "   





zTestOperators.run_binop_intsc                 C   @   g d}g d}t jt jft jt jfg}| j|||||d d S )N)g        g?)g      g?g @r   r   float32float64r   r   r   r   r   run_binop_floats"     


zTestOperators.run_binop_floatsc                 C   s   | j ||d d S r   )r   )r   r   r   r   r   r   run_binop_floats_floordiv,     z'TestOperators.run_binop_floats_floordivc                 C   r   )N)y333333?y                y        ?)y      ffffffy        ?y @       r   )r   	complex64
complex128r   r   r   r   r   run_binop_complex/  r   zTestOperators.run_binop_complexFc                    s   |D ]N}|  D ]G\}}dD ]@}d||f }|r|d7 }|r tnt}	d| }
||
|	fdd |r=d|v r=|s= fdd	}n }||_|rJtd
|}|| |< qqqd S )NFTz
test_%s_%s_npmz
%s_usecasec                 S   s$   t | |}t | j|}||| d S r   )getattrr   )r   runner_nameusecase_namer   runner
op_usecaser   r   r   innerC  s   
z1TestOperators.generate_binop_tests.<locals>.innerarrayc                    s4   |       W d    d S 1 sw   Y  d S r   )assertTypingErrorr   r   r   r   	test_methJ  s   
"z5TestOperators.generate_binop_tests.<locals>.test_meth	important)itemsr   force_pyobj_flagsrH   r	   )nsusecases
tp_runners	npm_arrayusecasetp_namer   r   	test_namer   r   r   r   r   r   generate_binop_tests9  s*   

z"TestOperators.generate_binop_tests)rO   rQ   rR   rS   rT   rU   r   r   r   )intsfloatscomplex)rX   rY   )rV   rW   rZ   r[   r   )r  r  c           
   	   C   s   t | j|}tjtjtjg}|r|tj |D ]5}t||ffi ||}| 	t
}	|dd W d    n1 s;w   Y  |turM| |t|	j qd S )Nr   r   )r   r   r   r   r   r   appendr   r   assertRaisesZeroDivisionErrorr   assertInstr	exception)
r   r   r}   r   allow_complexr   r   tpr   cmr   r   r   check_div_errorsm  s   zTestOperators.check_div_errorsc                 C   s   | j dd|dd d S )Nr'   division by zeroT)r   r  r  r   r   r   r   test_truediv_errors}  s   

z!TestOperators.test_truediv_errorsc                 C   r   r   )r  r   r   r   r   r   test_truediv_errors_npm  r   z%TestOperators.test_truediv_errors_npmc                 C      | j dd|d d S )Nr%   r  r   r  r   r   r   r   test_floordiv_errors  r   z"TestOperators.test_floordiv_errorsc                 C   r   r   )r  r   r   r   r   r   test_floordiv_errors_npm  r   z&TestOperators.test_floordiv_errors_npmc                 C   r  )Nr)   zmodulo by zeror   r  r   r   r   r   test_mod_errors  r   zTestOperators.test_mod_errorsc                 C   r   r   )r  r   r   r   r   r   test_mod_errors_npm  r   z!TestOperators.test_mod_errors_npmc                 C   s   g d}g d}t jt jft jt jfg}| j|||||d g d}g d}t jt jft jt jft jt jfg}| j|||||d d S )Nr   r   r   r   r   r   r   r   r   r   r   r   r   run_pow_ints  r   zTestOperators.run_pow_intsc                 C   sz   g d}g d}t jt jft jt jfg}| j|||||d dg}g d}t jt jft jt jfg}| j|||||d d S )N)gvkgv[gv[@gvk@r  r   r   r  r   r   r   r   r   run_pow_floats  s    




zTestOperators.run_pow_floats)r\   r]   r  r  c                 C   sD   | j j}g d}|}tjtjftjtjfg}| j|||||d d S )Ny      ?        y              ?y            r   )r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   test_add_complex  s   


zTestOperators.test_add_complexc                 C   r   r   )r"  r   r   r   r   r   test_add_complex_npm  r   z"TestOperators.test_add_complex_npmc                 C   H   | j j}g d}g d}tjtjftjtjfg}| j|||||d d S Nr   )r   r   r   r   )r   r!   r   r   r   r   r!  r   r   r   test_sub_complex     


zTestOperators.test_sub_complexc                 C   r   r   )r&  r   r   r   r   r   test_sub_complex_npm  r   z"TestOperators.test_sub_complex_npmc                 C   r$  r%  )r   r#   r   r   r   r   r!  r   r   r   test_mul_complex  r'  zTestOperators.test_mul_complexc                 C   r   r   )r)  r   r   r   r   r   test_mul_complex_npm  r   z"TestOperators.test_mul_complex_npmc                 C   r$  r%  )r   r'   r   r   r   r   r!  r   r   r   test_truediv_complex  r'  z"TestOperators.test_truediv_complexc                 C   r   r   )r+  r   r   r   r   r   test_truediv_complex_npm  r   z&TestOperators.test_truediv_complex_npmc                 C   s   | j j}ttjtjffi ||}| t}|dd W d    n1 s'w   Y  tjdv r4d}nt	tj| 
|t|j d S )Ny              @y               @))r   
   r      )r      )r      z!unsupported operand type(s) for %)r   r)   r   r   r   r	  	TypeErrorr   	PYVERSIONNotImplementedErrorr  r  r  )r   r   r   cresraisesr}   r   r   r   test_mod_complex  s   

zTestOperators.test_mod_complexc                 C   sJ   | j j}|   ttjtjf| W d    d S 1 sw   Y  d S r   )r   r)   r   r   r   r   )r   r   r   r   r   test_mod_complex_npm  s   
"z"TestOperators.test_mod_complex_npmc                 C   sj   t di t|}td}td}|||}| |jd |r'| || d S | || | || d S )Nr   r      r0  r   )r   r   r   r   valuer   assertIsNot)r   r   inplacer   abr   r   r   r   check_matmul_objmode  s   
z"TestOperators.check_matmul_objmodec                 C      | j | jjdd d S )NFr=  )r@  r   r   r   r   r   r   test_matmul     zTestOperators.test_matmulc                 C   rA  )NTrB  )r@  r   r   r   r   r   r   test_imatmul"  rD  zTestOperators.test_imatmulc                 C   sv   t t jdd}t||f|}tddg}tddg}|||}| |t|| | || | || d S )Nr   Cr   r   r9  )r   Arrayr   r   r   r   dotr<  )r   r   arrtyr   r>  r?  r   r   r   r   check_matmul_npm%  s   
zTestOperators.check_matmul_npmc                 C   s   |  | jj d S r   )rJ  r   r   r   r   r   r   test_matmul_npm1  r   zTestOperators.test_matmul_npmc                 C   s<   |   }| | jj W d    d S 1 sw   Y  d S r   )r   rJ  r   r   )r   r6  r   r   r   test_imatmul_npm4  s   
"zTestOperators.test_imatmul_npmc                 C   s   ddg}g d}t jt jfg}| j|||||d ddg}g d}t jt jfg}| j|||||d ddg}g d}t jt jfg}| j|||||d ddg}g d}t jt jfg}| j|||||d d S )Nr   r   r   r   r   r9           r   r   r   r   r9  rN  rO      ?   r   r   r   r   r   r   r   r   r   r   r   run_bitshift_left<  0   
zTestOperators.run_bitshift_left)bitshift_leftbitshift_ileftr  rU  c                 C   s   g d}g d}t jt jfg}| j|||||d g d}g d}t jt jfg}| j|||||d g d}g d}t jt jfg}| j|||||d g d}g d}t jt jfg}| j|||||d d S )N)r   r       rM  r   )r   r       rQ  )r   r      )r   r   r[  rT  r   r   r   r   run_bitshift_rightb  rV  z TestOperators.run_bitshift_right)bitshift_rightbitshift_irightr\  c                 C   s4  t tdddg }t tdddg }tjtjfg}| j|||||d t tdddg }t tdddg }tjtjfg}| j|||||d t tdddd	g }t tdddd	g }tjtjfg}| j|||||d t tddd
dg }t tddd
dg }tjtjfg}| j|||||d d S )Nr   rN  rY  r   rZ  r9  r[               )listranger   r   r   r   r   r   r   r   r   r   run_logical  s0   
zTestOperators.run_logical)bitwise_andbitwise_iand
bitwise_orbitwise_iorbitwise_xorbitwise_ixorre  r   )r  boolsc           	      C   sr  | j j}ttdddg }dd |D }dg}tjtjfg}| j|||||d ttddd	d
g }dg}tjtjfg}| j|||||d ttdddg }dd |D }dg}tjtjfg}| j|||||d ttddddg }dg}tj	tj	fg}| j|||||d g d}tt
tj|}| j j}ttjffi ||}|D ]}| |||| qd S )Nr   rN  rY  c                 S      g | ]}t |qS r   )r   r   .0r   r   r   r   
<listcomp>      z2TestOperators.test_bitwise_not.<locals>.<listcomp>r   r_  r9  r[  r`  rZ  c                 S   rm  r   )r   r   rn  r   r   r   rp    rq  ra  rb  r   )r   r9   rc  rd  r   r   r   r   r   r   mapr   bool_r;   r   r   r   )	r   r   r   r   r   r   valuesr   valr   r   r   test_bitwise_not  sD   zTestOperators.test_bitwise_notc                 C   r   r   )rv  r   r   r   r   r   test_bitwise_not_npm  r   z"TestOperators.test_bitwise_not_npmc                    sJ    fdd}g d}|D ]}t  j|}||tjtjf j| d qdS )zI
        Make sure that bitwise float operations are not allowed
        c                    s   d | } jtj|d}t||  W d    n1 sw   Y  td }| t|tr0|nd |} |t|j	 d S )Nz'expecting TypingError when compiling {}r|   z {}zFunction({}))
formatr	  r   TypingErrorr   r   
isinstancer  r  r  )r   argtypesopnamer}   r6  fmt	expectingr   r   r   assert_reject_compile  s   
z?TestOperators.test_bitwise_float.<locals>.assert_reject_compiler{   )r|  N)r   r   r   r   _bitwise_opnames)r   r  methodsnamer   r   r   r   test_bitwise_float  s   z TestOperators.test_bitwise_floatc                 C   D   | j j}g d}tdi t|}|D ]}| |||| qd S )Nr   r   r   333333?        333333@r   r:  )r   r<   r   r   r   r   r   rt  r   ru  r   r   r   test_not	  s   zTestOperators.test_notc                 C   sx   | j j}tjtjtjtjtjg}g d}t||D ] \}}t	|f|}| 
|jd jtj | 
|||| qd S )Nr  r   )r   r<   r   int8r   r   r   r   zipr   r   nopython_signaturesreturn_typer   r   r   argtysrt  tyru  r   r   r   r   test_not_npm  s   zTestOperators.test_not_npmc                 C   n   | j j}tjtjtjtjtjtjtj	tj	g}g d}t
||D ]\}}t|f|}| |||| qd S N)r   r   r   r  g333333@r  TF)r   r=   r   r  r   r   r   r   r   r   r  r   assertAlmostEqualr  r   r   r   test_negate_npm1     

zTestOperators.test_negate_npmc                 C   r  N)r   r   r   r  r  TFr   r:  )r   r=   r   r   r   r  r   r   r   test_negateM     	zTestOperators.test_negatec                 C   r  r  )r   r>   r   r  r   r   r   r   r   r   r  r   r  r  r   r   r   test_unary_positive_npm\  r  z%TestOperators.test_unary_positive_npmc                 C   r  r  )r   r>   r   r   r   r  r   r   r   test_unary_positivew  r  z!TestOperators.test_unary_positivec                 C   sP   t j}t|t |dffi ||}dD ]}d}| |||||| qd S )Nr   )r   r9        *   )r   r  r  )r   r   r   UniTupler   )r   r   r   r   r   itupr   r   r   	_check_in  s    zTestOperators._check_inc                 C   r   r   )r  r   rE   r   r   r   r   test_in  r   zTestOperators.test_inc                 C   r   r   )r  r   r   r   r   r   test_in_npm  r   zTestOperators.test_in_npmc                 C   r   r   )r  r   rF   r   r   r   r   test_not_in  r   zTestOperators.test_not_inc                 C   r   r   )r  r   r   r   r   r   test_not_in_npm  r   zTestOperators.test_not_in_npmN)F)drH   rI   rJ   __doc__r   r   rN   r`   ra   rb   rc   rd   re   rf   rg   rh   ri   rl   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  localsr  r  r  r  r  r  r  r  r  r"  r#  r&  r(  r)  r*  r+  r,  r7  r8  r@  rC  rE  r
   rJ  rK  rL  rU  r\  re  rv  rw  r  r  r  r  r  r  r  r  r  r  r  r  r   r   r   r   rz   h  s   


	





!!!/"rz   c                   @   sB   e Zd ZeZejejejej	ej
ejejejejejejdZdS )TestOperatorModuler{   N)rH   rI   rJ   rL   r   rN   r`   ra   rb   rc   rd   re   rf   rg   rh   ri   rl   r  r   r   r   r   r    s    
r  c                   @   sX  e Zd ZdZeZg dZejej	ej
ejgZdd eD Zdd eD ZeeeeZdd eD Zdd eD Zdd	 Zd
d Zdd Zdd Zdd Zdd Zedd fddZefddZedd f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/d0 Z(d1d2 Z)d3d4 Z*d5d6 Z+d7d8 Z,d9d: Z-d;d< Z.d=S )>TestMixedIntsz<
    Tests for operator calls with mixed integer types.
    )r   r   r   r-  r     i'  r   r   iiiic                 C   s   g | ]}|j r|qS r   signedro  r  r   r   r   rp    rq  zTestMixedInts.<listcomp>c                 C   s   g | ]}|j s|qS r   r  r  r   r   r   rp    rq  c                 C   s$   g | ]\}}|j s|j r||fqS r   r  ro  uvr   r   r   rp    
    c                 C   s$   g | ]\}}|j s|j s||fqS r   r  r  r   r   r   rp    r  c                 C   s(   t |j}|j|  ko|jkS   S r   )r   iinfokeyminmax)r   ru  r  tp_infor   r   r   int_in_dtype_range  s   z TestMixedInts.int_in_dtype_rangec                 G   .   t dd |D }t |tjj}ttd| S )Nc                 s       | ]	}|j jd  V  qdS rN  Nr   itemsizero  r  r   r   r   	<genexpr>      z8TestMixedInts.get_numpy_signed_upcast.<locals>.<genexpr>zint%dr  r   intpbitwidthr   r   r   valsr  r   r   r   get_numpy_signed_upcast     z%TestMixedInts.get_numpy_signed_upcastc                 G   r  )Nc                 s   r  r  r  r  r   r   r   r    r  z:TestMixedInts.get_numpy_unsigned_upcast.<locals>.<genexpr>zuint%dr  r  r   r   r   get_numpy_unsigned_upcast  r  z'TestMixedInts.get_numpy_unsigned_upcastc                 C   s   t t|j|S r   )r   r   r  )r   r   ru  r   r   r   get_typed_int  r   zTestMixedInts.get_typed_intc                       t t|  fdd}|S )Nc                        | |} || ||S r   r  r>  r?  r  r   r   r   r   control_signed     z8TestMixedInts.get_control_signed.<locals>.control_signedr   rN   )r   r|  r  r   r  r   get_control_signed     
z TestMixedInts.get_control_signedc                    r  )Nc                    r  r   r  r  r  r   r   control_unsigned  r  z<TestMixedInts.get_control_unsigned.<locals>.control_unsignedr  )r   r|  r  r   r  r   get_control_unsigned  r  z"TestMixedInts.get_control_unsignedc                 C      | S r   r   r   r   r   r   <lambda>      zTestMixedInts.<lambda>c                 K   s   |D ]^\}}	t ||	f|}
t||D ]K\}}| ||r$| ||	s%q| ||}| |	|}|||}|
||}| || d||||	ff }||||}}| j||fd|i| qqd S )N#mismatch for (%r, %r) with types %sr}   )r   r~   r   r  r  assertIsInstancer   )r   r   control_funcoperandsr   expected_type
force_typeassertPreciseEqualArgsxtytr   r   r   r   r   r}   r   r   r   
run_binary  s&   

zTestMixedInts.run_binaryc              
   C   sx   |D ]7}t |f|}|D ]+}| ||sq| ||}||}	||}
| |
| | j|
|	d|||
|	f d qqd S )Nz&mismatch for %r with type %s: %r != %rr|   )r   r  r  r  r   )r   r   r  r  r   r  r  r   r   r   r   r   r   r   	run_unary  s"   
zTestMixedInts.run_unaryc                 C   r  r   r   r   r   r   r   r    r  c                 K   sP   | j || ||| j|fd|i| | j || ||| j|fd|i| d S )Nr  )r  r  signed_pairsr  unsigned_pairs)r   r   r|  samplesr  r  r  r   r   r   run_arith_binop  s   
zTestMixedInts.run_arith_binopc                 C      |  | jjd| j d S )NrO   )r  r   r   int_samplesr   r   r   r   test_add  r   zTestMixedInts.test_addc                 C   r  )NrR   )r  r   r!   r  r   r   r   r   test_sub  r   zTestMixedInts.test_subc                 C   r  )NrT   )r  r   r#   r  r   r   r   r   test_mul  r   zTestMixedInts.test_mulc                 C   &   dd | j D }| | jjd| d S )Nc                 S      g | ]}|d kr|qS r   r   rn  r   r   r   rp        z/TestMixedInts.test_floordiv.<locals>.<listcomp>rV   )r  r  r   r%   r   r  r   r   r   test_floordiv     zTestMixedInts.test_floordivc                 C   r  )Nc                 S   r  r  r   rn  r   r   r   rp    r  z*TestMixedInts.test_mod.<locals>.<listcomp>rZ   )r  r  r   r)   r  r   r   r   test_mod  r  zTestMixedInts.test_modc                    s   i }t jdkrt|d<  jj}dd  jD } j|d|fi |  fdd}dd  jD }d	d  jD } j||||fi | d S )
Nr.  r  c                 S   s   g | ]}|d kr|qS r  r   rn  r   r   r   rp  '  r  z*TestMixedInts.test_pow.<locals>.<listcomp>r\   c                    sP     | |}|dkr|| || S || ||  }|dkr!dS td| S )Nr   g      ?)r  r   r  )r>  r?  r  invr   r   r   r  +  s   z.TestMixedInts.test_pow.<locals>.control_signedc                 S   r  r  r   rn  r   r   r   rp  5  r  c                 S   s$   g | ]\}}|j r|j r||fqS r   r  r  r   r   r   rp  6  r  )	r   r3  r   r   r   r  r  
type_pairsr  )r   
extra_castr   r  r  r  r   r   r   test_pow   s   


zTestMixedInts.test_powc                 C   sT   dd }dd | j D }| jj}| j|||| jtdd | j|||| jtdd d S )Nc                 S   s   t | t | S r   )r   r>  r?  r   r   r   control=  r   z+TestMixedInts.test_truediv.<locals>.controlc                 S   r  r  r   rn  r   r   r   rp  ?  r  z.TestMixedInts.test_truediv.<locals>.<listcomp>double)r  prec)r  r   r'   r  r  r   r  r   r  r  r   r   r   r   test_truediv;  s   
zTestMixedInts.test_truedivc                 C   r  )Nrd   )r  r   r0   r  r   r   r   r   test_andJ  r   zTestMixedInts.test_andc                 C   r  )Nrf   )r  r   r2   r  r   r   r   r   test_orM  r   zTestMixedInts.test_orc                 C   r  )Nrh   )r  r   r4   r  r   r   r   r   test_xorP  r   zTestMixedInts.test_xorc           
         s   t t|  fdd} fdd}jfdd}dd jD }d	d jD }|D ]
\}}	|||	| q0|D ]
\}}	|||	| q=d S )
Nc                    r  r   r  r  opfuncr   r   r   r  U  r  z5TestMixedInts.run_shift_binop.<locals>.control_signedc                    r  r   r  r  r  r   r   r  X  r  z7TestMixedInts.run_shift_binop.<locals>.control_unsignedc           
         s   t | |f }D ]H}| jd }dddd|d |fD ]6}|| r)||s*q| |}||}|||}|||}d||| |ff }	j|||	d qq
d S )Nr   r   r   r  r  r|   )r   r  r  r  r   )
r  r  r  r   r   maxshiftr   r   r   r}   )r   r  r   r   r   check^  s    


z,TestMixedInts.run_shift_binop.<locals>.checkc                 S   s   g | ]\}}|j r||fqS r   r  r  r   r   r   rp  r      z1TestMixedInts.run_shift_binop.<locals>.<listcomp>c                 S   s   g | ]\}}|j s||fqS r   r  r  r   r   r   rp  t  r  )r   rN   r  r  )
r   r   r|  r  r  r  r  r  r  r  r   )r  r   r  r   r   run_shift_binopS  s   
zTestMixedInts.run_shift_binopc                 C      |  | jjd d S )Nr`   )r  r   r,   r   r   r   r   test_lshift|  r   zTestMixedInts.test_lshiftc                 C   r	  )Nrb   )r  r   r.   r   r   r   r   test_rshift  r   zTestMixedInts.test_rshiftc                 C   s,   dd }| j }| jj}| |||| j d S )Nc                 S   r  r   r   r>  r   r   r   r    s   z2TestMixedInts.test_unary_positive.<locals>.control)r  r   r>   r  	int_typesr  r   r   r   r    s   z!TestMixedInts.test_unary_positivec                    N    fdd} fdd} j } jj} ||| j  ||| j d S )Nc                         | }||  S r   r  r>  r  r   r   r   r       

z9TestMixedInts.test_unary_negative.<locals>.control_signedc                    r  r   r  r  r   r   r   r    r  z;TestMixedInts.test_unary_negative.<locals>.control_unsigned)r  r   r=   r  signed_typesunsigned_typesr   r  r  r  r   r   r   r   test_unary_negative     z!TestMixedInts.test_unary_negativec                    r  )Nc                         | }||  S r   r  r  r   r   r   r    r  z1TestMixedInts.test_invert.<locals>.control_signedc                    r  r   r  r  r   r   r   r    r  z3TestMixedInts.test_invert.<locals>.control_unsigned)r  r   r;   r  r  r  r  r   r   r   test_invert  r  zTestMixedInts.test_invertN)/rH   rI   rJ   r  r   r   r  r   r  uint8r   r   r  r  r  rc  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    sL    


)r  c                   @   s   e Zd ZeZdS )TestMixedIntsOperatorModuleN)rH   rI   rJ   rL   r   r   r   r   r   r    s    r  c                   @   s(   e Zd ZdZdd Zdd Zdd ZdS )	TestStaticPowerz`
    Test the ** operator with a static exponent, to exercise a
    dedicated optimization.
    c                 C   s   |D ]R}t j}t|}tdd|}tdd|}|D ]8}z|||}	W n" tyF   | t || W d    n1 s?w   Y  Y qw ||}
| j|	|
dd qqd S )NTr   r  )r  )r   r   r   r   r
  r	  r   )r   	exponentsrt  r   regular_funcstatic_funcstatic_cfuncregular_cfuncr  r   r   r   r   r   
_check_pow  s$   
zTestStaticPower._check_powc              	   C   s6   g d}dddddt dt dg}| || d S )	N)	r   r   r   r     r   r   r  r   r   r   r   r   r_  r   r9  )r   r  uint16r!  r   r  r  r   r   r   test_int_values     zTestStaticPower.test_int_valuesc                 C   s6   g d}dddt dtdtdg}| || d S )N)r   r   r   r  r"  r   r   r  r   i ir   g      
@g      g       infnan)r   r   r   r!  r$  r   r   r   test_real_values  r&  z TestStaticPower.test_real_valuesN)rH   rI   rJ   r  r!  r%  r)  r   r   r   r   r    s
    r  c                   @   s    e Zd ZdZdd Zdd ZdS )TestStringConstComparisonz-
    Test comparison of string constants
    c                 C   P   dd }dd }t dd|}t dd|}| | |  | | |  d S )Nc                  S   s   d} | dkS Ntestr   sr   r   r   
test_impl1     z5TestStringConstComparison.test_eq.<locals>.test_impl1c                  S   s   d} | dkS Ntest1r-  r   r.  r   r   r   
test_impl2  r1  z5TestStringConstComparison.test_eq.<locals>.test_impl2Tr   r   r   r   r0  r4  cfunc1cfunc2r   r   r   test_eq     z!TestStringConstComparison.test_eqc                 C   r+  )Nc                  S   s   d} | dkS r,  r   r.  r   r   r   r0    r1  z6TestStringConstComparison.test_neq.<locals>.test_impl1c                  S   s   d} | dkS r2  r   r.  r   r   r   r4    r1  z6TestStringConstComparison.test_neq.<locals>.test_impl2Tr   r5  r6  r   r   r   test_neq  r:  z"TestStringConstComparison.test_neqN)rH   rI   rJ   r  r9  r;  r   r   r   r   r*    s    r*  c                   @   s@   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	dS )TestBooleanLiteralOperatorsz/
    Test operators with Boolean constants
    c           	             fdd}fdd}dd }t jddgd	d
D ]\ }tdd|}| |||| qt jddgd	d
D ]\}tdd|}| |||| q8tdd|}| | |  d S )Nc                    s    | kS r   r   r?  a_valr   r   r0    r   z7TestBooleanLiteralOperators.test_eq.<locals>.test_impl1c                    s   |  kS r   r   r  b_valr   r   r4    r   z7TestBooleanLiteralOperators.test_eq.<locals>.test_impl2c                  S   s,   ddk} ddk}ddk}ddk}| |||fS NTFr   r1r2r3r4r   r   r   
test_impl3  
   z7TestBooleanLiteralOperators.test_eq.<locals>.test_impl3TFr   repeatr   r~   r   r   r   	r   r0  r4  rI  r?  r7  r>  r8  cfunc3r   r@  rB  r   r9       z#TestBooleanLiteralOperators.test_eqc           	         r=  )Nc                    s    | kS r   r   r>  r?  r   r   r0    r   z7TestBooleanLiteralOperators.test_ne.<locals>.test_impl1c                    s   |  kS r   r   r  rA  r   r   r4    r   z7TestBooleanLiteralOperators.test_ne.<locals>.test_impl2c                  S   s,   ddk} ddk}ddk}ddk}| |||fS rC  r   rD  r   r   r   rI    rJ  z7TestBooleanLiteralOperators.test_ne.<locals>.test_impl3TFr   rK  r   rM  rN  r   rP  r   test_ne  rQ  z#TestBooleanLiteralOperators.test_nec                    st    fdd}dd }t jddgddD ]\ }tdd	|}| |||| qtdd	|}| | |  d S )
Nc                    s    | u S r   r   r>  r?  r   r   r0  (  r   z7TestBooleanLiteralOperators.test_is.<locals>.test_impl1c                  S   s,   ddu } ddu }ddu }ddu }| |||fS rC  r   rD  r   r   r   r4  +  rJ  z7TestBooleanLiteralOperators.test_is.<locals>.test_impl2TFr   rK  r   rM  )r   r0  r4  r?  r7  r8  r   r?  r   test_is&  s   z#TestBooleanLiteralOperators.test_isc                 C   *   dd }t dd|}| | |  d S )Nc                  S   s   d\} }|  | fS Nr   r   r  r   r   r   	test_impl;  s   z7TestBooleanLiteralOperators.test_not.<locals>.test_implTr   r5  r   rV  r   r   r   r   r  9     z$TestBooleanLiteralOperators.test_notc                 C   rT  )Nc                  S      d\} }t | t |fS rU  )boolr  r   r   r   rV  D     z8TestBooleanLiteralOperators.test_bool.<locals>.test_implTr   r5  rW  r   r   r   	test_boolB  rX  z%TestBooleanLiteralOperators.test_boolc                 C   rT  )Nc                  S   rY  rU  )r  r  r   r   r   rV  M  r[  z?TestBooleanLiteralOperators.test_bool_to_str.<locals>.test_implTr   r5  rW  r   r   r   test_bool_to_strK  rX  z,TestBooleanLiteralOperators.test_bool_to_strN)
rH   rI   rJ   r  r9  rR  rS  r  r\  r]  r   r   r   r   r<    s    		r<  __main__)&r   r~   rN   unittestnumpyr   numbar   r   
numba.corer   r   r   numba.core.types.functionsr   numba.tests.supportr   r	   r
   numba.tests.matmul_usecaser   r   r   r   r   r   objectr   rL   rz   r  r  r  r  r*  r<  rH   mainr   r   r   r   <module>   sD     , $      8 y$ g