B
     \                 @   s   d dl Zd dlZd dlZd dlZd dlZd dlZd dlm	Z	 d dlm
Z ddlmZ dd Zdd	 ZG d
d dejZedkre  dS )    N)jit)unittest_support   )
needs_blasc             C   s2   d}x(t t| D ]}|| | ||  7 }qW |S )Nr   )rangelen)absumi r   8lib/python3.7/site-packages/numba/tests/test_profiler.pydot   s    r   c             C   s   t | |S )N)npr   )r   r	   r   r   r   np_dot   s    r   c               @   s(   e Zd Zdd Zdd Zedd ZdS )TestProfilerc       	      C   s   t jdt jd}t jdt jd}tdd|}||| t }|  z||| W d|  X t	|
 }|j}tj|j|j|jf}| ||j dS )zy
        Make sure the jit-compiled function shows up in the profile stats
        as a regular Python function.
           )ZdtypeT)ZnopythonN)r   ZarangeZfloat32r   profilerZProfileenabledisablepstatsZStatsZ
strip_dirs__code__ospathbasenameco_filenameco_firstlinenoco_nameZassertInstats)	selfZpyfuncr   r	   Zcfuncpr   codeZexpected_keyr   r   r   check_profiler_dot   s    

zTestProfiler.check_profiler_dotc             C   s   |  t d S )N)r"   r   )r   r   r   r   test_profiler2   s    zTestProfiler.test_profilerc             C   s   d}t tjd|g d S )Na  if 1:
            import cProfile as profiler

            import numpy as np

            from numba import jit
            from numba.tests.test_profiler import np_dot

            cfunc = jit(nopython=True)(np_dot)

            a = np.arange(16, dtype=np.float32)
            b = np.arange(16, dtype=np.float32)

            p = profiler.Profile()
            p.enable()
            cfunc(a, b)
            cfunc(a, b)
            p.disable()
            z-c)
subprocessZ
check_callsys
executable)r   r!   r   r   r   test_profiler_np_dot5   s    z!TestProfiler.test_profiler_np_dotN)__name__
__module____qualname__r"   r#   r   r'   r   r   r   r   r      s   r   __main__)ZcProfiler   r   r   r$   r%   Znumpyr   Znumbar   r   ZunittestZtest_linalgr   r   r   ZTestCaser   r(   mainr   r   r   r   <module>   s   6