o
    i                     @   s|   d dl mZ d dlmZmZmZmZmZmZm	Z	m
Z
mZmZmZ G dd dZG dd dZG dd dZG d	d
 d
ZdS )    )Any)
AnnotationArgument	ArgumentsBaseOperatorNameBaseTyBaseTypeCustomClassTypeFunctionSchemaListTypeOperatorNameReturnc                   @   sF   e Zd ZeejeejeejeejiZe	de
deeB eB fddZdS )TypeGenobjreturnc                 C   s
  dd l }t| |jjrttjS t| |jrttjS t| |jr&ttjS t| |jr1ttjS t| |j	r?t
|   S t| ttfrnt| dksNJ dd | D }tt|dkretd| dt|d t| S t| }|tjvr~td| ttj| S )Nr   c                 S   s   g | ]}t |qS  )r   from_example).0xr   r   [/sda-disk/www/egybert/egybert_env/lib/python3.10/site-packages/torchgen/gen_schema_utils.py
<listcomp>/   s    z(TypeGen.from_example.<locals>.<listcomp>   zFCannot generate schema for a sequence of args of heterogeneous types: zc. Consider unpacking the argument and give proper names to them if possible instead of using *args.zunsupported type )torch
isinstancefxGraphModuler   r   TensorSymIntSymBoolScriptObjectr	   _typenamelisttuplelensetRuntimeErrorr   typer   convert_to_base_ty)r   r   all_base_tystpr   r   r   r      s.   





zTypeGen.from_exampleN)__name__
__module____qualname__intr   floatstrboolr(   staticmethodr   r   r   r	   r   r   r   r   r   r      s     r   c                	   @   s2   e Zd ZededB dededB defddZdS )	ReturnGenr!   Nr   
annotationr   c                 C   s   t | t||S N)r   r   r   )r!   r   r4   r   r   r   r   >   s   zReturnGen.from_example)	r+   r,   r-   r2   r0   r   r   r   r   r   r   r   r   r3   =   s    r3   c                   @   s6   e Zd ZededededB dedB def
ddZdS )	ArgumentGenr!   r   defaultNr4   r   c                 C   s   t | t|||dS )N)r7   r4   )r   r   r   )r!   r   r7   r4   r   r   r   r   F   s   zArgumentGen.from_example)	r+   r,   r-   r2   r0   r   r   r   r   r   r   r   r   r6   E   s    r6   c                	   @   sB   e Zd Zededeeeef df deedf defddZdS )	FunctionSchemaGenop_nameexample_inputs.example_outputsr   c              	   C   sz   g }|D ]\}}| t||d d  qtt d t|t d t t }tdd |D }tt| dddd} t| ||S )Nc                 s   s    | ]
}t d |d V  qd S r5   )r3   r   )r   outr   r   r   	<genexpr>]   s    
z1FunctionSchemaGen.from_example.<locals>.<genexpr>F )appendr6   r   r   r#   r   r   r
   )r9   r:   r;   argsr!   inp	argumentsreturnsr   r   r   r   P   s   zFunctionSchemaGen.from_exampleN)	r+   r,   r-   r2   r0   r#   r   r
   r   r   r   r   r   r8   O   s    
r8   N)typingr   torchgen.modelr   r   r   r   r   r   r	   r
   r   r   r   r   r3   r6   r8   r   r   r   r   <module>   s    4&
