
    xKg;^                     b   d dl Z d dlm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mZmZm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mZmZmZm Z m!Z!m"Z" d dl#Z#d dl$Z$d dl%Z% G d
 de&      Z'd Z(d Z)d Z*d Z+d Z, ee(      Z-d Z.d Z/d Z0d Z1d Z2d Z3d Z4 G d de      Z5 G d dee      Z6 G d dee      Z7 G d dee%j0                        Z8 G d  d!ee%j0                        Z9 G d" d#ee%j0                        Z: G d$ d%ee%j0                        Z;e<d&k(  r e%jz                          yy)'    N)StringIO)njit	vectorize)typeof)utilstypestypingircompilercpucgutils)CompilerFlags)
cpu_target)MemoryLeakMixinTestCasetemp_directorycreate_temp_module)overloadmodelslower_builtinregister_modelmake_attribute_wrappertype_callabletypeof_implc                        e Zd Z fdZ xZS )	Namespacec                 <    || v r| |   S t         t        |   |      S N)superr   __getattr__)sk	__class__s     `/home/alanp/www/video.onchill/myenv/lib/python3.12/site-packages/numba/tests/test_array_exprs.pyr!   zNamespace.__getattr__   s$    AvqtE5A#B1#EE    )__name__
__module____qualname__r!   __classcell__)r$   s   @r%   r   r      s    F Fr&   r   c                     | |z  |z   S r    axys      r%   axyr1           q519r&   c                     | |z  |z   S r   r,   r-   s      r%   ax2r4   #   r2   r&   c                 8    | |dz  d| z  |z  z
  dz  z   d| z  z  S )N       @g      @      ?r,   AsBsCss      r%   pos_rootr<   &   s.    CR2X"r'B,/C78R"WEEr&   c                 D    d| z  }d|z  |z  }|dz  |z
  }| |dz  z
  |z  S )Nr6   r7   r,   r9   r:   r;   _2As_4AsCs
_Bs2_4AsCss         r%   neg_root_common_subexprrB   )   s=    7D$Y^F(V#JC:$%--r&   c                 J    d| z  }d|z  |z  }|dz  |z
  dz   }| |dz  z
  |z  S )Nr6   y                r7   r,   r>   s         r%   neg_root_complex_subexprrD   /   sB    7D$Y^F(V#r)JC:$%--r&   c                 n    t        j                  t        | t        j                  |      dz
  d            S )N      ?)npcosvaxysin)a0a1s     r%   
call_stuffrM   7   s&    66$r266":?B/00r&   c                 $    |dz  d| z  |z  z
  dk  S )N      r   r,   r8   s      r%   are_roots_imaginaryrQ   :   s    !Ga"frk!Q&&r&   c                     | |z  |z   S r   r,   r8   s      r%   div_addrS   =   s    7R<r&   c                     | dz  S )N   r,   )r9   s    r%   cuberV   @   s    7Nr&   c                 \    t        j                  | |       t        j                  |||      S r   )rG   rH   add)r.   bouts      r%   explicit_outputr[   C   s"    FF1cN66#q#r&   c                 0    | |z   }|| |z  z
  }||z  |z   }|S r   r,   )r.   rY   cdus        r%   variable_name_reuser`   G   s*    	AA	AE	A	A	AHr&   c                    | j                   d   }t        j                  ||ft        j                        }t	        |      D ]C  }t	        ||      D ]2  }t        j
                  | |   | |   z
  dz        dz  x|||f<   |||f<   4 E |S )Nr   dtyperO   r7   )shaperG   emptyfloat64rangesum)vectors	n_vectorsresultijs        r%   distance_matrixrn   O   s    a IXXy),BJJ?F9q)$A(*gaj(Q.)036)7 7F1Q3K&1+ % 
 Mr&   c                   D    e Zd Zeddi dddfd       Zeddi dfd       Zy)RewritesTesterNc           	          |s
t               }d|_        |t        j                  }|t        j                  } | |||||||      S NT)r   nrtr   typing_contexttarget_context)clsargsreturn_typeflagslocalslibraryrt   ru   s           r%   mk_pipelinezRewritesTester.mk_pipeline\   sS     GE	!'66N!'66N>>7D+&" 	"r&   c                 V    |s
t               }d|_         | j                  |||||fi |S rr   )r   no_rewritesr|   )rv   rw   rx   ry   rz   r{   kwss          r%   mk_no_rw_pipelinez RewritesTester.mk_no_rw_pipelinei   s4     GE st[%PCPPr&   )r'   r(   r)   classmethodr|   r   r,   r&   r%   rp   rp   [   sB    +/tB d
" 
" 15T""&Q Qr&   rp   c                       e Zd Zd Zd Zd ZddZefdZe	fdZ
d Zd	 Zdd
Zd Zd Zd ZefdZd Zd Zd Zd Zy)TestArrayExpressionsc                     t         j                  |      }|j                  |      }|j                  }t         j	                  |      }|j                  |      }|j                  }||||fS )zT
        Compile the given function both without and with rewrites enabled.
        )rp   r   compile_extraentry_pointr|   )	selffnarg_tyscontrol_pipelinecres_0control_cfunctest_pipelinecres_1
test_cfuncs	            r%   _compile_functionz&TestArrayExpressions._compile_functiont   sj     *;;GD!//3**&227;,,R0''
zIIr&   c                 t   t        j                  ddd      }t        j                  ddd      }t        j                  ddd      }|||fD cg c]  }t        |       }}| j                  t        |      \  }}}}	t
        j                  |      }
|
j                  t              }|j                  } ||||      } |	|||      } ||||      }t         j                  j                  ||       t         j                  j                  ||       |j                  j                  j                  }|j                  j                  j                  }|
j                  j                  j                  }| j                  t!        |      t!        |             | j                  t!        |      t!        |             | j#                  t!        |d   j$                        t!        |d   j$                               | j                  t!        |d   j$                        t!        |d   j$                               yc c}w )zv
        Using a simple array expression, verify that rewriting is taking
        place, and is fusing loops.
        r      
   rO   N)rG   linspacer   r   r1   rp   r   r   r4   r   testingassert_array_equalstatefunc_irblocksassertEquallenassertGreaterbody)r   AXYargr   r   nb_axy_0r   nb_axy_1control_pipeline2cres_2nb_ctlexpectedactualcontrolir0ir1ir2s                      r%   test_simple_exprz%TestArrayExpressions.test_simple_expr   s   
 KK!BKK!BKK!B+,a)4)36#;)4 ""30 	<(M8 +<<WE"005##Aq!$!Q"Aq/


%%h7


%%gv6$$,,33!!))00%%--44S3s8,S3s8,3s1v{{+SQ-=>SV[[)3s1v{{+;<- 5s   H5c              #      K   |D ]`  }t        |t        j                        st        |j                  t        j                        sC|j                  j
                  dk(  s]| b y w)N	arrayexpr)
isinstancer
   AssignvalueExprop)r   blockinstrs      r%   _get_array_exprsz%TestArrayExpressions._get_array_exprs   sE     E%+ekk2773{{~~4#	 s    A)$A)A)"A)Nc                 :   |
t               }t        |t              st        dj	                  |            |\  }}g }|D ]8  }t        |t              r| j                  ||      \  }}|j                  |       : |t        |      f}|j                  |       ||fS )zK
        Convert an array expression tree into a set of operators.
        z{0} not a tuple)setr   tuple
ValueErrorformat_array_expr_to_setappendrX   )	r   exprrZ   	operationoperandsprocessed_operandsoperand_processed_exprs	            r%   r   z'TestArrayExpressions._array_expr_to_set   s     ;%C$&.55d;<<"	8G'5)!44WcB
%%g.   #E*<$==s""r&   c                    t         j                  j                  d      }t         j                  j                  d      dz   }t         j                  j                  d      }|||fD cg c]  }t        |       }}t        j	                  |      }|j                  |      }|j                  }	t        j                  |      }
|
j                  |      }|j                  } ||||      } |	|||      } ||||      }t         j                  j                  ||       t         j                  j                  ||       t        t                     S c c}w )Nr   rF   )rG   randomr   rp   r   r   r   r|   r   assert_array_almost_equalr   rz   )r   r   r   BCr   r   r   control_cresnb_fn_0r   	test_cresnb_fn_1	np_resultnb_result_0nb_result_1s                   r%   _test_root_functionz(TestArrayExpressions._test_root_function   s   IIR IIR 2% IIR +,a)4)36#;)4);;GD'55b9**&227;!//3	''q!QK	aA&aA&


,,YD


,,[+F""! 5s   (Ec                    t        j                  dt         j                        }t        |      f}t        j                  |      }|j                  |      }|j                  }t        j                  |      }|j                  |      }|j                  }	|dz  }
| j                  |
 ||             | j                  |
 |	|             t        t                     S )Nr   rb   rU   )rG   arangerf   r   rp   r   r   r   r|   assertPreciseEqualr   rz   )r   r   r   r   r   r   r   r   r   r   r   s              r%   _test_cube_functionz(TestArrayExpressions._test_cube_function   s    IIb

+!9,);;GD'55b9**&227;!//3	''6'!*5'!*5""r&   c                 H  	
 t        j                  dt         j                        		dz   
t        	      fdz  }| j	                  ||      \  }}}}	
fd} ||      }| j                  | ||             | j                  | ||             t        t                     S )z
        Test function having a (a, b, out) signature where *out* is
        an output array the function writes into.
        r   rb   r   rU   c                 F    t        j                        } | |       |S r   )rG   
zeros_like)r   rZ   r   r   s     r%   run_funczETestArrayExpressions._test_explicit_output_function.<locals>.run_func   s!    --"Cq!SMJr&   )rG   r   rf   r   r   r   r   rz   )r   r   r   r   r   r   r   r   r   r   r   s            @@r%   _test_explicit_output_functionz3TestArrayExpressions._test_explicit_output_function   s    
 IIb

+E!9," ""2w/ 	C-
	
 B<(=*AB(:*>?""r&   c                 n    t        t        | j                  |                  }| j                  ||       y)z`
        Assert the *block* has the expected number of array expressions
        in it.
        N)r   listr   r   )r   r   expected_countrewrite_counts       r%   _assert_array_exprsz(TestArrayExpressions._assert_array_exprs   s.    
 D!6!6u!=>?7r&   c                    | j                  t        |      t        |             |d   j                  }|d   j                  }| j                  |d       | j                  |d       |s%| j	                  t        |      t        |             yy)z
        Given two dictionaries of Numba IR blocks, check to make sure the
        control IR has no array expressions, while the test IR
        contains one and only one.
        r   r   N)r   r   r   r   r   )r   
control_irtest_irtrivialcontrol_block
test_blocks         r%   _assert_total_rewritez*TestArrayExpressions._assert_total_rewrite  s{     	Z#g,7"1**QZ__
  2  Q/ s=13z?C	 r&   c                 B   | j                  t        |      t        |             |j                         D ]h  \  }}|j                  }||   j                  }| j                  t        |      t        |             | j	                  |d       | j	                  |d       j y)z
        Given two dictionaries of Numba IR blocks, check to make sure
        the control IR and the test IR both have no array expressions.
        r   N)r   r   itemsr   r   )r   r   r   r#   vr   r   s          r%   _assert_no_rewritez'TestArrayExpressions._assert_no_rewrite  s    
 	Z#g,7$$&DAqFFM JS/ZA$$]A6$$Z3 'r&   c                     | j                         }| j                  |j                  j                  j                  j
                  |j                  j                  j                  j
                  d       y)z
        Ensure even a non-nested expression is rewritten, as it can enable
        scalar optimizations such as rewriting `x ** 2`.
        T)r   N)r   r   r   r   r   r   r   r   nss     r%   test_trivial_exprz&TestArrayExpressions.test_trivial_expr$  s]    
 %%'""2#6#6#<#<#D#D#K#K#%#3#3#9#9#A#A#H#H+/ 	# 	1r&   c                     | j                         }| j                  |j                  j                  j                  j
                  |j                  j                  j                  j
                         y)z
        Using the polynomial root function, ensure the full expression is
        being put in the same kernel with no remnants of intermediate
        array expressions.
        N)r   r   r   r   r   r   r   r   s     r%   test_complicated_exprz*TestArrayExpressions.test_complicated_expr.  sV     %%'""2#6#6#<#<#D#D#K#K#%#3#3#9#9#A#A#H#H	Jr&   c           
      \     j                  |      }|j                  j                  j                  j                  }|j
                  j                  j                  j                  } j                  t        |      t        |              j                  t        |d   j                        t        |d   j                                j                  t        t         j                  |d   j                                    d       t         j                  |d   j                              } j                  t        |      d       t         fd|D              }t        |dd |dd       D ]9  \  }}|j                  |      }	|	s j                  dj                  |	             ; y)zp
        Attempt to verify that rewriting will incorporate user common
        subexpressions properly.
        r   r   c              3   n   K   | ],  }j                  |j                  j                        d     . yw)r   N)r   r   r   ).0r   r   s     r%   	<genexpr>zBTestArrayExpressions.test_common_subexpressions.<locals>.<genexpr>K  s3      :'8e 11%++2B2BCAF'8s   25Nz9Common subexpressions detected in array expressions ({0}))r   r   r   r   r   r   r   r   r   r   r   r   zipintersectionfailr   )
r   r   r   r   r   array_expr_instrs
array_sets
expr_set_0
expr_set_1intersectionss
   `         r%   test_common_subexpressionsz/TestArrayExpressions.test_common_subexpressions8  s_   
 %%b)!!''//66$$,,33S3s8,3s1v{{+SQ-=>T$"7"7A"DEFJ
 !!6!6s1v{{!CD30115  :'8: :
&)*Sb/:ab>&J"J
&33J?M		 ..4f].CE 'Kr&   c                 ,    | j                  t              S r   )r   rD   )r   s    r%   test_complex_subexpressionz/TestArrayExpressions.test_complex_subexpressionS  s    ../GHHr&   c                 ~   t         j                  j                  d      }t         j                  j                  d      }||fD cg c]  }t        |       }}t        j                  j
                  }t        j                  ||j                  |j                        }|j                  t              }|j                  }t        j                  ||j                  |j                        }	|	j                  t              }
|
j                  }t        ||      } |||      } |||      }t         j                  j                  ||       t         j                  j                  ||       | j!                  |j"                  j$                  j&                  |	j"                  j$                  j&                         yc c}w )zn
        Verify that ufunc and DUFunc calls are being properly included in
        array expressions.
        r   )rt   ru   N)rG   r   r   rI   _dispatchertargetdescrrp   r   rt   ru   r   rM   r   r|   r   r   r   r   r   r   )r   r   r   r   r   
vaxy_descrr   r   nb_call_stuff_0r   r   nb_call_stuff_1r   r   r   s                  r%   test_ufunc_and_dufunc_callsz0TestArrayExpressions.test_ufunc_and_dufunc_callsV  sr   
 IIR IIR +,a&1&36#;&1%%11
);;%44%44 < 6 "//
; ,,&22%44%44 3 6 ,,Z8 ,,a#!!Q' A&


,,Xw?


,,Xv>""#3#9#9#A#A#H#H#0#6#6#>#>#E#E	G/ 2s   F:c                     | j                  t              }| j                  |j                  j                  j
                  j                  |j                  j                  j
                  j                         y)zQ
        Verify that comparison operators are supported by the rewriter.
        N)r   rQ   r   r   r   r   r   r   r   s     r%   test_cmp_opz TestArrayExpressions.test_cmp_opw  sY     %%&9:""2#6#6#<#<#D#D#K#K#%#3#3#9#9#A#A#H#H	Jr&   c                     | j                  t              }| j                  |j                  j                  j
                  j                  |j                  j                  j
                  j                         y)zQ
        Check that ufunc calls with explicit outputs are not rewritten.
        N)r   r[   r   r   r   r   r   r   r   s     r%   test_explicit_outputz)TestArrayExpressions.test_explicit_output  sX     00A 3 3 9 9 A A H H " 0 0 6 6 > > E E	Gr&   r   )F)r'   r(   r)   r   r   r   r   r<   r   rV   r   r   r   r   r   r   r   rB   r   r  r  r
  r  r,   r&   r%   r   r   r   sq    J=@$#$ &. #0 &* #$#.8D$41J -D E6IGBJGr&   r   c                   6    e Zd Zd Zd Zd Zd Zd Zd Zd Z	y)	TestRewriteIssuesc                     ddl m} dd l} |d      d         |d      fd       } |j                  d      } ||      \  }}| j	                  ||       | j	                  ||       y )Nr   )jitT)nopythonc                     | S r   r,   )arrs    r%   fooz.TestRewriteIssues.test_issue_1184.<locals>.foo  s    Jr&   c                 ,     |       } |       }||fS r   r,   )r  r]   r^   r  s      r%   barz.TestRewriteIssues.test_issue_1184.<locals>.bar  s    CACAa4Kr&   r   )numbar  numpyr   assertIs)r   r  rG   r  r  out_cout_dr  s          @r%   test_issue_1184z!TestRewriteIssues.test_issue_1184  ss    	d		 
	 
d		 
	
 biim3xueU#eS!r&   c                    d}t         j                  j                  |dz        j                  |df      }t	        |      } t        t              |      }t         j                  j                  ||       t        j                          y )Nd   rU   )size)
rG   r   uniformreshapern   r   r   r   gccollect)r   nr/   r   r   s        r%   test_issue_1264z!TestRewriteIssues.test_issue_1264  si    II1Q3'//16"1%&o&q)


,,Xv>


r&   c                    ddl m} |d        }t        j                  j	                  d      }t        j                  j	                  d      }|j                  ||      } |||      }t        j                  j                  ||       y)z*Test array expression with duplicated termr   )r   c                 <    t        j                  |      }||z   | z   S r   )rG   rJ   r.   rY   s     r%   r  z.TestRewriteIssues.test_issue_1372.<locals>.foo  s    q	Aq519r&   r   N)r  r   rG   r   r   py_funcr   assert_allclose)r   r   r  r.   rY   expectgots          r%   test_issue_1372z!TestRewriteIssues.test_issue_1372  sp    		 
	 IIb!IIb!Q"!Qi


""3/r&   c                     t         d        }d}t        j                  dt        j                        }|j	                  ||      } |||      }| j                  ||       y)zP
        Typing of unary array expression (np.negate) can be incorrect.
        c                     || z
  |  z   S r   r,   r(  s     r%   r  z3TestRewriteIssues.test_unary_arrayexpr.<locals>.foo  s    q5A2:r&   g      ?r   rb   N)r   rG   r   int32r)  r   )r   r  rY   r.   r+  r,  s         r%   test_unary_arrayexprz&TestRewriteIssues.test_unary_arrayexpr  s\     
	 
	 IIb)Q"!QiV,r&   c                     t         d        }t        j                  g d      }t        j                  g d      }|j                  ||      } |||      }| j	                  ||       y)zd
        Typing of bitwise boolean array expression can be incorrect
        (issue #1813).
        c                     | | z   S r   r,   r(  s     r%   r  z5TestRewriteIssues.test_bitwise_arrayexpr.<locals>.foo  s    1"X;r&   )TTFF)FTFTN)r   rG   arrayr)  r   )r   r  r.   rY   r+  r,  s         r%   test_bitwise_arrayexprz(TestRewriteIssues.test_bitwise_arrayexpr  sa    
 
	 
	 HH/0HH/0Q"!QiV,r&   c                    t        t              }t        j                  ddd      } |||||       t	               }|j                  |       |j                         }| j                  d|       | j                  d|       y)zo
        Type annotation of array expressions with disambiguated
        variable names (issue #1466).
        r   r   r   z
#   u.1 = z
#   u.2 = N)r   r`   rG   r   r   inspect_typesgetvalueassertIn)r   cfuncr.   bufress        r%   test_annotationsz"TestRewriteIssues.test_annotations  sk    
 ()KK1b!aAqjC llnlC(lC(r&   c                     t         d        } |d      }|j                  d      }t        j                  j	                  ||       y )Nc                 z    t        j                  |       }t        d      D ]  }||z  }|j                         } |S )NrO   )rG   onesrg   copy)r/   r  r   vals       r%   fz;TestRewriteIssues.test_issue_5599_name_collision.<locals>.f  s8    ''!*C1XSyhhj  Jr&      )r   r)  rG   r   r   )r   rC  r,  r+  s       r%   test_issue_5599_name_collisionz0TestRewriteIssues.test_issue_5599_name_collision  s@    		 
	 d1


%%c62r&   N)
r'   r(   r)   r  r%  r-  r1  r5  r=  rE  r,   r&   r%   r  r    s%    "&0-- ) 3r&   r  c                       e Zd Zd Zy)TestSemanticsc                 (   t         }t        |      }t        j                  ddt	        d      g      }t        j                  g d      }t        j
                  |      } ||||      } ||||      }t        j                  j                  ||       y )N        rF   inf)rI  rI  rF   )rS   r   rG   rf   float	ones_liker   r   )r   pyfuncr:  r.   rY   r]   r+  r,  s           r%   test_division_by_zeroz#TestSemantics.test_division_by_zero  st     VJJS%,/0JJ'LLO1aAq!n


%%fc2r&   N)r'   r(   r)   rN  r,   r&   r%   rG  rG    s    3r&   rG  c                       e Zd ZdZd Zd Zy)TestOptionalsze Tests the arrival and correct lowering of Optional types at a arrayexpr
    derived ufunc, see #3972c                    t         d        t         fd       }t        j                  d      df} || } |j                  | }t        j                  j                  ||       j                  }|d   d   }| j                  t        |t        j                               | j                  t        |j                  t        j                               y )Nc                     | |z   S r   r,   r/   r0   s     r%   arr_exprz9TestOptionals.test_optional_scalar_type.<locals>.arr_expr      q5Lr&   c                 *    |dkD  rd }n|} | |      S Nr   r,   r/   r0   zrT  s      r%   do_callz8TestOptionals.test_optional_scalar_type.<locals>.do_call       1uAq>!r&   rD  g333333r   r   )r   rG   r   r)  r   r*  
signatures
assertTruer   r   OptionaltypeFloatr   rZ  rw   r<  r   r"   otyrT  s          @r%   test_optional_scalar_typez'TestOptionals.test_optional_scalar_type	  s    		 
	 
	" 
	" 		!d# tn"7??D)


""31 d1g
378
388U[[9:r&   c                 P   t         d        t         fd       }t        j                  d      t        j                  d      f} || } |j                  | }t        j                  j                  ||       j                  }|d   d   }| j                  t        |t        j                               | j                  t        |j                  t        j                               | j                  t        |j                  j                  t        j                               y )Nc                     | |z   S r   r,   rS  s     r%   rT  z8TestOptionals.test_optional_array_type.<locals>.arr_expr&  rU  r&   c                 0    |d   dkD  rd }n|} | |      S rW  r,   rX  s      r%   rZ  z7TestOptionals.test_optional_array_type.<locals>.do_call*  $    taxAq>!r&   rD        @r   r   )r   rG   r   r)  r   r*  r\  r]  r   r   r^  r_  Arrayrc   r`  ra  s          @r%   test_optional_array_typez&TestOptionals.test_optional_array_type$  s    		 
	 
	" 
	" 		!biim, tn"7??D)


""31 d1g
378
388U[[9:
388>>5;;?@r&   N)r'   r(   r)   __doc__rc  rj  r,   r&   r%   rP  rP    s     ;6Ar&   rP  c                       e Zd Zd Zd Zy)TestOptionalsExceptionsc                    | j                          t        d        t        fd       }t        j                  d      df}| j	                  t
              5 } ||  d d d        | j                  dt        j                               j                  }|d   d   }| j                  t        |t        j                               | j                  t        |j                  t        j                               y # 1 sw Y   xY w)Nc                     | |z   S r   r,   rS  s     r%   rT  zUTestOptionalsExceptions.test_optional_scalar_type_exception_on_none.<locals>.arr_exprH  rU  r&   c                 *    |dkD  rd }n|} | |      S rW  r,   rX  s      r%   rZ  zTTestOptionalsExceptions.test_optional_scalar_type_exception_on_none.<locals>.do_callL  r[  r&   rD  rF   zexpected float64, got Noner   r   )disable_leak_checkr   rG   r   assertRaises	TypeErrorr9  str	exceptionr\  r]  r   r   r^  r_  r`  )r   rZ  rw   raisesr"   rb  rT  s         @r%   +test_optional_scalar_type_exception_on_nonezCTestOptionalsExceptions.test_optional_scalar_type_exception_on_noneD  s    !		 
	 
	" 
	" 		!c" y)VTN * 	2C8H8H4IJ d1g
378
388U[[9: *)s   C<<Dc                    | j                          t        d        t        fd       }t        j                  d      t        j                  dd      f}| j	                  t
              5 } ||  d d d        t        j                        }| j                  d|       | j                  d|       j                  }|d   d	   }| j                  t        |t        j                               | j                  t        |j                  t        j                               | j                  t        |j                  j                   t        j"                               y # 1 sw Y   xY w)
Nc                     | |z   S r   r,   rS  s     r%   rT  zTTestOptionalsExceptions.test_optional_array_type_exception_on_none.<locals>.arr_exprf  rU  r&   c                 0    |d   dkD  rd }n|} | |      S rW  r,   rX  s      r%   rZ  zSTestOptionalsExceptions.test_optional_array_type_exception_on_none.<locals>.do_callj  rg  r&   rD  rF   rh  zexpected array(float64,zgot Noner   r   )rq  r   rG   r   rr  rs  rt  ru  r9  r\  r]  r   r   r^  r_  ri  rc   r`  )r   rZ  rw   rv  excstrr"   rb  rT  s          @r%   *test_optional_array_type_exception_on_nonezBTestOptionalsExceptions.test_optional_array_type_exception_on_noneb  s   !		 
	 
	" 
	" 		!biiB/0 y)VTN * V%%&/8j&) d1g
378
388U[[9:
388>>5;;?@ *)s   ,E!!E*N)r'   r(   r)   rw  r|  r,   r&   r%   rm  rm  A  s    ;<Ar&   rm  c                   @    e Zd ZdZ ej
                  d      Zd Zd Zy)TestExternalTypeszJ Tests RewriteArrayExprs with external (user defined) types,
    see #5157z
        from numba.core import types

        class FooType(types.Type):
            def __init__(self):
                super(FooType, self).__init__(name='Foo')
        c                 2    G d dt               }t               G d dt        j                               }t	        dd       t        |      fd       }t        |t        j                        d        }t        j                  |      fd       }|fS )	Nc                       e Zd Zd Zy),TestExternalTypes.make_foo_type.<locals>.Fooc                     || _         y r   )r   )r   r   s     r%   __init__z5TestExternalTypes.make_foo_type.<locals>.Foo.__init__  s	    "
r&   Nr'   r(   r)   r  r,   r&   r%   Foor    s    #r&   r  c                       e Zd Zd Zy)1TestExternalTypes.make_foo_type.<locals>.FooModelc                 n    dt         j                  fg}t        j                  j	                  | |||       y )Nr   )r   intpr   StructModelr  )r   dmmfe_typememberss       r%   r  z:TestExternalTypes.make_foo_type.<locals>.FooModel.__init__  s-    #UZZ01""++D#wHr&   Nr  r,   r&   r%   FooModelr    s    Ir&   r  r   c                     fd}|S )Nc                             S r   r,   )r   FooTypes    r%   typerz@TestExternalTypes.make_foo_type.<locals>.type_foo.<locals>.typer  s    y r&   r,   )contextr  r  s     r%   type_fooz1TestExternalTypes.make_foo_type.<locals>.type_foo  s    ! Lr&   c                     |j                   }|\  } t        j                  |      | |      }||_        |j	                         S r   )rx   r   create_struct_proxyr   	_getvalue)r  buildersigrw   typr   r  s          r%   impl_fooz1TestExternalTypes.make_foo_type.<locals>.impl_foo  s>    //CGU2'--c27GDCCI==?"r&   c                             S r   r,   )rB  r]   r  s     r%   
typeof_fooz3TestExternalTypes.make_foo_type.<locals>.typeof_foo  s    9r&   )objectr   r   r  r   r   r   r   r  r   register)r   r  r  r  r  r  r  s    `     r%   make_foo_typezTestExternalTypes.make_foo_type  s    	#& 	# 
	 	Iv)) 	I 
!	I
 	w9	s		 
	 
sEJJ	'	# 
(	# 
		c	"	 
#	 G|r&   c                    t        | j                        5 }| j                  |j                        \  t	        t
        j                        fd       }t	        t
        j                        fd       }t	        t
        j                        fd       }t        fd       }t        fd       }t        fd       }t        j                  j                   |dd      t        j                  ddg             t        j                  j                   |d	d
      t        j                  d	d
g             t        j                  j                   |d      t        j                  dg             d d d        y # 1 sw Y   y xY w)Nc                 ^    t        |       r t        |t        j                        rd }|S y y )Nc                 J    t        j                  | j                  |d   g      S rW  rG   r4  r   lhsrhss     r%   impzKTestExternalTypes.test_external_type.<locals>.overload_foo_add.<locals>.imp  s    !xxCF(;<<r&   )r   r   ri  r  r  r  r  s      r%   overload_foo_addz>TestExternalTypes.test_external_type.<locals>.overload_foo_add  s/    c7+
30L= J	 1M+r&   c                 B    t        |       rt        |      rd }|S y y )Nc                 X    t        j                  | j                  |j                  g      S r   r  r  s     r%   r  zKTestExternalTypes.test_external_type.<locals>.overload_foo_add.<locals>.imp  s    !xxCII(>??r&   r   r  s      r%   r  z>TestExternalTypes.test_external_type.<locals>.overload_foo_add  s,    c7+
30H@ J	 1I+r&   c                 (    t        |       rd }|S y )Nc                 D    t        j                  | j                   g      S r   r  )r/   s    r%   r  zKTestExternalTypes.test_external_type.<locals>.overload_foo_neg.<locals>.imp  s    !xx!''
33r&   r  )r/   r  r  s     r%   overload_foo_negz>TestExternalTypes.test_external_type.<locals>.overload_foo_neg  s    a)4 J	 *r&   c                 B     |       t        j                  |g      z   S r   )rG   r4  r/   r0   r  s     r%   arr_expr_sum1z;TestExternalTypes.test_external_type.<locals>.arr_expr_sum1  s    1v!--r&   c                 &     |        |      z   S r   r,   r  s     r%   arr_expr_sum2z;TestExternalTypes.test_external_type.<locals>.arr_expr_sum2  s    1vA&r&   c                      |        S r   r,   )r/   r  s    r%   arr_expr_negz:TestExternalTypes.test_external_type.<locals>.arr_expr_neg  s    Awr&   r   r   rO   rU   rP   )r   source_linesr  r  r   operatorrX   negr   rG   r   r   r4  )	r   test_moduler  r  r  r  r  r  r  s	          @@r%   test_external_typez$TestExternalTypes.test_external_type  sA    1 12k--k.A.ABLC hll# $ hll# $ hll# $ . . ' '   JJ))-1*=rxxA?OPJJ))-1*=rxxA?OPJJ)),q/288RD>J_ 322s   EE??FN)	r'   r(   r)   rk  textwrapdedentr  r  r  r,   r&   r%   r~  r~    s*     #8?? $ L D0Kr&   r~  __main__)>r"  ior   r  rG   r  r   r   r   
numba.corer   r   r	   r
   r   r   r   numba.core.compilerr   r   numba.core.registryr   numba.tests.supportr   r   r   r   numba.extendingr   r   r   r   r   r   r   r  r  unittestdictr   r1   r4   r<   rB   rD   rI   rM   rQ   rS   rV   r[   r`   rn   rp   r   r  rG  rP  rm  r~  r'   mainr,   r&   r%   <module>r     sF   	   !  G G G / *5 5     F FF.. ~1'	QX Q.SG?H SGli3 i3X3OX%6%6 3"9AOX%6%6 9Ax@Aox/@/@ @AF^K):): ^KB zHMMO r&   