o
    ۾i-                     @   s   d Z ddlmZ ddlZzddlmZ W n ey#   ddlmZ Y nw ddlm	Z	 ddl
Z
ddlmZ ddlZddlmZ dd	 Zd
d Zdd Zdd Zdd ZdZdZdd ZdddZedkrhe  dS dS )z`
Generate documentation for all registered implementation for lowering
using reStructured text.
    )check_outputN)StringIO)defaultdict)partial)
cpu_targetc                  C   s   t g d} | ddS )N)gitlogz--pretty=format:'%H'z-n1ascii'")r   decodestrip)out r   X/home/ubuntu/.local/lib/python3.10/site-packages/numba/scripts/generate_lower_listing.pygit_hash   s   r   c                 C   s   t | d| jS )N__qualname__)getattr__name__)fnr   r   r   get_func_name   s   r   c                 C   s   t t}tjtjtj}| j D ]C\}}|j	D ];\}}i }|| 
| ||d< ||d< t|\}}	t|}
t|tjj|
|d|	|	t| d f|jd|d< qq|S )Nr   sig)start   )namefilenamelines	docstringimpl)r   listospathdirnamenumba__file___defnsitemsversionsappendinspectgetsourcelinesgetsourcefiler   relpathlen__doc__)backendfninfosbasepathr   oselr   r   infocodefirstlinenor!   r   r   r   gather_function_info   s"   
r6   c                 C   s   t t| dS )Nfile)r   print)fobjr   r   r   bind_file_to_print4   s   r;   c                 C   s&   dd }t t|| }dd|S )Nc                 S   s*   z| j W S  ty   t| d Y S w )Nr   )r   AttributeErrorreprr   )cr   r   r   fmt9   s
   zformat_signature.<locals>.fmtz`({0})`z, )tuplemapformatjoin)r   r?   r   r   r   r   format_signature8   s   rD   zLhttps://github.com/numba/numba/blob/{commit}/{path}#L{firstline}-L{lastline}a8  
This lists all lowering definition registered to the CPU target.
Each subsection corresponds to a Python function that is supported by numba
nopython mode. These functions have one or more lower implementation with
different signatures. The compiler chooses the most specific implementation
from all overloads.
c                 C   s:  t  }zt|}d}|| |dt|  |t t }dd }tt|| dd dD ]\}}| | }d|}	||	 |d	t|	  |  td
d |}
tt|
|dd d}dg}dg}|D ];\}}|d }|d }|d }|d }dj|g|R  }t	j|||d |d d}d|||}|
| |
| qcttt|}ttt|}d}|d | }|d | }d||}||d| d|  |||d |d  ||d| d|  t|dd  |dd  D ]\}}|||| q||d| d|  |  q-| W |  S |  w )NzLowering Listing=c                 S   s>   zd | jt| }W | |fS  ty   t| }Y | |fS w )Nz{0}.{1})rB   
__module__r   r<   r=   )r   fnamer   r   r   format_fname[   s   
z+format_function_infos.<locals>.format_fnamec                 S      | d S )Nr   r   xr   r   r   <lambda>b       z'format_function_infos.<locals>.<lambda>)keyz``{0}``-c                 S   s   t | d S )Nr   )rD   rJ   r   r   r   rL   j   s    c                 S   rI   )Nr   r   rJ   r   r   r   rL   l   rM   	Signature
Definitionr   r   r   r   z{0} lines {1}-{2}r   r   )commitr!   	firstlinelastlinez``{0}`` `{1} <{2}>`_   z{{0:^{0}}}  {{1:^{1}}})r   r;   r-   descriptionr   sortedrA   rB   zip
github_urlr(   maxgetvalueclose)r0   bufr9   
title_linerR   rH   r   rG   impinfosheader_lineformatted_sigssorted_impinfoscol_signaturescol_urlsfmtsigr3   r   r   r   sourcelinkurlmax_width_col_sigmax_width_col_urlpaddingwidth_col_sigwidth_col_urlline_formatr   r   r   r   format_function_infosN   sh   


"ro   c                 C   sn   t j}|  t|}t|}| du rt| dS t| d}t||d W d   dS 1 s0w   Y  dS )zG
    Generate lowering listing to ``path`` or (if None) to stdout.
    Nwr7   )r   target_contextrefreshr6   ro   r9   open)r!   cpu_backendr0   r   r:   r   r   r   gen_lower_listing   s   "ru   __main__)N)r.   
subprocessr   os.pathr    r   ImportErroriocollectionsr   r)   	functoolsr   r#   numba.core.registryr   r   r   r6   r;   rD   rY   rV   ro   ru   r   r   r   r   r   <module>   s2    
	
I
