o
    iH                     @   sb  d dl Z d dlZ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 d dlmZ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 e
 Ze
 Zde_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)compile_isolatedFlags)jit)typesutilserrors	typeinfer)_header_lead)TestCasetag
needs_blas)matmul_usecaseimatmul_usecase
DumbMatrixTc                    s    fdd}|S )Nc                    s   |   S N xexpr   i/var/www/html/eduruby.in/lip-sync/lip-sync-env/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_usecase2   r   zLiteralOperatorImpl.mul_usecasec                 C   s   | |9 } | S r   r   r   r   r   r   imul_usecase6   r    z LiteralOperatorImpl.imul_usecasec                 C   s   | | S r   r   r   r   r   r   floordiv_usecase;   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_usecaseD   r   z#LiteralOperatorImpl.truediv_usecasec                 C   s   | | } | S r   r   r   r   r   r   itruediv_usecaseH   r    z$LiteralOperatorImpl.itruediv_usecasec                 C   s   | | S r   r   r   r   r   r   mod_usecaseQ   r   zLiteralOperatorImpl.mod_usecasec                 C   s   | |; } | S r   r   r   r   r   r   imod_usecaseU   r    z LiteralOperatorImpl.imod_usecasec                 C   s   | | S r   r   r   r   r   r   r   Z   r   zLiteralOperatorImpl.pow_usecasec                 C   s   | |C } | S r   r   r   r   r   r   ipow_usecase^   r    z LiteralOperatorImpl.ipow_usecasec                 C   s   | |> S r   r   r   r   r   r   bitshift_left_usecasec   r   z)LiteralOperatorImpl.bitshift_left_usecasec                 C   s   | |K } | S r   r   r   r   r   r   bitshift_ileft_usecaseg   r    z*LiteralOperatorImpl.bitshift_ileft_usecasec                 C   s   | |? S r   r   r   r   r   r   bitshift_right_usecasel   r   z*LiteralOperatorImpl.bitshift_right_usecasec                 C   s   | |L } | S r   r   r   r   r   r   bitshift_iright_usecasep   r    z+LiteralOperatorImpl.bitshift_iright_usecasec                 C   s   | |@ S r   r   r   r   r   r   bitwise_and_usecaseu   r   z'LiteralOperatorImpl.bitwise_and_usecasec                 C   s   | |M } | S r   r   r   r   r   r   bitwise_iand_usecasey   r    z(LiteralOperatorImpl.bitwise_iand_usecasec                 C   s   | |B S r   r   r   r   r   r   bitwise_or_usecase~   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   Z_unusedr   r   r   bitwise_not_usecase_binary      z.LiteralOperatorImpl.bitwise_not_usecase_binaryc                 C   r6   r   r   r   r   r   r   bitwise_not_usecase   r9   z'LiteralOperatorImpl.bitwise_not_usecasec                 C   s   |  S r   r   r   r   r   r   not_usecase   r9   zLiteralOperatorImpl.not_usecasec                 C   s   |  S r   r   r   r   r   r   negate_usecase   r9   z"LiteralOperatorImpl.negate_usecasec                 C   s   | 
 S r   r   r   r   r   r   unary_positive_usecase   r9   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   r8   r:   r;   r<   r=   r>   r?   r@   rA   rB   rC   rD   rE   rF   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   rL   r   )rM   iaddr   r   r   r   r      rO   z#FunctionalOperatorImpl.iadd_usecasec                 C   rL   r   )rM   subr   r   r   r   r!      rO   z"FunctionalOperatorImpl.sub_usecasec                 C   rL   r   )rM   isubr   r   r   r   r"      rO   z#FunctionalOperatorImpl.isub_usecasec                 C   rL   r   )rM   mulr   r   r   r   r#      rO   z"FunctionalOperatorImpl.mul_usecasec                 C   rL   r   )rM   imulr   r   r   r   r$      rO   z#FunctionalOperatorImpl.imul_usecasec                 C   rL   r   )rM   floordivr   r   r   r   r%      rO   z'FunctionalOperatorImpl.floordiv_usecasec                 C   rL   r   )rM   	ifloordivr   r   r   r   r&      rO   z(FunctionalOperatorImpl.ifloordiv_usecasec                 C   rL   r   )rM   truedivr   r   r   r   r'      rO   z&FunctionalOperatorImpl.truediv_usecasec                 C   rL   r   )rM   itruedivr   r   r   r   r(      rO   z'FunctionalOperatorImpl.itruediv_usecasec                 C   rL   r   )rM   modr   r   r   r   r)      rO   z"FunctionalOperatorImpl.mod_usecasec                 C   rL   r   )rM   imodr   r   r   r   r*      rO   z#FunctionalOperatorImpl.imod_usecasec                 C   rL   r   )rM   powr   r   r   r   r      rO   z"FunctionalOperatorImpl.pow_usecasec                 C   rL   r   )rM   ipowr   r   r   r   r+      rO   z#FunctionalOperatorImpl.ipow_usecasec                 C   rL   r   )rM   matmulr   r   r   r   r     rO   z%FunctionalOperatorImpl.matmul_usecasec                 C   rL   r   )rM   imatmulr   r   r   r   r     rO   z&FunctionalOperatorImpl.imatmul_usecasec                 C   rL   r   )rM   lshiftr   r   r   r   r,     rO   z,FunctionalOperatorImpl.bitshift_left_usecasec                 C   rL   r   )rM   ilshiftr   r   r   r   r-     rO   z-FunctionalOperatorImpl.bitshift_ileft_usecasec                 C   rL   r   )rM   rshiftr   r   r   r   r.     rO   z-FunctionalOperatorImpl.bitshift_right_usecasec                 C   rL   r   )rM   irshiftr   r   r   r   r/     rO   z.FunctionalOperatorImpl.bitshift_iright_usecasec                 C   rL   r   )rM   and_r   r   r   r   r0     rO   z*FunctionalOperatorImpl.bitwise_and_usecasec                 C   rL   r   )rM   iandr   r   r   r   r1     rO   z+FunctionalOperatorImpl.bitwise_iand_usecasec                 C   rL   r   )rM   or_r   r   r   r   r2   #  rO   z)FunctionalOperatorImpl.bitwise_or_usecasec                 C   rL   r   )rM   iorr   r   r   r   r3   '  rO   z*FunctionalOperatorImpl.bitwise_ior_usecasec                 C   rL   r   )rM   xorr   r   r   r   r4   +  rO   z*FunctionalOperatorImpl.bitwise_xor_usecasec                 C   rL   r   )rM   ixorr   r   r   r   r5   /  rO   z+FunctionalOperatorImpl.bitwise_ixor_usecasec                 C   
   t | S r   rM   invertr7   r   r   r   r8   3     
z1FunctionalOperatorImpl.bitwise_not_usecase_binaryc                 C   ri   r   rj   r   r   r   r   r:   7  rl   z*FunctionalOperatorImpl.bitwise_not_usecasec                 C   ri   r   )rM   not_r   r   r   r   r;   ;  rl   z"FunctionalOperatorImpl.not_usecasec                 C   ri   r   )rM   negr   r   r   r   r<   ?  rl   z%FunctionalOperatorImpl.negate_usecasec                 C   ri   r   )rM   posr   r   r   r   r=   C  rl   z-FunctionalOperatorImpl.unary_positive_usecasec                 C   rL   r   )rM   ltr   r   r   r   r>   G  rO   z!FunctionalOperatorImpl.lt_usecasec                 C   rL   r   )rM   ler   r   r   r   r?   K  rO   z!FunctionalOperatorImpl.le_usecasec                 C   rL   r   )rM   gtr   r   r   r   r@   O  rO   z!FunctionalOperatorImpl.gt_usecasec                 C   rL   r   )rM   ger   r   r   r   rA   S  rO   z!FunctionalOperatorImpl.ge_usecasec                 C   rL   r   )rM   eqr   r   r   r   rB   W  rO   z!FunctionalOperatorImpl.eq_usecasec                 C   rL   r   )rM   ner   r   r   r   rC   [  rO   z!FunctionalOperatorImpl.ne_usecasec                 C   s   t || S r   rM   containsr   r   r   r   rD   _  rO   z!FunctionalOperatorImpl.in_usecasec                 C   s   t ||  S r   rv   r   r   r   r   rE   c  s   z%FunctionalOperatorImpl.not_in_usecasec                 C   rL   r   )rM   is_r   r   r   r   rF   g  rO   z!FunctionalOperatorImpl.is_usecaseN),rG   rH   rI   rJ   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   r8   r:   r;   r<   r=   r>   r?   r@   rA   rB   rC   rD   rE   rF   r   r   r   r   rK      s    






































rK   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   r8   c                 C   s   |D ]I}t |||d}|j}t||D ]6\}	}
t|	}t|	}|||
}|||
}| j||d|	|
|||f d | j||d|	|
|||f d qqd S )Nflagsz-mismatch for (%r, %r) with types %s: %r != %rmsg)r   entry_point	itertoolsproductcopyassertPreciseEqualselfpyfunc
x_operands
y_operands
types_listr|   	arg_typescrcfuncr   r   Zx_gotZ
x_expectedgotexpectedr   r   r   run_test_ints  s,   



zTestOperators.run_test_intsc                 C   s   |D ]=}t |||d}|j}t||D ]*\}	}
t|	}t|	}|||
}|||
}tjj||dd tjj||dd qqd S )Nr{   gh㈵>)Zrtol)r   r   r   r   r   nptestingZ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)
hasattrZcast_python_valuer   Zunsigned_domainabsintrealZinteger_domainZreal_domainfloat)r   opZ
numba_typer   r   r   coerce_operand  s   






zTestOperators.coerce_operandTc              
   C   s   | j }| j}|s|| j }|D ]E}t|||f|d}|j}t||D ]0\}	}
| |	|}	| |
|}
||	|
}||	|
}| t	|t	| | 
||d||	|
f  q#qd S )Nr{   zmismatch with %r (%r, %r))compare_scalar_operandscompare_typescompare_unordered_typesr   r   r   r   r   assertIstypeassertEqual)r   r   r|   orderedopsr   typr   r   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 Nr{   )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   r@   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   rA   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   rB   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   rC   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   s0   t | jjtjtjf}|j}| |tt d S r   )r   r   rF   r   ellipsisr   
assertTrueEllipsis)r   cresr   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nopythonc                    s
    | |S r   r   r   Z
cfunc_voidr   r   r     rl   z-TestOperators.test_is_void_ptr.<locals>.cfunc      )r   r   Zvoidptrr   rF   r   ZassertFalse)r   r   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_floordiv4     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_complex7  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_%sZ_npmz
%s_usecasec                 S   s$   t | |}t | j|}||| d S r   )getattrr   )r   runner_nameusecase_namer|   runnerZ
op_usecaser   r   r   innerK  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_methR  s   
"z5TestOperators.generate_binop_tests.<locals>.test_methZ	important)itemsr   force_pyobj_flagsrG   r   )nsZusecasesZ
tp_runnersZ	npm_arrayZusecaseZtp_namer   r   Z	test_namer|   r   r   r   r   r   generate_binop_testsA  s*   

z"TestOperators.generate_binop_tests)rN   rP   rQ   rR   rS   rT   r   r   r   )intsfloatscomplex)rW   rX   )rU   rV   rY   rZ   r   )r   r   c              	   C   s   t | j|}tjtjtjg}|r|tj |D ]5}t|||f|d}|j	}	| 
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   r   appendr   r   r   assertRaisesZeroDivisionErrorr   assertInstr	exception)r   r   r~   r|   allow_complexr   r   tpr   r   cmr   r   r   check_div_errorsu  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   sH   | 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   r   r   test_mod_complex  s   
"zTestOperators.test_mod_complexc                 C   r   r   )r  r   r   r   r   r   test_mod_complex_npm  r   z"TestOperators.test_mod_complex_npmc                 C   sl   t |dtd}|j}td}td}|||}| |jd |r(| || d S | || | || d S )Nr   r{   r         )r   r   r   r   r   valuer   assertIsNot)r   r   inplacer   r   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   r$  )NTr%  )r#  r   r   r   r   r   r   test_imatmul!  r'  zTestOperators.test_imatmulc                 C   s~   t t jdd}t|||ftd}|j}tddg}tddg}|||}| |t|| | 	|| | 	|| d S )Nr   Cr{   r   r   r  )
r   ZArrayr   r   r   r   r   r   dotr  )r   r   Zarrtyr   r   r!  r"  r   r   r   r   check_matmul_npm$  s   
zTestOperators.check_matmul_npmc                 C   s   |  | jj d S r   )r+  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   r+  r   r   )r   raisesr   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   r           r{   r   r   r   r  r0  r1      ?   r   r   r   r   r   r   r   r   r   r   r   run_bitshift_left<  0   
zTestOperators.run_bitshift_left)Zbitshift_leftZbitshift_ileftr   r7  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       r/  r{   )r   r       r3  )r   r      )r   r   r;  r6  r   r   r   r   run_bitshift_rightb  r8  z TestOperators.run_bitshift_right)Zbitshift_rightZ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   r0  r9  r{   r:  r  r;               )listranger   r   r   r   r   r   r   r   r   r   run_logical  s0   
zTestOperators.run_logical)Zbitwise_andZbitwise_iandZ
bitwise_orZbitwise_iorZbitwise_xorZbitwise_ixorrC  r   )r   Z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|d}|j}|D ]}	| ||	||	 qd S )Nr   r0  r9  c                 S      g | ]}t |qS r   )r   r   .0r   r   r   r   
<listcomp>      z2TestOperators.test_bitwise_not.<locals>.<listcomp>r{   r=  r  r;  r>  r:  c                 S   rD  r   )r   r   rE  r   r   r   rG    rH  r?  r@  r   )r   r8   rA  rB  r   r   r   r   r   r   mapr   Zbool_r:   r   r   r   r   )
r   r|   r   r   r   r   valuesr   r   valr   r   r   test_bitwise_not  sF   zTestOperators.test_bitwise_notc                 C   r   r   )rL  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r/|nd |} |t|j	 d S )Nz'expecting TypingError when compiling {}r}   z {}zFunction({}))
formatr   r   ZTypingErrorr   r	   
isinstancer   r   r   )r   argtypesopnamer~   r-  fmtZ	expectingr   r   r   assert_reject_compile  s   
z?TestOperators.test_bitwise_float.<locals>.assert_reject_compilerz   )rQ  N)r   r   r   r   _bitwise_opnames)r   rS  methodsnamer   r   r   r   test_bitwise_float  s   z TestOperators.test_bitwise_floatc                 C   F   | j j}g d}t|dtd}|j}|D ]}| |||| qd S )Nr   r   r   333333?        333333@r   r{   )r   r;   r   r   r   r   r   r   rJ  r   r   rK  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	||g}| 
|jjtj |j}| 
|||| qd S )NrY  )r   r;   r   int8r   r   r   r   zipr   r   	signaturereturn_typer   r   r   r   ZargtysrJ  tyrK  r   r   r   r   r   test_not_npm  s   zTestOperators.test_not_npmc                 C   r   | j j}tjtjtjtjtjtjtj	tj	g}g d}t
||D ]\}}t||g}|j}| |||| qd S N)r   r   r   rZ  g333333@r[  TF)r   r<   r   r^  r   r   r   r   r   r   r_  r   r   assertAlmostEqualrb  r   r   r   test_negate_npm3      

zTestOperators.test_negate_npmc                 C   rX  N)r   r   r   rZ  r[  TFr   r{   )r   r<   r   r   r   r   r\  r   r   r   test_negateP     	zTestOperators.test_negatec                 C   re  rf  )r   r=   r   r^  r   r   r   r   r   r   r_  r   r   rg  rb  r   r   r   test_unary_positive_npm`  ri  z%TestOperators.test_unary_positive_npmc                 C   rX  rj  )r   r=   r   r   r   r   r\  r   r   r   test_unary_positive|  rl  z!TestOperators.test_unary_positivec                 C   sP   t j}t||t |df|d}|j}dD ]}d}| |||||| qd S )Nr   r{   )r   r        *   )r   rq  ro  )r   r   r   ZUniTupler   r   )r   r   r|   r   r   r   itupr   r   r   	_check_in  s   zTestOperators._check_inc                 C   r   r   )rt  r   rD   r   r   r   r   test_in  r   zTestOperators.test_inc                 C   r   r   )ru  r   r   r   r   r   test_in_npm  r   zTestOperators.test_in_npmc                 C   r   r   )rt  r   rE   r   r   r   r   test_not_in  r   zTestOperators.test_not_inc                 C   r   r   )rw  r   r   r   r   r   test_not_in_npm  r   zTestOperators.test_not_in_npmN)F)drG   rH   rI   __doc__r   r   rM   r_   r`   ra   rb   rc   rd   re   rf   rg   rh   rk   rT  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  r  r  r#  r&  r(  r   r+  r,  r.  r7  r<  rC  rL  rM  rW  r]  rd  rh  rk  rm  rn  rt  ru  rv  rw  rx  r   r   r   r   ry   l  s   


	




!!!0"	ry   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 )TestOperatorModulerz   N)rG   rH   rI   rK   r   rM   r_   r`   ra   rb   rc   rd   re   rf   rg   rh   rk   rT  r   r   r   r   r{    s    
r{  c                   @   sP  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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-d. Z'd/d0 Z(d1d2 Z)d3d4 Z*d5d6 Z+d7d8 Z,d9d: Z-d;S )<TestMixedIntsz<
    Tests for operator calls with mixed integer types.
    )r   r   r   
   rq     i'  r   r   iiiic                 C   s   g | ]}|j r|qS r   signedrF  r   r   r   r   rG    rH  zTestMixedInts.<listcomp>c                 C   s   g | ]}|j s|qS r   r  r  r   r   r   rG    rH  c                 C   s$   g | ]\}}|j s|j r||fqS r   r  rF  uvr   r   r   rG    
    c                 C   s$   g | ]\}}|j s|j s||fqS r   r  r  r   r   r   rG    r  c                 G   .   t dd |D }t |tjj}ttd| S )Nc                 s       | ]	}|j jd  V  qdS r0  Nr   itemsizerF  r  r   r   r   	<genexpr>      z8TestMixedInts.get_numpy_signed_upcast.<locals>.<genexpr>zint%dmaxr   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   rV  )r   r   rK  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   rM   )r   rQ  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   rQ  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 ]U\}}	t |||	ftd}
|
j}t||D ]>\}}| ||}| |	|}|||}|||}| || d||||	ff }||||}}| j||fd|i| qqd S )Nr{   #mismatch for (%r, %r) with types %sr~   )r   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   r   
run_binary  s$   

zTestMixedInts.run_binaryc              
   C   sr   |D ]4}t ||ftd}|j}|D ]$}	| ||	}	||	}
||	}| || | j||
d|	|||
f d qqd S )Nr{   z&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   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   rQ  samplesr  r  r  r   r   r   run_arith_binop  s   
zTestMixedInts.run_arith_binopc                 C      |  | jjd| j d S )NrN   )r  r   r   int_samplesr   r   r   r   test_add  r   zTestMixedInts.test_addc                 C   r  )NrQ   )r  r   r!   r  r   r   r   r   test_sub  r   zTestMixedInts.test_subc                 C   r  )NrS   )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   rE  r   r   r   rG        z/TestMixedInts.test_floordiv.<locals>.<listcomp>rU   )r  r  r   r%   r   r  r   r   r   test_floordiv     zTestMixedInts.test_floordivc                 C   r  )Nc                 S   r  r  r   rE  r   r   r   rG    r  z*TestMixedInts.test_mod.<locals>.<listcomp>rY   )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 )
N)r      r  c                 S   s   g | ]}|d kr|qS r  r   rE  r   r   r   rG  (  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   rE  r   r   r   rG  6  r  c                 S   s$   g | ]\}}|j r|j r||fqS r   r  r  r   r   r   rG  7  r  )	r   Z	PYVERSIONr   r   r   r  r  
type_pairsr  )r   Z
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   rE  r   r   r   rG  @  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  )Nrc   )r  r   r0   r  r   r   r   r   test_andK  r   zTestMixedInts.test_andc                 C   r  )Nre   )r  r   r2   r  r   r   r   r   test_orN  r   zTestMixedInts.test_orc                 C   r  )Nrg   )r  r   r4   r  r   r   r   r   test_xorQ  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  V  r  z5TestMixedInts.run_shift_binop.<locals>.control_signedc                    r  r   r  r  r  r   r   r  Y  r  z7TestMixedInts.run_shift_binop.<locals>.control_unsignedc                    s   t  | |ftd}|j}D ];}| jd }dddd|d |fD ])}| |}||}|||}|||}	d||| |ff }
j|	||
d qqd S )Nr{   r   r   r   ro  r  r}   )r   r   r   r  r  r   )r  r  r  r   r   r   Z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   rG  r      z1TestMixedInts.run_shift_binop.<locals>.<listcomp>c                 S   s   g | ]\}}|j s||fqS r   r  r  r   r   r   rG  t  r  )r   rM   r  r  )
r   r   rQ  r  r  r  r  r  r  r  r   )r  r   r  r   r   run_shift_binopT  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  )Nra   )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   rn    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).rG   rH   rI   ry  r   r   r  r   r^  Zuint8r   r   r  r  r  rA  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  rn  r  r  r   r   r   r   r|    sJ    


(r|  c                   @   s   e Zd ZeZdS )TestMixedIntsOperatorModuleN)rG   rH   rI   rK   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   	exponentsrJ  r   Zregular_funcZstatic_funcZstatic_cfuncZ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   ro     r   r   r	  r   r   r   r   r   r=  r   r  )r   r^  Z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   ro  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)rG   rH   rI   ry  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 NZtest1r  r   r  r   r   r   
test_impl2  r  z5TestStringConstComparison.test_eq.<locals>.test_impl2Tr   r   r   r   r  r  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   r    r  z6TestStringConstComparison.test_neq.<locals>.test_impl1c                  S   s   d} | dkS r  r   r  r   r   r   r    r  z6TestStringConstComparison.test_neq.<locals>.test_impl2Tr   r  r  r   r   r   test_neq  r   z"TestStringConstComparison.test_neqN)rG   rH   rI   ry  r  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   r    r   z7TestBooleanLiteralOperators.test_eq.<locals>.test_impl1c                    s   |  kS r   r   r  b_valr   r   r    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r2Zr3Zr4r   r   r   
test_impl3  
   z7TestBooleanLiteralOperators.test_eq.<locals>.test_impl3TFr   repeatr   r   r   r   r   	r   r  r  r  r"  r  r!  r  Zcfunc3r   r  r  r   r       z#TestBooleanLiteralOperators.test_eqc           	         r  )Nc                    s    | kS r   r   r  r  r   r   r    r   z7TestBooleanLiteralOperators.test_ne.<locals>.test_impl1c                    s   |  kS r   r   r  r  r   r   r    r   z7TestBooleanLiteralOperators.test_ne.<locals>.test_impl2c                  S   s,   ddk} ddk}ddk}ddk}| |||fS r	  r   r
  r   r   r   r    r  z7TestBooleanLiteralOperators.test_ne.<locals>.test_impl3TFr   r  r   r  r  r   r  r   test_ne  r  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   r  (  r   z7TestBooleanLiteralOperators.test_is.<locals>.test_impl1c                  S   s,   ddu } ddu }ddu }ddu }| |||fS r	  r   r
  r   r   r   r  +  r  z7TestBooleanLiteralOperators.test_is.<locals>.test_impl2TFr   r  r   r  )r   r  r  r"  r  r  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   r  r   r  r   r   r   r   r]  9     z$TestBooleanLiteralOperators.test_notc                 C   r  )Nc                  S      d\} }t | t |fS r  )boolr  r   r   r   r  D     z8TestBooleanLiteralOperators.test_bool.<locals>.test_implTr   r  r  r   r   r   	test_boolB  r  z%TestBooleanLiteralOperators.test_boolc                 C   r  )Nc                  S   r  r  )r   r  r   r   r   r  M  r  z?TestBooleanLiteralOperators.test_bool_to_str.<locals>.test_implTr   r  r  r   r   r   test_bool_to_strK  r  z,TestBooleanLiteralOperators.test_bool_to_strN)
rG   rH   rI   ry  r  r  r  r]  r  r   r   r   r   r   r    s    		r  __main__),r   r   rM   syswarningsnumpyr   ZunittestZnumba.core.compilerr   r   Znumbar   Z
numba.corer   r   r   r   Znumba.core.types.functionsr	   Znumba.tests.supportr
   r   r   Znumba.tests.matmul_usecaser   r   r   r   r   Zforce_pyobjectr   objectr   rK   ry   r{  r|  r  r  r  r  rG   mainr   r   r   r   <module>   sL     , $      < q$ g