U
    ?h?                     @   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re
  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   Z/var/www/html/venv/lib/python3.8/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   s
    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   s
    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   Zndmin)npr   r   selfr   r   r   getarg:   s    zTestSharedMemoryCreation.getargc                 C   s   |   ddS )Nr
   )r/   Z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   r/   r.   Zudtr   r   r   test_global_constants@   s    z.TestSharedMemoryCreation.test_global_constantsc                 C   s4   t td d d d f ft}|d |   d S r1   )r   r2   r   r"   r0   r3   r   r   r   test_global_build_tupleD   s     z0TestSharedMemoryCreation.test_global_build_tuplez8Simulator does not prohibit lists for shared array shapec              	   C   s^   |  t&}ttd d d d f ft W 5 Q R X | 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   r2   r   r#   assertInstr	exceptionr.   Zraisesr   r   r   test_global_build_listH   s    *z/TestSharedMemoryCreation.test_global_build_listc                 C   s4   t td d d d f ft}|d |   d S r1   )r   r2   r   r%   r0   r3   r   r   r   test_global_constant_tupleU   s     z3TestSharedMemoryCreation.test_global_constant_tuplez&Can't check for constants in simulatorc              	   C   sV   |  t}ttd d  ft W 5 Q R X | dt|j | dt|j d S )Nr6   zFfound for signature:
 
 >>> array(shape=float32, dtype=class(float32)))	r7   r   r   r2   r   r'   r8   r9   r:   r;   r   r   r   test_invalid_1Y   s    "z'TestSharedMemoryCreation.test_invalid_1c              	   C   s^   |  t&}ttd d d d f ft W 5 Q R X | dt|j | dt|j d S )Nr6   zlfound for signature:
 
 >>> array(shape=Tuple(Literal[int](1), array(float32, 1d, A)), dtype=class(float32)))	r7   r   r   r2   r   r(   r8   r9   r:   r;   r   r   r   test_invalid_2f   s    *z'TestSharedMemoryCreation.test_invalid_2c              	   C   sV   |  t}ttd d  ft W 5 Q R X | dt|j | dt|j d S )Nr6   zDfound for signature:
 
 >>> array(shape=int32, dtype=class(float32)))	r7   r   r   r2   r   r'   r8   r9   r:   r;   r   r   r   test_invalid_3t   s    "z'TestSharedMemoryCreation.test_invalid_3c              	   C   sV   |  t}ttd d  ft W 5 Q R X | dt|j | dt|j d S )Nr6   z\found for signature:
 
 >>> array(shape=Tuple(Literal[int](1), int32), dtype=class(float32)))	r7   r   r   r2   r   r)   r8   r9   r:   r;   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iterZ	overloadsvaluesZ_type_annotationtypemapr   ZassertEqual)r.   fr   
annotationZl_dtyper   r   r   check_dtype   s    z$TestSharedMemoryCreation.check_dtypezCan't check typing in simulatorc                 C   s0   t ttd d d dd }| |t d S )Nr
   c                 S   s,   t jjdtd}| d |d< |d | d< d S N
   r   r   )r   r   r   r   xrB   r   r   r   rG      s    z4TestSharedMemoryCreation.test_numba_dtype.<locals>.fr   r2   r   r   rI   r.   rG   r   r   r   test_numba_dtype   s    
z)TestSharedMemoryCreation.test_numba_dtypec                 C   s0   t ttd d d dd }| |t d S )Nr
   c                 S   s.   t jjdtjd}| d |d< |d | d< d S rJ   )r   r   r   r,   r   rM   r   r   r   rG      s    z4TestSharedMemoryCreation.test_numpy_dtype.<locals>.frO   rP   r   r   r   test_numpy_dtype   s    
z)TestSharedMemoryCreation.test_numpy_dtypec                 C   s0   t ttd d d dd }| |t d S )Nr
   c                 S   s,   t jjddd}| d |d< |d | d< d S )NrK   r   rL   r   r   r   r   rM   r   r   r   rG      s    z5TestSharedMemoryCreation.test_string_dtype.<locals>.frO   rP   r   r   r   test_string_dtype   s    
z*TestSharedMemoryCreation.test_string_dtypec              	   C   s@   d}|  t|& tttd d d dd }W 5 Q R X d S )Nz*.*Invalid NumPy dtype specified: 'int33'.*r
   c                 S   s,   t jjddd}| d |d< |d | d< d S )NrK   Zint33rL   r   rS   rM   r   r   r   rG      s    z=TestSharedMemoryCreation.test_invalid_string_dtype.<locals>.f)assertRaisesRegexr   r   r2   r   r   )r.   rerG   r   r   r   test_invalid_string_dtype   s    z2TestSharedMemoryCreation.test_invalid_string_dtypec                 C   s0   t ttd d d dd }| |t d S )Nr
   c                 S   s,   t jjdtd}| d |d< |d | d< d S rJ   )r   r   r   r   rM   r   r   r   rG      s    zDTestSharedMemoryCreation.test_type_with_struct_data_model.<locals>.f)r   r2   r   r   rI   rP   r   r   r    test_type_with_struct_data_model   s    
z9TestSharedMemoryCreation.test_type_with_struct_data_modelN)__name__
__module____qualname__r/   r0   r4   r5   r	   r<   r=   r>   r?   r@   rA   rI   rQ   rR   rT   rW   rX   r   r   r   r   r*   9   s4   












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