o
    ki                     @   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rpt| dkrPtddd | D }tt|dkrgtd| dt|d t| S t| }|tjvrtd| ttj| S )	Nr   zlist/tuple must be non-emptyc                 S   s   g | ]}t |qS  )r   from_example).0xr   r   c/var/www/addictedbytheproject.nl/epg/venv/lib/python3.10/site-packages/torchgen/gen_schema_utils.py
<listcomp>0   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AssertionErrorsetRuntimeErrorr   typer   convert_to_base_ty)r   r   all_base_tystpr   r   r   r      s0   





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   r5   r   r   r   r   ?   s   zReturnGen.from_example)	r,   r-   r.   r3   r1   r   r   r   r   r   r   r   r   r4   >   s    r4   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   defaultNr5   r   c                 C   s   t | t|||dS )N)r8   r5   )r   r   r   )r!   r   r8   r5   r   r   r   r   G   s   zArgumentGen.from_example)	r,   r-   r.   r3   r1   r   r   r   r   r   r   r   r   r7   F   s    r7   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 r6   )r4   r   )r   outr   r   r   	<genexpr>^   s    
z1FunctionSchemaGen.from_example.<locals>.<genexpr>F )appendr7   r   r   r#   r   r   r
   )r:   r;   r<   argsr!   inp	argumentsreturnsr   r   r   r   Q   s   zFunctionSchemaGen.from_exampleN)	r,   r-   r.   r3   r1   r#   r   r
   r   r   r   r   r   r9   P   s    
r9   N)typingr   torchgen.modelr   r   r   r   r   r   r	   r
   r   r   r   r   r4   r7   r9   r   r   r   r   <module>   s    4'
