U
    •Ê¹jt  ã                	   @   sþ   d Z ddlZddlZddlmZ ddlmZ ddlmZm	Z	 ddl
mZ ddlmZ dd	lmZ dd
lmZmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ deeeeeeddœdd„Zeeeeddœdd„Zddœdd„Zedkrúeƒ  dS )a~  
To run this file by hand from the root of the PyTorch
repository, run:

python -m tools.autograd.gen_autograd        aten/src/ATen/native/native_functions.yaml        aten/src/ATen/native/tags.yaml        $OUTPUT_DIR        tools/autograd

Where $OUTPUT_DIR is where you would like the files to be
generated.  In the full build system, OUTPUT_DIR is
torch/csrc/autograd/generated/
é    N)ÚList)Úcpp)Úmatch_differentiability_infoÚ'NativeFunctionWithDifferentiabilityInfo)Úparse_native_yaml)ÚSelectiveBuilderé   )Úgen_python_functions)Úgen_autograd_functions_libÚgen_autograd_functions_python)Úgen_inplace_or_view_type)Úgen_trace_type)Úgen_variable_factories)Úgen_variable_type)Úload_derivativesF)Únative_functions_pathÚ	tags_pathÚoutÚautograd_dirÚoperator_selectorÚdisable_autogradÚreturnc                 C   s¦   t tj |d¡| |ƒ\}}tj |d¡}t| |ƒj}	tt|j|	ƒdd„ d�}
t	|
|ƒ}|sˆt
|| ||||ƒ t|| |||ƒ t||	|ƒ t|||ƒ t|| ||ƒ d S )Núderivatives.yamlÚ	templatesc                 S   s   t  | j¡S )N)r   ÚnameÚfunc)Úf© r   úf/var/www/html/bwave/python/venv/lib/python3.8/site-packages/torchgen/packaged/autograd/gen_autograd.pyÚ<lambda>E   ó    zgen_autograd.<locals>.<lambda>)Úkey)r   ÚosÚpathÚjoinr   Únative_functionsÚsortedÚfilterZ(is_native_function_selected_for_trainingr   r   r   r   r
   r   )r   r   r   r   r   r   Údifferentiability_infosZused_dispatch_keysÚtemplate_pathZnative_funcsZfnsZfns_with_diff_infosr   r   r   Úgen_autograd1   sF    	  ÿ ÿüþú	    ÿr*   )r   r   r   r   r   c                 C   sX   t tj |d¡| |ƒ\}}tj |d¡}t|||ƒ tj |d¡}t || |||¡ d S )Nr   r   zdeprecated.yaml)r   r"   r#   r$   r   r	   Úgen)r   r   r   r   r(   Ú_r)   Zdeprecated_pathr   r   r   Úgen_autograd_pythonc   s      ÿ    ÿr-   )r   c                  C   st   t jdd�} | jdddd� | jdddd� | jd	d
dd� | jdddd� |  ¡ }t|j|j|j|jt	 
¡ ƒ d S )Nz"Generate autograd C++ files script)Údescriptionr%   ZNATIVEzpath to native_functions.yaml)ÚmetavarÚhelpÚtagszpath to tags.yamlr   ZOUTzpath to output directoryÚautogradZAUTOGRADzpath to autograd directory)ÚargparseÚArgumentParserÚadd_argumentÚ
parse_argsr*   r%   r1   r   r2   r   Zget_nop_selector)ÚparserÚargsr   r   r   Úmainy   s*      ÿ  ÿûr9   Ú__main__)F)Ú__doc__r3   r"   Útypingr   Ztorchgen.apir   Ztorchgen.api.autogradr   r   Ztorchgen.genr   Z!torchgen.selective_build.selectorr   Ú r	   Zgen_autograd_functionsr
   r   r   r   r   r   r   ÚstrÚboolr*   r-   r9   Ú__name__r   r   r   r   Ú<module>   sB   	 úù3û