
    
Ng                     t   d dl Z d dlZd dlZd dlZd dlZd dlmc mc mc m	Z
 d dlmc mc mc mZ d dlmZmZmZ ej                            ej                            e                    Zej                            ed          Zde j        ddfdZde j        fdZd
dZed	k    r e             dS dS )    N)ONNX_MLTensorProtonumpy_helperdataargsreturnc                    dt           dd fd}t          j                            | j        d          }t          d t          j        |          D                       }| j        rt          j                            |          ret          j        |          D ]P}t          s|
                    d          s2t          j        t          j                            ||                     Qt          j                    }| j        r|t!          j                    z  }n|t!          j        | j                  z  }d}|D ]}t          j                            | j        |j        |j                  } ||           |j        dk    r|dz  }|j        d	k    rwt+          t          j                            |d
          d          5 }	t-          j        |j        |j        |j        |j        d|	d           d d d            n# 1 swxY w Y   |j        sJ t+          t          j                            |d          d          5 }
|
                    |j                                                   d d d            n# 1 swxY w Y   |j        sJ tA          |j                  D ]\  }\  }}t          j                            |d|           } ||           tA          |          D ]\  }}t+          t          j                            |d| d          d          5 }
|j        j!        j"        |         j#        $                    d          rV|
                    tK          j&        ||j        j!        j"        |         j                                                             n|j        j!        j"        |         j#        $                    d          rV|
                    tK          j'        ||j        j!        j"        |         j                                                             nF|j        j!        j"        |         j#        $                    d          rU|
                    tK          j(        ||j        j!        j"        |         j                                                             n|j        j!        j"        |         j#        $                    d          sJ tS          |tT                    r(|
                    |                                           nT|
                    tK          j+        ||j        j!        j"        |         j                                                             d d d            n# 1 swxY w Y   tA          |          D ]\  }}t+          t          j                            |d| d          d          5 }
|j        j!        j        |         j#        $                    d          rV|
                    tK          j&        ||j        j!        j        |         j                                                             n|j        j!        j        |         j#        $                    d          rV|
                    tK          j'        ||j        j!        j        |         j                                                             nF|j        j!        j        |         j#        $                    d          rU|
                    tK          j(        ||j        j!        j        |         j                                                             n|j        j!        j        |         j#        $                    d          sJ tS          |tT                    r(|
                    |                                           nT|
                    tK          j+        ||j        j!        j        |         j                                                             d d d            n# 1 swxY w Y   | j        s$||k    r tY          j-        dt\          d           d S d S d S )Npathr   c                     t           j                            |           rt          j        |            t          j        |            d S N)osr
   existsshutilrmtreemakedirs)r
   s    W/var/www/html/ai-engine/env/lib/python3.11/site-packages/onnx/backend/test/cmd_tools.pyprepare_dirz"generate_data.<locals>.prepare_dir   s>    7>>$ 	 M$
D    nodec                 P    g | ]#}t           j                            |          !|$S  )r   r
   isfile).0names     r   
<listcomp>z!generate_data.<locals>.<listcomp>   s+    HHH$27>>$3G3GHHHHr   test_ai_onnx_ml_r      realz	data.jsonw)url
model_namertolatolT)	sort_keysz
model.onnxwbtest_data_set_input_z.pbmap_typesequence_typeoptional_typetensor_typeoutput_a  There are some models under 'onnx/backend/test/data/node' which cannot not be generated by the script from 'onnx/backend/test/case/node'. Please add '--clean' option for 'python onnx/backend/test/cmd_tools.py generate-data' to cleanup the existing directories and regenerate them.   )
stacklevel)/strr   r
   joinoutputlenlistdircleanr   r   
startswithr   r   
model_testcollect_testcasesdiff	node_testcollect_diff_testcasesop_typekindr   openjsondumpr    r!   r"   r#   modelwriteSerializeToString	data_sets	enumerategraphinputtypeHasFieldr   	from_dict	from_listfrom_optional
isinstancer   
from_arraywarningswarnWarning)r   r   	node_rootoriginal_dir_numbersub_dircasesnode_numbercase
output_dirfifiinputsoutputsdata_set_dirjrF   r1   s                     r   generate_datar_      s   # $     T[&11IHH"*Y//HHH  z @bgnnY// @z),, 	@ 	@G @g001CDD @bgll9g>>???(**E y ;1333,T\:::K X" X"W\\$+ty$)DD
J91K9bgll:{;;SAA 
R	#x&*o $	 $		  "	 	 	 	
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 :bgll:|<<dCC 8q
44667778 8 8 8 8 8 8 8 8 8 8 8 8 8 8>!!!(1$.(A(A B" B"$$FG!w||J8L8L8LMML))) )& 1 1 " "HAubgll<!II4PP "TU:+1!49BB:NN "GG , 6$)4:+;+A!+D+I!" !""3"3"5"5   
 "Z-3A6;DD_UU "GG , 6$)4:+;+A!+D+I!" !""3"3"5"5   
 "Z-3A6;DD_UU "GG , :$)4:+;+A!+D+I!" !""3"3"5"5    $(:#3#9!#<#A#J#J -$ $     *%== " !(?(?(A(A B B B B !$0$;(-tz/?/Ea/H/M%& %&&7&7&9&9!" !" !"5" " " " " " " " " " " " " " "> "+7!3!3 " "IAvbgll<9I19I9I9IJJDQQ "UV:+215:CCJOO "GG , 6$*DJ,<,CA,F,K!" !""3"3"5"5   
 "Z-4Q7<EEoVV "GG , 6$*DJ,<,CA,F,K!" !""3"3"5"5   
 "Z-4Q7<EEoVV "GG , :$*DJ,<,CA,F,K!" !""3"3"5"5    $(:#3#:1#=#B#K#K -$ $     *&+>> " !(@(@(B(B C C C C !$0$;(.
0@0G0J0O%& %&&7&7&9&9!" !" !"5" " " " " " " " " " " " " " ""GB"F : 
+)<<<H 	
 	
 	
 	
 	
 	

 
<<sJ   1G>>H	H	-I::I>	I>	 IU=	=VVI`.	.`25`2c                     t          j        d          } |                                 }|                    dd          }|                    ddddd	
           |                    ddt
          d           |                    ddd d           |                    ddddd
           |                    t                     |                                 S )Nzbackend-test-toolszgenerate-datazconvert testcases to test data.)helpz-cz--cleanF
store_truezEClean the output directory before generating data for node testcases.)defaultactionra   z-oz--outputz'output directory (default: %(default)s))rc   ra   z-tz	--op_typezWop_type for test case generation. (generates test data for the specified op_type only.)z-dz--diffzOonly generates test data for those changed files (compared to the main branch).)func)	argparseArgumentParseradd_subparsers
add_parseradd_argumentDATA_DIRset_defaultsr_   
parse_args)parser
subparsers	subparsers      r   rm   rm      s!   $%9::F&&((J%%? &  I T     6	     f	     ^     ...r   c                  L    t                      } |                     |            d S r   )rm   re   )r   s    r   mainrr      s    <<DIIdOOOOOr   __main__)r   N)rf   r>   r   r   rN   onnx.backend.test.case.modelbackendtestrV   r@   r6   onnx.backend.test.case.noder   r9   onnxr   r   r   r
   realpathdirname__file__TOP_DIRr0   rk   	Namespacer_   rm   rr   __name__r   r   r   <module>r      sg  
   				   1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 / / / / / / / / / / / / / / / 3 3 3 3 3 3 3 3 3 3
'

27??844
5
57<<(({
* {
t {
 {
 {
 {
|#H& # # # #L   
 zDFFFFF r   