U
    ?h9                     @   sl   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rhe   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__ \/var/www/html/venv/lib/python3.8/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}|rd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(\@)Zfigsize   *black)ZlwmarkercolorzInitial State   )ZfontsizeZPositionZTemperature   i'  zlaplace_initial.svgc                    s     d}|t| krd S  j }t|D ]}|d dkrF| }|}n|}| }|| }	|dkr||	|||d  d|	    }
nV|t|d kr|	|||d  d|	    }
n(|	|||d  d|	  ||d     }
|
||< |  q,d S )N      r   )gridlenZcgZ	this_gridrangesync)buf_0buf_1Z	timestepskir!   stepdataZ	next_dataZ	curr_tempZ	next_tempr   r   r   solve_heat_equationN   s(    

z8TestLaplace.test_ex_laplace.<locals>.solve_heat_equationg      ?zT = zlaplace_final.svg)numpyZnumbar   ZzerosZ	to_deviceZdevice_array_likeZmatplotlib.pyplotZpyplotZsubplotsplotZaranger"   Zcopy_to_hosttitleZxlabelZylabelZ
set_xticksZ
get_xticksZ
set_yticksZ
get_yticksZxlimZylimZsavefigZjitforallmaxZtestingZassert_allclosesum)r   r-   npsizer*   r%   r&   ZniterZpltZfigZaxr+   resultsr   r   r   test_ex_laplace   sl    



+    
zTestLaplace.test_ex_laplace)__name__
__module____qualname____doc__r   r   r5   __classcell__r   r   r   r   r   	   s   r   __main__)ZunittestZnumba.cuda.testingr   r   r   r   r   Znumba.tests.supportr   r   r6   mainr   r   r   r   <module>   s    