o
    s::j                     @  sJ   d dl mZ d dlZd dlZd dlZ	ddddZdddZdddZ	dS )    )annotationsNvalir.Value | Nonedtypeir.DataType | None
size_limit
int | Nonereturnnp.ndarray | Nonec                 C  s   | du rdS | j }|durM|dur|j|krdS |dur#|j|kr#dS z| }|jtjjkr7||j }W n
 tyB   Y dS w t	|t
jsKJ |S dS )zReturns the numpy value of a constant value, if available.

    It returns None if the value is not a constant value, or if the value is not of
    the specified element dtype, or if the size of the value exceeds the specified
    size_limit.
    N)const_valuer   sizenumpyirDataTypeSTRINGviewFileNotFoundError
isinstancenpndarray)r   r   r   r   array r   f/home/nk/hobo-godmode/plappi-mvp/.venv/lib/python3.10/site-packages/onnxscript/_internal/_inference.py_get_numpy_value   s&   	r   nodeir.NodeNonec                   s   ddd dfddfddt jD } fddjD }dd | D }tjjjj}tj	
|tj||}jD ]}|j|v rd||j }tj|}|| tj||_qFdS )zRRun ONNX shape and type inference on a single node, updating its outputs in place.xir.Valuer	   onnx.TensorProto | Nonec                 S  s4   t | dd}|d ur| jd usJ tj| jS d S )N   )r   )r   r   r   serdeserialize_tensor)r   valuer   r   r   get_constant_value9   s
   z._do_onnx_inference.<locals>.get_constant_valueindexintr#   onnx.TypeProtoc                   sV   |j d u rtd|  d|j d j dtj|j }|jd ur)tj||j |S )NzType of input z value z	 of node z
 not known)type
ValueErrornamer   r!   serialize_typeshapeserialize_shape_into)r%   r#   
type_proto)r   r   r   get_type@   s   

z$_do_onnx_inference.<locals>.get_typec                   s&   i | ]\}}|d ur|j  ||qS Nr*   ).0ir   )r/   r   r   
<dictcomp>J   s   & z&_do_onnx_inference.<locals>.<dictcomp>c                   s    i | ]}|d ur|j  |qS r0   r1   )r2   r   )r$   r   r   r4   K   s     c                 S  s   i | ]\}}|d ur||qS r0   r   )r2   kvr   r   r   r4   L   s    N)r   r   r	   r   )r%   r&   r#   r   r	   r'   )	enumerateinputsitemsonnxdefs
get_schemaop_typeversiondomainshape_inferenceinfer_node_outputsr   r!   serialize_nodeoutputsr*    deserialize_type_proto_for_shapemerge_shapesdeserialize_type_proto_for_typer(   )r   input_types
input_dataschemaoutput_typesoutputinferred_typeinferred_shaper   )r$   r/   r   r   _do_onnx_inference6   s(   






rN   c              
   C  sD   zt |  W d S  ty! } zt|| jd< W Y d }~d S d }~ww )Nz$pkg.onnxscript.shape_inference_error)rN   	Exceptionstrmetadata_props)r   er   r   r   infer_outputs`   s   rS   )NN)r   r   r   r   r   r   r	   r
   )r   r   r	   r   )

__future__r   r   r   r:   onnx_irr   r   rN   rS   r   r   r   r   <module>   s   
+*