
    J/PhI                         d dl Zd dlmZ d dlmZ d dlmZ d dlZd dl	Z	d Z
d Zd Zd Zd	 Z G d
 de	j                  Zedk    r e	j                     dS dS )    N)TypingError)njit)typesc                 *    t          j        |           S N)r   int32xs    X/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/numba/tests/test_casting.pyfloat_to_intr   	   s    ;q>>    c                 0    t          j        |           dz  S )N   )r   float64r	   s    r   int_to_floatr      s    =ar   c                 *    t          j        |           S r   )r   uint32r	   s    r   float_to_unsignedr      s    <??r   c                 *    t          j        |           S r   )r   
complex128r	   s    r   float_to_complexr      s    Ar   c                  R    t          j        t          j        d                     d S )N)   )npr   zeros r   r   numpy_scalar_cast_errorr      s     HRXd^^r   c                   >    e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	S )
TestCastingc                 
   t           } t          t          j        f          |          }|                     |j        d         j        t          j                   |                      |d           |d                     |                      |d          t          d                     |                      |d           |d                     |                      |d          t          d                     d S )Nr   皙(@g()	r   r   r   float32assertEqualnopython_signaturesreturn_typer   intselfpyfunccfuncs      r   test_float_to_intzTestCasting.test_float_to_int   s    &em%&&v..215A5;OOOtffTll333tc$ii000uvve}}555us5zz22222r   c                 H   t           } t          t          j        f          |          }|                     |j        d         j        t          j                   |                      |d           |d                     |                      |d          d           d S )Nr   iA  g     d@)r   r   r   int64r#   r$   r%   r   r'   s      r   test_int_to_floatzTestCasting.test_int_to_float'   s    $ek^$$V,,215A	( 	( 	(sVVC[[111sX.....r   c           
         t           } t          t          j        f          |          }|                     |j        d         j        t          j                   |                      |d           |d                     |                      |d          t          j	        dt          j
        dd                    d                    d S )Nr   gGz	@Ii   )r   r   r   r"   r#   r$   r%   r   structunpackpackr'   s      r   test_float_to_unsignedz"TestCasting.test_float_to_unsigned0   s    "&em%&&v..215A5<PPPtffTll333tfmCSFG:I :I 'J 'JJK'M 	N 	N 	N 	N 	Nr   c                 H   t           } t          t          j        f          |          }|                     |j        d         j        t          j                   |                      |d           |d                     |                      |d          d           d S )Nr   gGz	yGz	        )r   r   r   r   r#   r$   r%   r   r'   s      r   test_float_to_complexz!TestCasting.test_float_to_complex9   s    !&em%&&v..215A)	+ 	+ 	+uvve}}555uz22222r   c                 p   t          d          d                                              t          d          fd            }t          j        dgt          j                  }|                      ||          |d                    |                     t          j                  d           d	S )
z<Make sure this compiles.

        Cast C to A array
        z	f8(f8[:])c                     | d         S )Nr   r   r	   s    r   innerz.TestCasting.test_array_to_array.<locals>.innerF   s    Q4Kr   zf8(f8[::1])c                      |           S r   r   )r
   r;   s    r   driverz/TestCasting.test_array_to_array.<locals>.driverL   s    588Or   i  dtyper      N)r   disable_compiler   arrayr   r#   len	overloads)r(   r=   r
   r;   s      @r   test_array_to_arrayzTestCasting.test_array_to_arrayA   s    
 
k			 	 
		 		m			 	 	 	 
		 HdV2:...AaD)))U_--q11111r   c                    t           d             }t          j        dft          j        dft          j        dft          j        dft          j        dft          j        dft          j        t          j        dd          ft          j	        t          j	        d          fd	g	}|D ]@\  }}t          j
        ||
          }|                      ||          |d                    Ad S )Nc                 6    | j                             |           S r   )r?   typer	   s    r   r;   z-TestCasting.test_0darrayT_to_T.<locals>.innerU   s    7<<??"r   Tr!      y      @       @r2   hz
2016-01-01)z<U3ABCr>   r   )r   r   bool_r"   r   r-   	complex64r   timedelta64
datetime64rB   r#   )r(   r;   inputsTinpr
   s         r   test_0darrayT_to_TzTestCasting.test_0darrayT_to_TT   s    		# 	# 
	# XtZZXrN\4 ]D!^R^As334]BM,778

  	. 	.HQA&&&AUU1XXqu----	. 	.r   c                     |                      t                    5 } t          d          t                     ddd           n# 1 swxY w Y   |                     dt          |j                             dS )zv
        Ensure that a TypingError exception is raised if
        user tries to convert numpy array to scalar
        r   Nz?Casting array(float64, 1d, C) to int32 directly is unsupported.)assertRaisesr   r   r   assertInstr	exception)r(   raisess     r   test_array_to_scalarz TestCasting.test_array_to_scalari   s     {++ 	.vDHH,---	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	W&*++	- 	- 	- 	- 	-s   AA	A	c                 >   t          j        t           j                  }t          j        t           j                  } ||          }t	          |          d             }|                      |d          d           |                      |d                     dS )z
        Test error due mishandling of Optional to Optional casting

        Related issue: https://github.com/numba/numba/issues/1718
        c                     | S r   r   )as    r   fooz2TestCasting.test_optional_to_optional.<locals>.foo   s    Hr   r   N)r   Optionalintpr   r   r#   assertIsNone)r(   opt_intopt_fltsigr^   s        r   test_optional_to_optionalz%TestCasting.test_optional_to_optionalu   s     .,,.//gg	c	 	 
	 	Q#####d))$$$$$r   N)__name__
__module____qualname__r+   r.   r6   r8   rE   rS   rZ   re   r   r   r   r   r      s        3 3 3/ / /N N N3 3 32 2 2&. . .*
- 
- 
-% % % % %r   r   __main__)numpyr   numba.core.errorsr   numbar   
numba.corer   r3   unittestr   r   r   r   r   TestCaser   rf   mainr   r   r   <module>rq      s        ) ) ) ) ) )                           i% i% i% i% i%(# i% i% i%X zHMOOOOO r   