o
    ۾i9                     @   sp   d dl Z d dlmZmZmZmZmZ d dlmZ eeededG dd deZ	e
dkr6e   dS dS )	    N)CUDATestCaseskip_if_cudadevrt_missingskip_on_cudasimskip_unless_cc_60skip_if_mvc_enabled)captured_stdoutzCG not supported with MVCz4cudasim doesn't support cuda import at non-top-levelc                       s4   e Zd ZdZ fddZ fddZdd Z  ZS )TestLaplacez%
    Test simple vector addition
    c                    s    t  | _| j  t   d S N)r   _captured_stdout	__enter__supersetUpself	__class__ ^/home/ubuntu/.local/lib/python3.10/site-packages/numba/cuda/tests/doc_examples/test_laplace.pyr      s   
zTestLaplace.setUpc                    s   | j d d d  t   d S r	   )r
   __exit__r   tearDownr   r   r   r   r      s   zTestLaplace.tearDownc                    s  d}dd l }ddlm  d}||}d|d<  |} |}d}|r~dd lm} |jdd\}	}
|j	|
t|| d	d
dd |jddd |jddd |jddd |
j|
 dd |
j|
 dd |dt| |dd |d  j fdd}|t||||d | }|r|jdd\}	}
|j	|
t||d	d
dd |jd| dd |jddd |jddd |
j|
 dd |
j|
 dd |dt| |dt| |d |j| d d S )NFr   cudai  i'  i  )gQ%@g(\@)figsize   *black)lwmarkercolorzInitial State   )fontsizePositionTemperature   i'  zlaplace_initial.svgc                    s     d}|t| krd S  j }t|D ][}|d dkr#| }|}n|}| }|| }	|dkr>|	|||d  d|	    }
n+|t|d krU|	|||d  d|	    }
n|	|||d  d|	  ||d     }
|
||< |  qd S )N      r   )gridlencg	this_gridrangesync)buf_0buf_1	timestepskir&   stepdata	next_data	curr_temp	next_tempr   r   r   solve_heat_equationN   s*   


z8TestLaplace.test_ex_laplace.<locals>.solve_heat_equationg      ?zT = zlaplace_final.svg)numpynumbar   zeros	to_devicedevice_array_likematplotlib.pyplotpyplotsubplotsplotaranger'   copy_to_hosttitlexlabelylabel
set_xticks
get_xticks
set_yticks
get_yticksxlimylimsavefigjitforallmaxtestingassert_allclosesum)r   r?   npsizer2   r,   r-   niterpltfigaxr6   resultsr   r   r   test_ex_laplace   sd   



+
zTestLaplace.test_ex_laplace)__name__
__module____qualname____doc__r   r   rY   __classcell__r   r   r   r   r   	   s
    r   __main__)unittestnumba.cuda.testingr   r   r   r   r   numba.tests.supportr   r   rZ   mainr   r   r   r   <module>   s     