
    ,i&                        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
 d dlmZ d dlZd dlmZ d Zd Zd Zd	 Zd
 Z G d de	ej
                  Z G d de
          Z G d de	ej
                  Zedk    r ej                     dS dS )    N)njit	vectorize)MemoryLeakMixinTestCase)TypingError)dufuncc                     | |z   S N a0a1s     ^/var/www/html/speakWrite/venv/lib/python3.11/site-packages/numba/tests/npyufunc/test_dufunc.pypyuaddr          7N    c                     | |z
  S r
   r   r   s     r   pysubr      r   r   c                     | |z  S r
   r   r   s     r   pymultr      r   r   c                     | |z  S r
   r   r   s     r   pydivr      s    8Or   c                     | |k     r| n|S r
   r   r   s     r   pyminr      s    b22b r   c                   8    e Zd Zd Zd Zd Zd Zd Zd Zd Z	dS )	
TestDUFuncc                 J    t          j        |t          d                    S )NT)nopython)targetoptions)r   DUFuncdict)selfpyfuncs     r   nopython_dufunczTestDUFunc.nopython_dufunc$   s"    }V43F3F3FGGGGr   c           	         |                      t                    }|                     |j                   d|_        |                     |j                   |                     t                    5  d|_        d d d            n# 1 swxY w Y   |                     t                    5   |t          j	        ddd          t          j	        ddd                     d d d            d S # 1 swxY w Y   d S )NTFr      
      )
r$   r   assertFalse_frozen
assertTrueassertRaises
ValueError	TypeErrornplinspacer"   duadds     r   test_frozenzTestDUFunc.test_frozen'   s\   $$V,,'''&&&z** 	" 	"!EM	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	"y)) 	< 	<E"+a"%%r{1Qr':':;;;	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	<s$   0BBB)5C++C/2C/c                     |                      t                    }|                     t          dd           |dd                     d S )Nr&   r(   )r$   r   assertEqualr1   s     r   test_scalarzTestDUFunc.test_scalar1   sC    $$V,,!eeAajj11111r   c                    |                      t                    t          fd            }t          j        ddd          }|d d         }|dd          }t          j        d          } ||||           t          j                            ||z   |           |                    d          }|                    d          }t          j        d          } ||||           t          j                            ||z   |           |d d         }	t          j        d          }
 |||	|
           t          j                            ||	z   |
           d S )Nc                 "     | ||           d S r
   r   )r   r   o0r2   s      r   npmaddz(TestDUFunc.test_npm_call.<locals>.npmadd8   s    E"b"r   r   ffffff?   r'   r(      r>   )	r$   r   r   r/   r0   zerostestingassert_array_equalreshape)r"   r:   XX0X1out0Y0Y1out1Y2out2r2   s              @r   test_npm_callzTestDUFunc.test_npm_call5   sR   $$V,,		 	 	 	 
	K#b!!ssVrssVx||r2t

%%b2gt444ZZZZxr2t

%%b2gt444Vxr2t

%%b2gt44444r   c                 z   |                      t                    t          fd            }t          j        ddd          }|d d         }|dd          } |||          }t          j                            ||z   |           |                    d          }|                    d          } |||          }t          j                            ||z   |           |d d         }	 |||	          }
t          j                            ||	z   |
            |dd	          }|                     |d
           d S )Nc                      | |          S r
   r   )r   r   r2   s     r   r:   z8TestDUFunc.test_npm_call_implicit_output.<locals>.npmaddN   s    5R== r   r   r;   r<   r'   r=   r>   g      ?g       @g      @)	r$   r   r   r/   r0   r@   rA   rB   r5   )r"   r:   rC   rD   rE   rF   rG   rH   rI   rJ   rK   out3r2   s               @r   test_npm_call_implicit_outputz(TestDUFunc.test_npm_call_implicit_outputK   sA   $$V,,		! 	! 	! 	! 
	!K#b!!ssVrssVvb"~~

%%b2gt444ZZZZvb"~~

%%b2gt444Vvb"~~

%%b2gt444vb}}r"""""r   c                 t   |                      t                    }|                     |j        d           |                     |j        d           |                     |j        |j        |j        z              |                     |j        d           |                     |j        g            |                     |j        d             |dd           |                     |j        d           |                     |j        t          |j                             | 
                    |j                   d S )Nr(   r&   r   )r$   r   r5   ninnoutnargsntypestypesidentitylenassertIsNone	signaturer1   s     r   test_ufunc_propszTestDUFunc.test_ufunc_props`   s   $$V,,A&&&Q'''ei%*&<===q)))b)))...aq)))s5;'7'7888%/*****r   c                 H   |                      t                     dd           j        j        j        j        j        d}fd}|                                D ]?\  }}t           ||                    }| 	                    | |            d|            @d S )Nr&   r(   )rR   rS   rT   rW   rZ   c                 n    d|  d}i }t          t          j        |          di|           |d         S )Nz>
                def impl():
                    return duadd.z
            r2   impl)exectextwrapdedent)attrfnlr2   s      r   get_attr_fnz4TestDUFunc.test_ufunc_props_jit.<locals>.get_attr_fny   sN    "&  B A$$w&6:::V9r   z!Attribute differs from original: )
r$   r   rR   rS   rT   rW   rZ   itemsr   r5   )r"   
attributesre   rb   valcfuncr2   s         @r   test_ufunc_props_jitzTestDUFunc.test_ufunc_props_jitm   s    $$V,,a"Y#j${ #(.#(?4 4
	 	 	 	 	 $))++ 	I 	IID#T**++ES%%''GGGI I I I	I 	Ir   N)
__name__
__module____qualname__r$   r3   r6   rL   rP   r[   rj   r   r   r   r   r   "   s        H H H< < <2 2 25 5 5,# # #*+ + +I I I I Ir   r   c                   Z    e Zd ZddZddZd Zd Zd Zd Zd Z	d	 Z
d
 Zd Zd Zd ZdS )TestDUFuncMethodsNc                    t           fd            }t          j        d          t          j        d                              dd          t          j        d                              ddd          g}|D ]U}t	          |j                  D ]>}|                    ||||          } |||||          }	|                     ||	           ?Vd S )Nc                 6                         | |||          S )N)axisdtypeinitialreduce)arr   rs   rt   ufuncs       r   fooz,TestDUFuncMethods._check_reduce.<locals>.foo   s)    <<%)&+(/   1 1 1r   r>      r(   (   )r   r/   arangerB   rangendimpy_funcassertPreciseEqual)
r"   rx   rs   rt   ry   inputsarrayrr   expectedgots
    `        r   _check_reducezTestDUFuncMethods._check_reduce   s    		1 	1 	1 	1 
	1 IaLLIaLL  A&&IbMM!!!Q**

  	7 	7Eej)) 7 7;;udE7CCc%ug66''#66667	7 	7r   c                    	
 t           fd            
	
 fd}dj         d	t          j        d|                              ddd	          t          j        d
|          g}|D ]et          dj        dz             D ]9}t          j        t          j                  |          D ] |           :dD ] |           fd S )Nc                 4                         | |          S )N)rr   rt   ru   )rw   rr   rt   rx   s     r   ry   z1TestDUFuncMethods._check_reduce_axis.<locals>.foo   s    <<g<>>>r   c                  v   	                                }           }                    ||           d S # t          $ rq}                    |j        d                                        t                    5             }d d d            n# 1 swxY w Y   Y d }~d S Y d }~d S d }~ww xY w)Nr   )r   r   r-   r5   argsassertRaisesRegexr   )	r   r   r   er   rr   exc_msgry   r"   s	       r   _checkz4TestDUFuncMethods._check_reduce_axis.<locals>._check   s?   7;;ud33 c%&&''#66666  + + +  G444++KAA + +#eT**C+ + + + + + + + + + + + + + + + + + + + + + + + + + ++s9   = 
B8<B3BB3B 	 B3#B 	$B33B8zreduction operation 'z:' is not reorderable, so at most one axis may be specifiedr{   rs   r>   rz   r(   r'   r&   )r)r   N)	r   rk   r/   r|   rB   r}   r~   	itertoolscombinations)r"   rx   rs   rt   r   r   ir   rr   r   ry   s   `` `   @@@@r   _check_reduce_axisz$TestDUFuncMethods._check_reduce_axis   sc   		? 	? 	? 	? 	? 
	?		7 		7 		7 		7 		7 		7 		7 		7 		7G5> G G G Ib&&&..q!Q77Ib&&&
  	$ 	$E1ej1n-- ( (%253D3DJJJ ( (DF5$''''( # $ $ud####$	$ 	$r   c                      t          dd          t                    }|                     |           |                     |t          j                   d S )Nint64(int64, int64)r   rW   r   )r   r   r   r   r/   int64r1   s     r   test_add_reducez!TestDUFuncMethods.test_add_reduce   sT    <	/!<<<VDD5!!!RX66666r   c                 n     t          dd          t                    }|                     |           d S )Nr   r&   r   )r   r   r   )r"   dumuls     r   test_mul_reducez!TestDUFuncMethods.test_mul_reduce   s9    <	/!<<<VDD5!!!!!r   c                 R    t          d          t                    } t          d          t                    }|                     |           |                     |t
          j                   |                     |           |                     |t
          j                   d S Nr   r   )r   r   r   r   r   r/   r   )r"   dusubdudivs      r   test_non_associative_reducez-TestDUFuncMethods.test_non_associative_reduce   s    0	/00770	/00775!!!RX6665!!!RX66666r   c                      t          dd          t                    }|                     |t          j                   d S )Nfloat64(float64, int64)r   r   r   )r   r   r   r/   float64r1   s     r   test_reduce_dtypez#TestDUFuncMethods.test_reduce_dtype   s@    @	3a@@@HH5
33333r   c                      t          d          t                    }|                     |d           |                     |t          j                   d S )Nr   r'   )rt   r   )r   r   r   r   r/   r   )r"   dumins     r   test_min_reducez!TestDUFuncMethods.test_min_reduce   sT    0	/00775"---RX66666r   c                      t          dd          t                    }|                     |t          j        d           d S )Nr   r   r   d   )rs   rt   r   r   r   r/   r   r1   s     r   test_add_reduce_initialz)TestDUFuncMethods.test_add_reduce_initial   sB    <	/!<<<VDD5#>>>>>r   c                      t          d          t                    }|                     |t          j                   d S r   r   r1   s     r   &test_add_reduce_no_initial_or_identityz8TestDUFuncMethods.test_add_reduce_no_initial_or_identity   s;    0	/0088511111r   c                      t          dd          t                    t          fd            }d}|                     t          |          5   |d           d d d            d S # 1 swxY w Y   d S )Nr   r   r   c                 .                         |           S r
   ru   )rw   r2   s    r   ry   z1TestDUFuncMethods.test_invalid_input.<locals>.foo   s    <<??"r   z-The first argument "array" must be array-likerw   )r   r   r   r   r   )r"   ry   r   r2   s      @r   test_invalid_inputz$TestDUFuncMethods.test_invalid_input   s    @	3a@@@HH		# 	# 	# 	# 
	# B##K99 	 	CHHH	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   A))A-0A-c                 :    t          dd          t                    t          fd            }t          j        d                              ddd          }d	}|D ]:}                    ||          } |||          }|                     ||           ;d S )
Nr   r   r   c                 2                         | |          S N)rr   ru   rw   rr   r2   s     r   ry   z8TestDUFuncMethods.test_dufunc_negative_axis.<locals>.foo       <<<---r   r{   r>   rz   r(   )r   )r   r   )r   )r&   r   )r   r   r   r/   r|   rB   rv   r   )r"   ry   rw   casesrr   r   r   r2   s          @r   test_dufunc_negative_axisz+TestDUFuncMethods.test_dufunc_negative_axis   s    <	/!<<<VDD		. 	. 	. 	. 
	. IbMM!!!Q**7 	3 	3D||At,,H#a,,C##Hc2222	3 	3r   c                     t          dd          t                    t          fd            }t          j        d                              ddd          }d	}|D ]C}d
}|                     t          |          5   |||           d d d            n# 1 swxY w Y   Dd}|D ]A}|                     t          d          5   |||           d d d            n# 1 swxY w Y   Bd S )Nr   r   r   c                 2                         | |          S r   ru   r   s     r   ry   z7TestDUFuncMethods.test_dufunc_invalid_axis.<locals>.foo  r   r   r{   r>   rz   r(   ))r   r   )r   r&   r   )r   r   )r   r   )r   r(   zduplicate value in 'axis')   )r   r   zInvalid axis)r   r   r   r/   r|   rB   r   r-   )r"   ry   rw   r   rr   msgr2   s         @r   test_dufunc_invalid_axisz*TestDUFuncMethods.test_dufunc_invalid_axis  s   <	/!<<<VDD		. 	. 	. 	. 
	. IbMM!!!Q**? 	 	D-C''
C88  At               " 	 	D''
NCC  At              	 	s$   ?BB	B	CC"	%C"	)NNr
   )rk   rl   rm   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   ro   ro      s        7 7 7 7($ $ $ $@7 7 7
" " "7 7 74 4 47 7 7
? ? ?
2 2 2
	 	 	3 3 3    r   ro   c                        e Zd Zd Zd Zd ZdS )TestDUFuncPicklingc                 X   t          j        |          }t          j        |           d          }|                     d|           |                     ||           t
          fd            } |d          }|                     d|           |                     ||           d S )N{   c                      |           S r
   r   )xrebuilts    r   ry   z%TestDUFuncPickling.check.<locals>.foo   s    71::r   iA  )pickledumpsloadsr5   assertIsInstancer   )r"   identresult_typebufr   ry   r   s         @r   checkzTestDUFuncPickling.check  s    l5!!,s## GCLLa   a--- 
	 	 	 	 
	 CHHa   a-----r   c                 v    t           d             }|                     |t          t          j        f           d S )Nc                     | S r
   r   x1s    r   r   z3TestDUFuncPickling.test_unrestricted.<locals>.ident)      Ir   r   )r   r   intr/   integerr"   r   s     r   test_unrestrictedz$TestDUFuncPickling.test_unrestricted(  s@    		 	 
	 	

5sBJ&7
88888r   c                 p    t          dg          d             }|                     |t                     d S )Nzfloat64(float64)c                     | S r
   r   r   s    r   r   z1TestDUFuncPickling.test_restricted.<locals>.ident0  r   r   r   )r   r   floatr   s     r   test_restrictedz"TestDUFuncPickling.test_restricted/  sF    	&'	(	(	 	 
)	(	 	

5e
,,,,,r   N)rk   rl   rm   r   r   r   r   r   r   r   r     sA        . . .$9 9 9- - - - -r   r   __main__)r   r   r`   numpyr/   numbar   r   numba.tests.supportr   r   numba.core.errorsr   unittestnumba.np.ufuncr   r   r   r   r   r   r   ro   r   rk   mainr   r   r   <module>r      s             ! ! ! ! ! ! ! ! 9 9 9 9 9 9 9 9 ) ) ) ) ) )  ! ! ! ! ! !        ! ! !cI cI cI cI cI("3 cI cI cIZC C C C C C C CL- - - - -(*; - - -D zHMOOOOO r   