
    ܙd                         d dl Zd dlm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)compile_isolated)TypingError)njit)typesc                 *    t          j        |           S N)r   int32xs    8lib/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        g          }|j        }|                     |j        j        t          j                   |                      |d           |d                     |                      |d          t          d                     |                      |d           |d                     |                      |d          t          d                     d S )N皙(@g()
r   r   r   float32entry_pointassertEqual	signaturereturn_typer	   intselfpyfunccrcfuncs       r   test_float_to_intzTestCasting.test_float_to_int   s    fu}o6615;???tffTll333tc$ii000uvve}}555us5zz22222r   c                 :   t           }t          |t          j        g          }|j        }|                     |j        j        t          j                   |                      |d           |d                     |                      |d          d           d S )NiA  g     d@)	r   r   r   int64r$   r%   r&   r'   r   r)   s       r   test_int_to_floatzTestCasting.test_int_to_float)   s    fu{m4415=AAAsVVC[[111sX.....r   c           
         t           }t          |t          j        g          }|j        }|                     |j        j        t          j                   |                      |d           |d                     |                      |d          t          j
        dt          j        dd                    d                    d S )NgGz	@Ii   r   )r   r   r   r#   r$   r%   r&   r'   r   structunpackpackr)   s       r   test_float_to_unsignedz"TestCasting.test_float_to_unsigned2   s    "fu}o6615<@@@tffTll333tfmCSFG:I :I 'J 'JJK'M 	N 	N 	N 	N 	Nr   c                 :   t           }t          |t          j        g          }|j        }|                     |j        j        t          j                   |                      |d           |d                     |                      |d          d           d S )NgGz	yGz	        )	r   r   r   r   r$   r%   r&   r'   r   r)   s       r   test_float_to_complexz!TestCasting.test_float_to_complex<   s    !fu}o66153CDDD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>.innerI   s    Q4Kr   zf8(f8[::1])c                      |           S r   r   )r   r>   s    r   driverz/TestCasting.test_array_to_array.<locals>.driverO   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_arrayD   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   )rB   typer
   s    r   r>   z-TestCasting.test_0darrayT_to_T.<locals>.innerX   s    7<<??"r   Tr"      y      @       @r5   hz
2016-01-01)z<U3ABCrA   r   )r   r   bool_r#   r   r0   	complex64r   timedelta64
datetime64rE   r%   )r*   r>   inputsTinpr   s         r   test_0darrayT_to_TzTestCasting.test_0darrayT_to_TW   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          t          d           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_scalarl   s     {++ 	:v4b999	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	W&*++	- 	- 	- 	- 	-s   =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sigra   s        r   test_optional_to_optionalz%TestCasting.test_optional_to_optionalx   s     .,,.//gg	c	 	 
	 	Q#####d))$$$$$r   N)__name__
__module____qualname__r.   r1   r9   r;   rH   rV   r]   rh   r   r   r   r    r       s        	3 	3 	3/ / /N N N3 3 32 2 2&. . .*
- 
- 
-% % % % %r   r    __main__)numpyr   numba.core.compilerr   numba.core.errorsr   numbar   
numba.corer   r6   unittestr   r   r   r   r   TestCaser    ri   mainr   r   r   <module>ru      s       0 0 0 0 0 0 ) ) ) ) ) )                           k% k% k% k% k%(# k% k% k%\ zHMOOOOO r   