o
    "i                     @   s   d dl Z d dlZddlmZmZmZmZ ddejdefddZ	d	d
 Z
dd Zedeje dedededejdiZdd Ze Zde jdefddZdS )    N   )devicedtypeTensortypes prototype_functionreturnc              	      s  t |   fdd}g }t }d}t j D ]\}\}}t|s'|d |jt jj	kr7|s7|
d d}|jt jju rF|d| d |jt vr^|d| d	|j d
t  d t|j }	||v r|	dst|d| d d| d|	tdd  }	|| |jt jju r|
|	 d|  q|jdurt|jtttfs|d| d |
|	 d| d|j  qt|| }
t|
dkr||
 d t j|}dd| d| S )a  Given a function with type hints, parses a schema.

    We make some assumptions to make our lives easier that correspond to how people
    write custom ops in real life:
    - none of the outputs alias any of the inputs or each other.
    - only the args listed in mutates_args are being mutated.

    Callers (e.g. the custom ops API) are responsible for checking these assumptions.
    c                    s   t d|  d  d)Nzinfer_schema(func): z Got func with signature ))
ValueError)whatsigr   Y/home/ubuntu/SoloSpeech/.venv/lib/python3.10/site-packages/torch/_library/infer_schema.pyerror_fn   s   zinfer_schema.<locals>.error_fnFz>We do not support positional-only args, varargs, or varkwargs.*Tz
Parameter z must have a type annotation.z has unsupported type . The valid types are: .r   zM is in mutable_args but only Tensors or collections of Tensors can be mutatedzTensor(az!)N z has an unsupported default value (we only support int, float, bool, None). Please file an issue on GitHub so we can prioritize this.=r   z in mutates_args were not found in the custom op's signature. mutates_args should contain the names of all args that the custom op mutates.(, z) -> )inspect	signatureset	enumerate
parametersitemssupported_paramkind	ParameterKEYWORD_ONLYappend
annotationemptySUPPORTED_PARAM_TYPESkeys
startswithlenadddefault
isinstanceintfloatboolparse_returnreturn_annotationjoin)r   mutates_argsr   params	seen_argssaw_kwarg_only_argidxnameparamschema_typemutates_args_not_seenretr   r   r   infer_schema   sX   







r<   c                 C   s   | |ft j|  | dfg}dd }|r%|| D ]}||| df q|r;|t j|  D ]}||| df q.|rQ|| D ]}|t j| | df qA|S )N?c                 S   s   t j|  t j|  gS N)typingSequenceList)typr   r   r   derived_seq_typesW   s   z(derived_types.<locals>.derived_seq_typesz[]z?[]z[]?)r?   Optionalr"   )	base_typecpp_type	list_baseoptional_base_listoptional_list_baseresultrC   seq_typr   r   r   derived_typesO   s   rL   c                  C   s   t ddddftddddftddddftddddftddddftjddddftd	dddftd
dddfg} g }| D ]	}|	t
|  q7t|S )Nr   TFSymIntr-   r.   strScalar
ScalarTypeDevice)r   r,   r-   r.   rN   r   Numberr   r   extendrL   dict)datarJ   liner   r   r   get_supported_param_typesi   s   rW   r   zTensor[]rM   r-   r.   rO   c                 C   s   | d u rdS t | }|tur$| t vr |d|  dt d t|  S t | }|D ]}|tvr<|d|  dt d q+dddd |D  d	 S )
Nz()zReturn has unsupported type r   r   r   r   c                 S   s   g | ]}t | qS r   )SUPPORTED_RETURN_TYPES).0argr   r   r   
<listcomp>   s    z parse_return.<locals>.<listcomp>r
   )r?   
get_origintuplerX   r&   get_argsr1   )r#   r   originargsrZ   r   r   r   r/      s*   

r/   r8   c                 C   s   | j tjjtjjfv S r>   )r   r   r    POSITIONAL_OR_KEYWORDr!   )r8   r   r   r   r      s   r   )r   )r   r?    r   r   r   r   CallablerN   r<   rL   rW   rA   r,   r-   r.   rR   rX   r/   r%   r    r   r   r   r   r   <module>   s    G

