
    
Ngy                         d dl Z d dlZd dlZd dlZdZ G d dej        j                  Z G d dej                  Z	 G d dej                  Z
dS )	    NaH  <
    ir_version: 8,
    opset_import: ["" : 17, "local" : 1]
>
agraph (float[N] X) => (float[N] Y) {
    Y = local.foo (X)
}

<opset_import: ["" : 17, "local" : 1], domain: "local">
foo (x) => (y) {
    temp = Add(x, x)
    y = local.bar(temp)
}

<opset_import: ["" : 17], domain: "local">
bar (x) => (y) {
    y = Mul (x, x)
}c                   F    e Zd ZdZdZ edh          ZdefdZdefdZ	dS )	_OnnxTestTextualSerializerz:Serialize and deserialize the ONNX textual representation.onnxtextz	.onnxtextreturnc                 j    t           j                            |          }|                    d          S )Nutf-8)onnxprinterto_textencode)selfprototexts      X/var/www/html/ai-engine/env/lib/python3.11/site-packages/onnx/test/serialization_test.pyserialize_protoz*_OnnxTestTextualSerializer.serialize_proto%   s)    |##E**{{7###    
serializedc                 2   |                     d          }t          |t          j                  rt          j                            |          S t          |t          j                  rt          j                            |          S t          |t          j                  rt          j        	                    |          S t          |t          j
                  rt          j                            |          S t          dt          |                     )Nr   zUnsupported proto type: )decode
isinstancer	   
ModelProtoparserparse_model
GraphProtoparse_graphFunctionProtoparse_function	NodeProto
parse_node
ValueErrortype)r   r   r   r   s       r   deserialize_protoz,_OnnxTestTextualSerializer.deserialize_proto)   s      ))eT_-- 	1;**4000eT_-- 	1;**4000eT/00 	4;--d333eT^,, 	0;))$///ADKKAABBBr   N)
__name__
__module____qualname____doc__supported_format	frozensetfile_extensionsbytesr   r"    r   r   r   r      sn        DD!i..O$ $ $ $ $
CE 
C 
C 
C 
C 
C 
Cr   r   c                   .    e Zd ZddZddZddZddZdS )TestRegistryr   Nc                 ~    t                      | _        t          j        j                            | j                   d S )N)r   
serializerr	   serializationregistryregisterr   s    r   setUpzTestRegistry.setUp7   s1    466#,,T_=====r   c                     t           j        j                            d          }|                     || j                   d S )Nr   )r	   r0   r1   getassertIsr/   )r   r/   s     r   (test_get_returns_the_registered_instancez5TestRegistry.test_get_returns_the_registered_instance;   s7    '044Z@@
j$/22222r   c                     |                      t                    5  t          j        j                            d           d d d            d S # 1 swxY w Y   d S )Nunsupported)assertRaisesr    r	   r0   r1   r6   r3   s    r   &test_get_raises_for_unsupported_formatz3TestRegistry.test_get_raises_for_unsupported_format?   s    z** 	; 	;'++M:::	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	;s   %AAAc                    t           j                            t                    }t	          j                    5 }t          j                            |d          }t          j	        ||d           t          |d          5 }|                                }|                     |t           j                            |                     d d d            n# 1 swxY w Y   t          j        |d          }|                     |                    d          |                    d                     d d d            d S # 1 swxY w Y   d S )Nz
model.onnxr   )formatr   )encodingTdeterministic)r	   r   r   _TEST_MODELtempfileTemporaryDirectoryospathjoin
save_modelopenreadassertEqualr
   r   
load_modelSerializeToString)r   modeltmpdir
model_pathfcontentloaded_models          r   4test_onnx_save_load_model_uses_the_custom_serializerzATestRegistry.test_onnx_save_load_model_uses_the_custom_serializerC   s   ''44(** 	ffl;;JOE:jAAAA j7333 Gq&&((  $,*>*>u*E*EFFFG G G G G G G G G G G G G G G  ?:jIIIL''d';;..T.BB  	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s8   A	EAC	EC	EC	AEEEr   N)r#   r$   r%   r4   r8   r<   rT   r+   r   r   r-   r-   6   sd        > > > >3 3 3 3; ; ; ;     r   r-   c                       e Zd ZddZdS )TestCustomSerializerr   Nc                 ^   t                      }t          j                            t                    }|                    |          }|                    |t          j                              }|                     |	                    d          |	                    d                     d S )NTr@   )
r   r	   r   r   rB   r   r"   r   rK   rM   )r   r/   rN   r   deserializeds        r    test_serialize_deserialize_modelz5TestCustomSerializer.test_serialize_deserialize_modelW   s    /11
''44//66
!33J@Q@QRR##$#77***>>	
 	
 	
 	
 	
r   rU   )r#   r$   r%   rZ   r+   r   r   rW   rW   V   s(        
 
 
 
 
 
r   rW   )rE   rC   unittestr	   rB   r0   ProtoSerializerr   TestCaser-   rW   r+   r   r   <module>r^      s    
			   *C C C C C!3!C C C C.    8$   @	
 	
 	
 	
 	
8, 	
 	
 	
 	
 	
r   