o
    wi!                     @  sV   d dl mZ d dlZd dlZd dlmZmZ G dd dejZedkr)e	  dS dS )    )annotationsN)checkerutilsc                   @  s   e Zd Zdd ZdddZdS )	TestFunctionc                   sP   t | | t|jt| |D ]| t fdd|jD d  qd S )Nc                 3  s(    | ]}|j kr|j kr|V  qd S )N)namedomain).0ffunc_domainfunction T/home/ubuntu/sommelier/.venv/lib/python3.10/site-packages/onnx/test/function_test.py	<genexpr>   s    z4TestFunction._verify_function_set.<locals>.<genexpr>)r   check_modelassertEquallen	functionsassertIsNotNonenext)selfextracted_modelfunction_setr   r   r
   r   _verify_function_set   s   
z!TestFunction._verify_function_setreturnNonec           '      C  s  d}t jddg}t jddt j|dg}d}ddg}dg}t jd	ddgdgg}t j||||||}d
}	dg}
dg}t jddgdgg}t j||	|
|||}d}ddg}dg}t jjd
dgdg|dt jjd
dgdg|dt jjdddgdg|dg}t j||||||}t jj|ddgdg|d}t jd	ddgdg}t jd	ddgdg}t jj|	dgdg|d}t jddgdg}t jd	ddgdg}t jj|ddgdg|d}t jj|ddgdg|d}d}d}t jddt jddg}t jjddgd}t j||||||||g|t jjd|d t jjd|d t jjd|d gt jjd|d t jjd|d t jjd|d t jjd|d g}||d!|||gd"} t jj|fi | }!t	
|! t|!g d#dg}"| |"i | t|!g d#dg}#| |#|h| t|!g d#dg}$| |$||	|h| t|!g d#dg}%| |%||	|h| t|!g d#g d$}&| |&||	|h| d%S )&aO  #   1. build a model with graph below. extract models with output combinations
        #   2. validate extracted models' local functions
        #
        # model graph:
        #      i0                    i1                 i2
        #      |   __________________|__________________/_________
        #      |  |                  |             |   /          |
        #      |  |                  |             |  /           |
        #   func_add        func_identity          add         identity
        #    |  ___\___________\____________________|_________    |
        #    | |    \           \                   |  _______|___|
        #    | |     \           \                  | |       |   |
        #    add     function_nested_identity_add   add     function_nested_identity_add
        #     |                 |                    |              |
        #     |                 |                    |              |
        #   o_func_add      o_all_func0           o_no_func     o_all_func1
        #
        # where function_nested_identity_add is a function that is defined with functions:
        #       a               b
        #       |               |
        #   func_identity   func_identity
        #             \       /
        #             func_add
        #                |
        #                c
        #
        local       func_addabcAddfunc_identityIdentityfunc_nested_identity_adda1)r   b1i0i1t0i2t2
o_func_addt1t3	o_no_funco_all_func0o_all_func1graph_with_imbedded_functions         )	elem_typeshape)r   
type_proto&test_extract_model_with_local_function)
ir_versionopset_importsproducer_namer   )r*   r+   r-   )r2   r/   r3   r4   N)onnxhelpermake_opsetid	make_nodemake_functionmake_tensor_type_proto
make_graphmake_value_info
make_modelr   r   r   	Extractorextract_modelr   )'r   r   func_opset_importsfunc_nested_opset_importsfunc_add_namefunc_add_inputsfunc_add_outputsfunc_add_nodesr    func_identity_namefunc_identity_inputsfunc_identity_outputsfunc_identity_nodesr%   func_nested_identity_add_namefunc_nested_identity_add_inputs func_nested_identity_add_outputsfunc_nested_identity_add_nodesr'   node_func_add	node_add0	node_add1node_func_identitynode_identity	node_add2node_func_nested0node_func_nested1
graph_namer=   r>   tensor_type_protographmetamodelextracted_with_no_funcionextracted_with_add_funcionextracted_with_o_all_funcion0extracted_with_o_all_funcion1extracted_with_o_all_funcion2r   r   r   r<      s  



"









z3TestFunction.test_extract_model_with_local_functionN)r   r   )__name__
__module____qualname__r   r<   r   r   r   r   r      s    r   __main__)

__future__r   unittestr@   r   r   TestCaser   rk   mainr   r   r   r   <module>   s    V