o
    ۾i?                     @   s   d dl Zd dlmZmZmZmZ d dlmZ d dl	m
Z
mZ d dl	mZ ddlmZ dZd	Zd
Zdd Zdd Zdd Zdd Zdd Zdd Zdd ZG dd deZedkr^e
  dS dS )    N)cudafloat32int32void)TypingError)unittestCUDATestCase)skip_on_cudasim   )test_struct_model_type      )r   r   c                 C   s*   t jjttd}t d}|| | |< d S )Nshapedtyper
   )r   sharedarrayGLOBAL_CONSTANTr   gridAsai r   \/home/ubuntu/.local/lib/python3.10/site-packages/numba/cuda/tests/cudapy/test_sm_creation.pyudt_global_constants   s   
r   c                 C   s:   t jjttftd}t d\}}|||f | ||f< d S Nr      r   r   r   r   GLOBAL_CONSTANT_2r   r   r   r   r   jr   r   r   udt_global_build_tuple   
   r"   c                 C   s:   t jjttgtd}t d\}}|||f | ||f< d S r   r   r    r   r   r   udt_global_build_list   r#   r$   c                 C   s6   t jjttd}t d\}}|||f | ||f< d S r   )r   r   r   GLOBAL_CONSTANT_TUPLEr   r   r    r   r   r   udt_global_constant_tuple!   s   r&   c                 C   s.   t jj| d td}t d}|| | |< d S )Nr   r   r
   r   r   r   r   r   r   r   r   r   udt_invalid_1'   s   
r(   c                 C   s>   t jjd| d ftd}t d\}}|||f | ||f< d S )Nr
   r   r   r   r'   r    r   r   r   udt_invalid_2-   s   r)   c                 C   s6   t jjd| d ftd}t d}||df | |< d S )Nr
   r   r   r'   r   r   r   r   udt_invalid_33   s   
r*   c                   @   s   e Zd Zdd Zdd Zdd Zdd Zed	d
d Zdd Z	eddd Z
eddd Zeddd Zeddd Zdd Zeddd Zeddd Zeddd Zedd d! Zedd"d# Zd$S )%TestSharedMemoryCreationc                 C   s   t jdt jddS )Nd   r
   )r   ndmin)npr   r   selfr   r   r   getarg:   s   zTestSharedMemoryCreation.getargc                 C   s   |   ddS )Nr
   )r1   reshaper/   r   r   r   getarg2=   s   z TestSharedMemoryCreation.getarg2c                 C   s,   t td d  ft}|d |   d S N)r
   r
   )r   jitr   r   r1   r0   udtr   r   r   test_global_constants@   s   z.TestSharedMemoryCreation.test_global_constantsc                 C   4   t td d d d f ft}|d |   d S r4   )r   r5   r   r"   r3   r6   r   r   r   test_global_build_tupleD       z0TestSharedMemoryCreation.test_global_build_tuplez8Simulator does not prohibit lists for shared array shapec                 C   r   |  t}ttd d d d f ft W d    n1 s w   Y  | dt|j | dt|j d S )N=No implementation of function Function(<function shared.arrayzTfound for signature:
 
 >>> array(shape=list(int64)<iv=[5, 6]>, dtype=class(float32))	assertRaisesr   r   r5   r   r$   assertInstr	exceptionr0   raisesr   r   r   test_global_build_listH   s   "z/TestSharedMemoryCreation.test_global_build_listc                 C   r9   r4   )r   r5   r   r&   r3   r6   r   r   r   test_global_constant_tupleU   r;   z3TestSharedMemoryCreation.test_global_constant_tuplez&Can't check for constants in simulatorc                 C   j   |  t}ttd d  ft W d    n1 sw   Y  | dt|j | dt|j d S )Nr=   zFfound for signature:
 
 >>> array(shape=float32, dtype=class(float32)))	r>   r   r   r5   r   r(   r?   r@   rA   rB   r   r   r   test_invalid_1Y      z'TestSharedMemoryCreation.test_invalid_1c                 C   r<   )Nr=   zlfound for signature:
 
 >>> array(shape=Tuple(Literal[int](1), array(float32, 1d, A)), dtype=class(float32)))	r>   r   r   r5   r   r)   r?   r@   rA   rB   r   r   r   test_invalid_2f   s   "z'TestSharedMemoryCreation.test_invalid_2c                 C   rF   )Nr=   zDfound for signature:
 
 >>> array(shape=int32, dtype=class(float32)))	r>   r   r   r5   r   r(   r?   r@   rA   rB   r   r   r   test_invalid_3t   rH   z'TestSharedMemoryCreation.test_invalid_3c                 C   rF   )Nr=   z\found for signature:
 
 >>> array(shape=Tuple(Literal[int](1), int32), dtype=class(float32)))	r>   r   r   r5   r   r*   r?   r@   rA   rB   r   r   r   test_invalid_4   s   z'TestSharedMemoryCreation.test_invalid_4c                 C   s0   t t|j j}|jd j}| || d S )Ns)nextiter	overloadsvalues_type_annotationtypemapr   assertEqual)r0   fr   
annotationl_dtyper   r   r   check_dtype   s   z$TestSharedMemoryCreation.check_dtypezCan't check typing in simulatorc                 C   0   t ttd d d dd }| |t d S )Nr
   c                 S   ,   t jjdtd}| d |d< |d | d< d S N
   r   r   )r   r   r   r   xrL   r   r   r   rT         z4TestSharedMemoryCreation.test_numba_dtype.<locals>.fr   r5   r   r   rW   r0   rT   r   r   r   test_numba_dtype      
z)TestSharedMemoryCreation.test_numba_dtypec                 C   rX   )Nr
   c                 S   s.   t jjdtjd}| d |d< |d | d< d S rZ   )r   r   r   r.   r   r]   r   r   r   rT      s   z4TestSharedMemoryCreation.test_numpy_dtype.<locals>.fr`   ra   r   r   r   test_numpy_dtype   rc   z)TestSharedMemoryCreation.test_numpy_dtypec                 C   rX   )Nr
   c                 S   ,   t jjddd}| d |d< |d | d< d S )Nr[   r   r\   r   r   r   r   r]   r   r   r   rT      r_   z5TestSharedMemoryCreation.test_string_dtype.<locals>.fr`   ra   r   r   r   test_string_dtype   rc   z*TestSharedMemoryCreation.test_string_dtypec                 C   sV   d}|  t| tttd d d dd }W d    d S 1 s$w   Y  d S )Nz*.*Invalid NumPy dtype specified: 'int33'.*r
   c                 S   re   )Nr[   int33r\   r   rf   r]   r   r   r   rT      r_   z=TestSharedMemoryCreation.test_invalid_string_dtype.<locals>.f)assertRaisesRegexr   r   r5   r   r   )r0   rerT   r   r   r   test_invalid_string_dtype   s
   "z2TestSharedMemoryCreation.test_invalid_string_dtypec                 C   rX   )Nr
   c                 S   rY   rZ   )r   r   r   r   r]   r   r   r   rT      r_   zDTestSharedMemoryCreation.test_type_with_struct_data_model.<locals>.f)r   r5   r   r   rW   ra   r   r   r    test_type_with_struct_data_model   s   
z9TestSharedMemoryCreation.test_type_with_struct_data_modelN)__name__
__module____qualname__r1   r3   r8   r:   r	   rD   rE   rG   rI   rJ   rK   rW   rb   rd   rg   rk   rl   r   r   r   r   r+   9   s6    












r+   __main__)numpyr.   numbar   r   r   r   numba.core.errorsr   numba.cuda.testingr   r   r	   extensions_usecasesr   r   r   r%   r   r"   r$   r&   r(   r)   r*   r+   rm   mainr   r   r   r   <module>   s*     