U
    hâËd;  ã                   @   s`   d dl mZmZ d dlZd dlZd dlZdZdZdZdZ	dZ
G dd	„ d	eƒZed
kr\e ¡  dS )é    )ÚCUDATestCaseÚskip_on_cudasimNz‹from numba import cuda

@cuda.jit
def cuhello():
    i = cuda.grid(1)
    print(i, 999)
    print(-42)

cuhello[2, 3]()
cuda.synchronize()
z�from numba import cuda

@cuda.jit
def printfloat():
    i = cuda.grid(1)
    print(i, 23, 34.75, 321)

printfloat[1, 1]()
cuda.synchronize()
zŒfrom numba import cuda

@cuda.jit
def printstring():
    i = cuda.grid(1)
    print(i, "hop!", 999)

printstring[1, 3]()
cuda.synchronize()
zgfrom numba import cuda

@cuda.jit
def printempty():
    print()

printempty[1, 1]()
cuda.synchronize()
a‰  from numba import cuda
import numpy as np

@cuda.jit
def print_too_many(r):
    print(r[0], r[1], r[2], r[3], r[4], r[5], r[6], r[7], r[8], r[9], r[10],
          r[11], r[12], r[13], r[14], r[15], r[16], r[17], r[18], r[19], r[20],
          r[21], r[22], r[23], r[24], r[25], r[26], r[27], r[28], r[29], r[30],
          r[31], r[32])

print_too_many[1, 1](np.arange(33))
cuda.synchronize()
c                   @   sD   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Zedƒdd„ ƒZ	dS )Ú	TestPrintc                 C   s2   t jd|g}tj|dddd�}|j ¡ |j ¡ fS )z9Runs code in a subprocess and returns the captured outputz-cé<   T)ÚtimeoutÚcapture_outputÚcheck)ÚsysÚ
executableÚ
subprocessÚrunÚstdoutÚdecodeÚstderr)ÚselfÚcodeÚcmdÚcp© r   ú[/home/sam/Atlas/atlas_env/lib/python3.8/site-packages/numba/cuda/tests/cudapy/test_print.pyÚrun_codeN   s    zTestPrint.run_codec                 C   sP   |   t¡\}}dd„ | ¡ D ƒ}dgd dd„ tdƒD ƒ }|  t|ƒ|¡ d S )Nc                 S   s   g | ]}|  ¡ ‘qS r   ©Ústrip©Ú.0Úliner   r   r   Ú
<listcomp>V   s     z*TestPrint.test_cuhello.<locals>.<listcomp>z-42é   c                 S   s   g | ]}d | ‘qS )z%d 999r   ©r   Úir   r   r   r   W   s     )r   Úcuhello_usecaseÚ
splitlinesÚrangeÚassertEqualÚsorted)r   ÚoutputÚ_ÚactualÚexpectedr   r   r   Útest_cuhelloT   s    zTestPrint.test_cuhelloc                 C   s*   |   t¡\}}ddg}|  | ¡ |¡ d S )Nz0 23 34.750000 321z0 23 34.75 321)r   Úprintfloat_usecaseÚassertInr   )r   r%   r&   Zexpected_casesr   r   r   Útest_printfloat\   s    zTestPrint.test_printfloatc                 C   s"   |   t¡\}}|  | ¡ d¡ d S )NÚ )r   Úprintempty_usecaser#   r   )r   r%   r&   r   r   r   Útest_printemptyb   s    zTestPrint.test_printemptyc                 C   sH   |   t¡\}}dd„ | d¡D ƒ}dd„ tdƒD ƒ}|  t|ƒ|¡ d S )Nc                 S   s   g | ]}|  ¡ ‘qS r   r   r   r   r   r   r   h   s     z)TestPrint.test_string.<locals>.<listcomp>Tc                 S   s   g | ]}d | ‘qS )z%d hop! 999r   r   r   r   r   r   i   s     é   )r   Úprintstring_usecaser!   r"   r#   r$   )r   r%   r&   Úlinesr(   r   r   r   Útest_stringf   s    zTestPrint.test_stringz"cudasim can print unlimited outputc                 C   sF   |   t¡\}}d dd„ tdƒD ƒ¡}|  ||¡ d}|  ||¡ d S )Nú c                 S   s   g | ]}d ‘qS )z%lldr   )r   r&   r   r   r   r   v   s     z0TestPrint.test_too_many_args.<locals>.<listcomp>é!   zjCUDA print() cannot print more than 32 items. The raw format string will be emitted by the kernel instead.)r   Úprint_too_many_usecaseÚjoinr"   r+   )r   r%   ÚerrorsZexpected_fmt_stringZwarn_msgr   r   r   Útest_too_many_argsl   s
    zTestPrint.test_too_many_argsN)
Ú__name__Ú
__module__Ú__qualname__r   r)   r,   r/   r3   r   r9   r   r   r   r   r   J   s   r   Ú__main__)Znumba.cuda.testingr   r   r   r	   Zunittestr    r*   r1   r.   r6   r   r:   Úmainr   r   r   r   Ú<module>   s   5